-
Notifications
You must be signed in to change notification settings - Fork 317
Add more java related analysis code #4437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50ff9f4
add more java related analysis code
saragluna 20c11e5
address comments
saragluna ab91a37
add tests
saragluna 35aefd8
fix ci
saragluna 2be10ec
fix ci
saragluna 9e155d9
address comments to add multi-module support, and add tests
saragluna adff1f8
fix ci
saragluna 1d6900d
address comments
saragluna 7b2a1eb
Merge branch 'main' into xiada/app-detect-java
saragluna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package appdetect | ||
|
|
||
| import ( | ||
| "context" | ||
| "io/fs" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestJavaDetector_Language(t *testing.T) { | ||
| jd := &javaDetector{} | ||
| if jd.Language() != Java { | ||
| t.Errorf("expected language to be Java, got %v", jd.Language()) | ||
| } | ||
| } | ||
|
|
||
| func TestJavaDetector_DetectProject_WithPomXml(t *testing.T) { | ||
|
saragluna marked this conversation as resolved.
Outdated
|
||
| jd := &javaDetector{} | ||
| entries := []fs.DirEntry{ | ||
| mockDirEntry{name: "pom.xml"}, | ||
| } | ||
| tempDir := t.TempDir() | ||
| err := os.WriteFile(filepath.Join(tempDir, "pom.xml"), []byte(` | ||
| <project> | ||
|
|
||
| </project>`), 0600) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| project, err := jd.DetectProject(context.Background(), tempDir, entries) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if project == nil { | ||
| t.Fatal("expected project to be detected, got nil") | ||
| } | ||
| } | ||
|
|
||
| func TestJavaDetector_DetectProject_WithoutPomXml(t *testing.T) { | ||
|
saragluna marked this conversation as resolved.
Outdated
|
||
| jd := &javaDetector{} | ||
| entries := []fs.DirEntry{ | ||
| mockDirEntry{name: "not_pom.xml"}, | ||
| } | ||
| project, err := jd.DetectProject(context.Background(), ".", entries) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if project != nil { | ||
| t.Fatalf("expected no project to be detected, got %v", project) | ||
| } | ||
| } | ||
|
|
||
| func TestJavaDetector_DetectProject_WithSubmodules(t *testing.T) { | ||
| // Set up a temporary directory with a root pom.xml and submodule poms | ||
| tempDir := t.TempDir() | ||
| err := os.WriteFile(filepath.Join(tempDir, "pom.xml"), []byte(` | ||
| <project> | ||
| <modules> | ||
| <module>submodule</module> | ||
| </modules> | ||
| </project>`), 0600) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| err = os.Mkdir(filepath.Join(tempDir, "submodule"), 0755) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| err = os.WriteFile(filepath.Join(tempDir, "submodule", "pom.xml"), []byte(` | ||
| <project> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.mysql</groupId> | ||
| <artifactId>mysql-connector-j</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project>`), 0600) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| jd := &javaDetector{} | ||
| entries, err := os.ReadDir(tempDir) | ||
| if err != nil { | ||
| t.Fatalf("reading directory: %v", err) | ||
| } | ||
|
|
||
| project, err := jd.DetectProject(context.Background(), tempDir, entries) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if project != nil { | ||
| t.Fatalf("expected no project to be detected, got %v", project) | ||
| } | ||
| if len(jd.rootProjects) != 1 { | ||
| t.Fatalf("expected 1 root project, got %d", len(jd.rootProjects)) | ||
| } | ||
|
|
||
| entries, err = os.ReadDir(filepath.Join(tempDir, "submodule")) | ||
| if err != nil { | ||
| t.Fatalf("reading directory: %v", err) | ||
| } | ||
| project, err = jd.DetectProject(context.Background(), filepath.Join(tempDir, "submodule"), entries) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if project == nil { | ||
| t.Fatalf("expected project to be detected, got nil") | ||
| } | ||
| } | ||
|
|
||
| func TestDetectDependencies_WithDatabaseDeps(t *testing.T) { | ||
|
saragluna marked this conversation as resolved.
Outdated
|
||
| mavenProj := &mavenProject{ | ||
| Dependencies: []dependency{ | ||
| {GroupId: "com.mysql", ArtifactId: "mysql-connector-j"}, | ||
| {GroupId: "org.postgresql", ArtifactId: "postgresql"}, | ||
| }, | ||
| } | ||
| project := &Project{} | ||
| project, err := detectDependencies(mavenProj, project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(project.DatabaseDeps) != 2 { | ||
| t.Fatalf("expected 2 database dependencies, got %d", len(project.DatabaseDeps)) | ||
| } | ||
| } | ||
|
|
||
| func TestDetectDependencies_WithoutDatabaseDeps(t *testing.T) { | ||
| mavenProj := &mavenProject{ | ||
| Dependencies: []dependency{ | ||
| {GroupId: "com.example", ArtifactId: "example-dependency"}, | ||
| }, | ||
| } | ||
| project := &Project{} | ||
| project, err := detectDependencies(mavenProj, project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(project.DatabaseDeps) != 0 { | ||
| t.Fatalf("expected 0 database dependencies, got %d", len(project.DatabaseDeps)) | ||
| } | ||
| } | ||
|
|
||
| // Mock implementation of fs.DirEntry for testing purposes | ||
| type mockDirEntry struct { | ||
| name string | ||
| } | ||
|
|
||
| func (m mockDirEntry) Name() string { return m.name } | ||
| func (m mockDirEntry) IsDir() bool { return false } | ||
| func (m mockDirEntry) Type() fs.FileMode { return 0 } | ||
| func (m mockDirEntry) Info() (fs.FileInfo, error) { return nil, nil } | ||
23 changes: 23 additions & 0 deletions
23
cli/azd/internal/appdetect/testdata/java-multimodules/application/build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| plugins { | ||
|
saragluna marked this conversation as resolved.
Outdated
|
||
| id 'org.springframework.boot' version '3.3.0' | ||
| id 'io.spring.dependency-management' version '1.1.5' | ||
| id 'java' | ||
| } | ||
|
|
||
| group = 'com.example' | ||
| version = '0.0.1-SNAPSHOT' | ||
|
|
||
| java { | ||
| sourceCompatibility = '17' | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'org.springframework.boot:spring-boot-starter-actuator' | ||
| implementation 'org.springframework.boot:spring-boot-starter-web' | ||
| implementation project(':library') | ||
| testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.