-
Notifications
You must be signed in to change notification settings - Fork 210
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
Try to use effective pom if possible #4710
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- cli/azd/internal/appdetect/pom_test.go: Evaluated as low risk
Comments suppressed due to low confidence (1)
cli/azd/pkg/tools/maven/maven.go:241
- The new function 'EffectivePom' does not have test coverage. Please add tests to ensure its functionality.
func (cli *Cli) EffectivePom(ctx context.Context, pomPath string) (string, error) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
cli/azd/internal/appdetect/pom.go
Outdated
result, err = unmarshalPomFile(pomFilePath) | ||
if err == nil { | ||
result.path = filepath.Dir(pomFilePath) | ||
// todo: handle pom, for example: <version>${project.version}<version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @weikanglim
- My current plan is do this after current PR merged.
- Anyway, analyze the unmarshalled pom will be done. If you think
toSimulatedEffectivePom
is not accurate, I can choose another func name, for example:pom := analyzeUnmarshalledPom(pom)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous comment here: #4473 (comment)
I still strongly suggest we do not do this. A user is asking azd
to scan a Java project that has pom.xml
. The pom.xml
clearly requires maven tooling installed to run. User also needs maven tooling installed to run azd package
or azd up
. The overall scenario requires the user to install maven.
I don't like the idea of trying to replicate maven evaluation because evaluation rules can be tricky to replicate; and I prefer tools that just work exactly, instead of tools that are subtly wrong. This can lead to downstream impacts that are harder to debug.
On the flip side, if we are confident in replicating maven evaluation rules, I would prefer removing the current effective-POM evaluation and have the native-go implementation take over -- it's cool work to have a 100% compatible maven evaluator in go
, but I'm not confident that we can always replicate it since it's not a fully documented standard -- and it's one that changes over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up deciding removing the maven evaluation, perhaps pom_test.go
can be removed along those lines as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @weikanglim
I still strongly suggest we do not do this.
-
Thanks for the detailed explanation. Now I deleted the
todo
. My current plan is usemvn help:effective-pom
only, will not analyze the pom file by go code. -
When
mvn
command not found, current behavior is to just unmarshall the pom file. Do you think it's necessary to exit analyze and ask customer to installmvn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we end up deciding removing the maven evaluation, perhaps pom_test.go can be removed along those lines as well.
Agree. Now effective pom is generated by mvn help:effective-pom
, it's not necessary to test it. I deleted pom_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's necessary to exit analyze and ask customer to install mvn?
Yes, I think it's better than doing a partial analysis
Hi, @saragluna , @haoozhang, @weikanglim BTW, I can't set @haoozhang as reviewer. @weikanglim , could you please help to set this? |
cli/azd/pkg/tools/maven/maven.go
Outdated
inProject := false | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if strings.HasPrefix(strings.TrimSpace(line), "<project") { | ||
inProject = true | ||
} else if strings.HasPrefix(strings.TrimSpace(line), "</project>") { | ||
builder.WriteString(line) | ||
break | ||
} | ||
if inProject { | ||
if strings.TrimSpace(line) != "" { | ||
builder.WriteString(line) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small suggestion here to avoid string allocations and streamline the code
inProject := false | |
for scanner.Scan() { | |
line := scanner.Text() | |
if strings.HasPrefix(strings.TrimSpace(line), "<project") { | |
inProject = true | |
} else if strings.HasPrefix(strings.TrimSpace(line), "</project>") { | |
builder.WriteString(line) | |
break | |
} | |
if inProject { | |
if strings.TrimSpace(line) != "" { | |
builder.WriteString(line) | |
} | |
} | |
} | |
inProject := false | |
projectStart := regexp.MustCompile(`\s+<project`) | |
projectEnd := regexp.MustCompile(`\s+</project>`) | |
for scanner.Scan() { | |
line := scanner.Text() | |
if projectStart.MatchString(line) { | |
inProject = true | |
} else if projectEnd.MatchString(line) { | |
builder.WriteString(line) | |
break | |
} | |
if inProject { | |
builder.WriteString(line) | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI:
- I'll accept the changes by clicking
commit suggestion
. - I'll fix the indent problem in line 271 in another commit.
- To test the changes, make sure it won't bring new bug, I'll recover
pom_test.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix the bug in another commit.
Done in this commit: 90e806f
type mavenProject struct { | ||
pom pom | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see us adding more properties here... Are we okay keeping what we have to avoid code churn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK to delete mavenProject and use pom directly.
Hi, @saragluna , This option is required by you before. Now if you agree, I'll delete mavenProject and use pom directly.
@@ -0,0 +1,94 @@ | |||
package appdetect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general go
programming convention here, I would like to avoid adding more files like maven_project.go
or
pom.go
here. We can fit all under java.go
. In the future, we could rename this to java_maven.go
when gradle support is added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general go programming convention here
- Thanks for telling me that. I didn't know this convention before. BTW, could you please share related link about this convention? I guess there should be some official doc like this one: https://go.dev/doc/effective_go
- I use different files because:
2.1.java
andpom
are different things in concept. Especially fortype pom struct
, it's unmarshalled from pom.xml, it's a standalone concept.
2.2. Separate codes into multiple file can avoid one file too long. Too long file will make it hard to maintain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished reviewing. Overall looks good. Left some comments.
I do feel it'd be nice for us to avoid introducing additional types like pom
instead of mavenProject
, and keep it simple for now by having the shared logic in java.go
to start.
Co-authored-by: Wei Lim <[email protected]>
Co-authored-by: Wei Lim <[email protected]>
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash:
pwsh:
WindowsPowerShell install
MSI install
Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Co-authored-by: Wei Lim <[email protected]>
This reverts commit 82726b3.
Try to use effective pom if possible (both mvn and java command exists)