Skip to content

Commit 6e7056e

Browse files
haoozhangHao Zhang
andauthored
separate spring boot and spring cloud from spring detection (#229)
* separate spring boot and spring cloud from spring detection Signed-off-by: Hao Zhang <[email protected]> * reuse spring detector Signed-off-by: Hao Zhang <[email protected]> * fix path format Signed-off-by: Hao Zhang <[email protected]> * update test Signed-off-by: Hao Zhang <[email protected]> * add test for spring cloud Signed-off-by: Hao Zhang <[email protected]> --------- Signed-off-by: Hao Zhang <[email protected]> Co-authored-by: Hao Zhang <[email protected]>
1 parent b286e29 commit 6e7056e

File tree

10 files changed

+174
-21
lines changed

10 files changed

+174
-21
lines changed

pkg/apis/enricher/framework/java/micronaut_detector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package enricher
1414
import (
1515
"context"
1616
"os"
17+
"path/filepath"
1718

1819
"github.com/devfile/alizer/pkg/apis/model"
1920
"github.com/devfile/alizer/pkg/utils"
@@ -31,13 +32,13 @@ func (m MicronautDetector) GetApplicationFileInfos(componentPath string, ctx *co
3132
{
3233
Context: ctx,
3334
Root: componentPath,
34-
Dir: "src/main/resources",
35+
Dir: filepath.FromSlash("src/main/resources"),
3536
File: "application.yml",
3637
},
3738
{
3839
Context: ctx,
3940
Root: componentPath,
40-
Dir: "src/main/resources",
41+
Dir: filepath.FromSlash("src/main/resources"),
4142
File: "application.yaml",
4243
},
4344
}

pkg/apis/enricher/framework/java/quarkus_detector.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ func (q QuarkusDetector) GetApplicationFileInfos(componentPath string, ctx *cont
3333
{
3434
Context: ctx,
3535
Root: componentPath,
36-
Dir: "src/main/resources",
36+
Dir: filepath.FromSlash("src/main/resources"),
3737
File: "application.properties",
3838
},
3939
{
4040
Context: ctx,
4141
Root: componentPath,
42-
Dir: "src/main/resources",
42+
Dir: filepath.FromSlash("src/main/resources"),
4343
File: "application.yml",
4444
},
4545
{
4646
Context: ctx,
4747
Root: componentPath,
48-
Dir: "src/main/resources",
48+
Dir: filepath.FromSlash("src/main/resources"),
4949
File: "application.yaml",
5050
},
5151
}

pkg/apis/enricher/framework/java/spring_detector.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,42 @@ import (
2525
type SpringDetector struct{}
2626

2727
func (s SpringDetector) GetSupportedFrameworks() []string {
28-
return []string{"Spring", "Spring Boot"}
28+
return []string{"Spring", "Spring Boot", "Spring Cloud"}
2929
}
3030

3131
func (s SpringDetector) GetApplicationFileInfos(componentPath string, ctx *context.Context) []model.ApplicationFileInfo {
3232
return []model.ApplicationFileInfo{
3333
{
3434
Context: ctx,
3535
Root: componentPath,
36-
Dir: "src/main/resources",
36+
Dir: filepath.FromSlash("src/main/resources"),
3737
File: "application.properties",
3838
},
3939
{
4040
Context: ctx,
4141
Root: componentPath,
42-
Dir: "src/main/resources",
42+
Dir: filepath.FromSlash("src/main/resources"),
4343
File: "application.yml",
4444
},
4545
{
4646
Context: ctx,
4747
Root: componentPath,
48-
Dir: "src/main/resources",
48+
Dir: filepath.FromSlash("src/main/resources"),
4949
File: "application.yaml",
5050
},
5151
}
5252
}
5353

5454
// DoFrameworkDetection uses the groupId to check for the framework name
5555
func (s SpringDetector) DoFrameworkDetection(language *model.Language, config string) {
56+
if hasFwk, _ := hasFramework(config, "org.springframework.boot", ""); hasFwk {
57+
language.Frameworks = append(language.Frameworks, "Spring Boot")
58+
}
59+
if hasFwk, _ := hasFramework(config, "org.springframework.cloud", ""); hasFwk {
60+
language.Frameworks = append(language.Frameworks, "Spring Cloud")
61+
}
5662
if hasFwk, _ := hasFramework(config, "org.springframework", ""); hasFwk {
57-
language.Frameworks = append(language.Frameworks, s.GetSupportedFrameworks()...)
63+
language.Frameworks = append(language.Frameworks, "Spring")
5864
}
5965
}
6066

pkg/apis/enricher/framework/java/vertx_detector.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package enricher
1414
import (
1515
"context"
1616
"encoding/json"
17+
"path/filepath"
1718

1819
"github.com/devfile/alizer/pkg/apis/model"
1920
"github.com/devfile/alizer/pkg/utils"
@@ -30,7 +31,7 @@ func (v VertxDetector) GetApplicationFileInfos(componentPath string, ctx *contex
3031
{
3132
Context: ctx,
3233
Root: componentPath,
33-
Dir: "src/main/conf",
34+
Dir: filepath.FromSlash("src/main/conf"),
3435
File: ".*.json",
3536
},
3637
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>spring-cloud</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<name>spring-cloud</name>
11+
<packaging>jar</packaging>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>3.2.5</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<java.version>17</java.version>
22+
<spring-cloud.version>2023.0.1</spring-cloud.version>
23+
</properties>
24+
25+
<dependencies>
26+
<!-- Spring Boot Web -->
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
</dependency>
31+
32+
<!-- Spring Cloud Config Client -->
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-starter-config</artifactId>
36+
</dependency>
37+
38+
<!-- Spring Cloud Discovery Client (Eureka) -->
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
42+
</dependency>
43+
44+
<!-- Actuator for health checks -->
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-actuator</artifactId>
48+
</dependency>
49+
50+
<!-- Test dependencies -->
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-test</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
57+
58+
<dependencyManagement>
59+
<dependencies>
60+
<dependency>
61+
<groupId>org.springframework.cloud</groupId>
62+
<artifactId>spring-cloud-dependencies</artifactId>
63+
<version>${spring-cloud.version}</version>
64+
<type>pom</type>
65+
<scope>import</scope>
66+
</dependency>
67+
</dependencies>
68+
</dependencyManagement>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-maven-plugin</artifactId>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.example.demo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
9+
@RestController
10+
@SpringBootApplication
11+
public class DemoApplication {
12+
13+
@RequestMapping("/")
14+
String home() {
15+
return "Hello World!";
16+
}
17+
18+
public static void main(String[] args) {
19+
SpringApplication.run(DemoApplication.class, args);
20+
}
21+
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
server:
2+
http:
3+
port: 9012
4+
spring:
5+
application:
6+
name: spring-cloud-sample
7+
cloud:
8+
config:
9+
uri: http://localhost:8888
10+
eureka:
11+
client:
12+
service-url:
13+
defaultZone: http://localhost:8761/eureka/
14+
management:
15+
endpoints:
16+
web:
17+
exposure:
18+
include: "*"
19+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.demo;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class DemoApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

test/apis/component_recognizer_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func TestComponentDetectionOnSpring(t *testing.T) {
112112
isComponentsInProject(t, "spring", 1, "java", "spring")
113113
}
114114

115+
func TestComponentDetectionOnSpringCloud(t *testing.T) {
116+
isComponentsInProject(t, "spring-cloud", 1, "java", "spring-cloud")
117+
}
118+
115119
func TestComponentDetectionOnVertx(t *testing.T) {
116120
isComponentsInProject(t, "vertx", 1, "java", "http-vertx")
117121
}
@@ -419,7 +423,7 @@ func TestComponentDetectionWithGitIgnoreRule(t *testing.T) {
419423

420424
func TestComponentDetectionMultiProjects(t *testing.T) {
421425
components := getComponentsFromTestProject(t, "")
422-
nComps := 70
426+
nComps := 71
423427
if len(components) != nComps {
424428
t.Errorf("Expected %v components but found %v", strconv.Itoa(nComps), strconv.Itoa(len(components)))
425429
}

test/git_test.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@
273273
{
274274
"name": "Java",
275275
"frameworks": [
276-
"Spring"
276+
"Spring",
277+
"Spring Boot"
277278
],
278279
"tools": [
279280
"Maven"
@@ -531,7 +532,8 @@
531532
{
532533
"name": "Java",
533534
"frameworks": [
534-
"Spring"
535+
"Spring",
536+
"Spring Boot"
535537
],
536538
"tools": [
537539
"Maven"
@@ -548,7 +550,8 @@
548550
{
549551
"name": "Java",
550552
"frameworks": [
551-
"Spring"
553+
"Spring",
554+
"Spring Boot"
552555
],
553556
"tools": [
554557
"Maven"
@@ -565,7 +568,8 @@
565568
{
566569
"name": "Java",
567570
"frameworks": [
568-
"Spring"
571+
"Spring",
572+
"Spring Boot"
569573
],
570574
"tools": [
571575
"Maven"
@@ -587,7 +591,8 @@
587591
{
588592
"name": "Java",
589593
"frameworks": [
590-
"Spring"
594+
"Spring",
595+
"Spring Boot"
591596
],
592597
"tools": [
593598
"Maven"
@@ -643,7 +648,8 @@
643648
{
644649
"name": "Java",
645650
"frameworks": [
646-
"Spring"
651+
"Spring",
652+
"Spring Boot"
647653
],
648654
"tools": [
649655
"Gradle"
@@ -662,7 +668,8 @@
662668
{
663669
"name": "Java",
664670
"frameworks": [
665-
"Spring"
671+
"Spring",
672+
"Spring Boot"
666673
],
667674
"tools": [
668675
"Gradle"
@@ -676,7 +683,8 @@
676683
{
677684
"name": "Java",
678685
"frameworks": [
679-
"Spring"
686+
"Spring",
687+
"Spring Boot"
680688
],
681689
"tools": [
682690
"Gradle"
@@ -1174,7 +1182,8 @@
11741182
{
11751183
"name": "Java",
11761184
"frameworks": [
1177-
"Spring"
1185+
"Spring",
1186+
"Spring Boot"
11781187
],
11791188
"tools": [
11801189
"Maven"

0 commit comments

Comments
 (0)