Skip to content

Commit a8c0f8c

Browse files
committed
add java jakarta ee framework detection support
1 parent d51f02d commit a8c0f8c

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc.
10+
******************************************************************************/
11+
12+
package enricher
13+
14+
import (
15+
"context"
16+
17+
"github.com/devfile/alizer/pkg/apis/model"
18+
)
19+
20+
type JakartaEEDetector struct{}
21+
22+
func (j JakartaEEDetector) GetSupportedFrameworks() []string {
23+
return []string{"JakartaEE"}
24+
}
25+
26+
func (j JakartaEEDetector) GetApplicationFileInfos(componentPath string, ctx *context.Context) []model.ApplicationFileInfo {
27+
return []model.ApplicationFileInfo{}
28+
}
29+
30+
// DoFrameworkDetection uses the groupId to check for the framework name
31+
func (j JakartaEEDetector) DoFrameworkDetection(language *model.Language, config string) {
32+
jakartaGroupIds := []string{
33+
"jakarta.platform", // Jakarta EE Platform BOM
34+
"jakarta.servlet", // Servlet API
35+
"jakarta.ws.rs", // JAX-RS (RESTful Web Services)
36+
"jakarta.persistence", // JPA (Persistence)
37+
"jakarta.enterprise", // CDI (Contexts and Dependency Injection)
38+
}
39+
40+
for _, groupId := range jakartaGroupIds {
41+
if hasFwk, _ := hasFramework(config, groupId, ""); hasFwk {
42+
language.Frameworks = append(language.Frameworks, "JakartaEE")
43+
return
44+
}
45+
}
46+
}
47+
48+
// DoPortsDetection is not implemented for JakartaEE as port configuration varies by runtime
49+
func (j JakartaEEDetector) DoPortsDetection(component *model.Component, ctx *context.Context) {
50+
}

pkg/apis/enricher/java_enricher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func getJavaFrameworkDetectors() []FrameworkDetectorWithConfigFile {
3434
&framework.VertxDetector{},
3535
&framework.WildFlyDetector{},
3636
&framework.JBossEAPDetector{},
37+
&framework.JakartaEEDetector{},
3738
}
3839
}
3940

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>jakartaee-app</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<properties>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>11</maven.compiler.target>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>jakarta.platform</groupId>
21+
<artifactId>jakarta.jakartaee-api</artifactId>
22+
<version>10.0.0</version>
23+
<scope>provided</scope>
24+
</dependency>
25+
</dependencies>
26+
27+
<build>
28+
<finalName>jakartaee-app</finalName>
29+
</build>
30+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
import jakarta.ws.rs.Produces;
6+
import jakarta.ws.rs.core.MediaType;
7+
8+
@Path("/hello")
9+
public class HelloResource {
10+
11+
@GET
12+
@Produces(MediaType.TEXT_PLAIN)
13+
public String hello() {
14+
return "Hello, Jakarta EE!";
15+
}
16+
}

test/apis/component_recognizer_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ func TestComponentDetectionOnWildFly(t *testing.T) {
124124
isComponentsInProject(t, "wildfly", 1, "java", "wildfly")
125125
}
126126

127+
func TestComponentDetectionOnJakartaEE(t *testing.T) {
128+
isComponentsInProject(t, "jakartaee", 1, "java", "jakartaee-app")
129+
}
130+
127131
// port detection: java
128132
func TestPortDetectionJavaJBossEAP(t *testing.T) {
129133
testPortDetectionInProject(t, "jboss-eap", []int{8380})
@@ -423,7 +427,7 @@ func TestComponentDetectionWithGitIgnoreRule(t *testing.T) {
423427

424428
func TestComponentDetectionMultiProjects(t *testing.T) {
425429
components := getComponentsFromTestProject(t, "")
426-
nComps := 71
430+
nComps := 72
427431
if len(components) != nComps {
428432
t.Errorf("Expected %v components but found %v", strconv.Itoa(nComps), strconv.Itoa(len(components)))
429433
}

0 commit comments

Comments
 (0)