Skip to content

Commit e859000

Browse files
authored
add java jakarta ee framework detection support (#303)
* add java jakarta ee framework detection support Signed-off-by: bzssm <358963981@qq.com> * docs: add JakartaEE to supported Java frameworks list Signed-off-by: bzssm <358963981@qq.com> --------- Signed-off-by: bzssm <358963981@qq.com>
1 parent f17ab9e commit e859000

File tree

6 files changed

+103
-1
lines changed

6 files changed

+103
-1
lines changed

docs/public/alizer-spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ NOTE: Maven, Gradle and Ant are saved as Tools inside the data structure returne
3737
By reading the content of its configuration file and mainly its dependencies section, Alizer is also able to detect
3838
frameworks. Currently, it recognizes:
3939

40+
- JakartaEE
4041
- Micronaut
4142
- OpenLiberty
4243
- Quarkus
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
&framework.WebSphereDetector{},
3839
&framework.WebLogicDetector{},
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
@@ -152,6 +152,10 @@ func TestComponentDetectionOnWildFly(t *testing.T) {
152152
isComponentsInProject(t, "wildfly", 1, "java", "wildfly")
153153
}
154154

155+
func TestComponentDetectionOnJakartaEE(t *testing.T) {
156+
isComponentsInProject(t, "jakartaee", 1, "java", "jakartaee-app")
157+
}
158+
155159
// port detection: java
156160
func TestPortDetectionJavaJBossEAP(t *testing.T) {
157161
testPortDetectionInProject(t, "jboss-eap-by-eap-maven-plugin", []int{8380})
@@ -451,7 +455,7 @@ func TestComponentDetectionWithGitIgnoreRule(t *testing.T) {
451455

452456
func TestComponentDetectionMultiProjects(t *testing.T) {
453457
components := getComponentsFromTestProject(t, "")
454-
nComps := 78
458+
nComps := 79
455459
if len(components) != nComps {
456460
t.Errorf("Expected %v components but found %v", strconv.Itoa(nComps), strconv.Itoa(len(components)))
457461
}

0 commit comments

Comments
 (0)