Skip to content
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

Easy Init: Enhance the Java analyzer #4640

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

saragluna
Copy link
Member

This PR is targeting improving the Java analyzer of AZD, which will:

  • Analyze the Maven Project
  • Analyze the Spring Framework configuration property files
  • Try to introduce Options / Metadata in the project struct, to store more information related to the project

Copy link
Contributor

@weikanglim weikanglim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review

return azdMvnCommand, nil
}

func downloadMaven(filepath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what happens if we don't download maven and just fail with a proper help here.

In azd, we generally do not acquire build tools for users. A Java user with a valid project set up should be able to land into maven / mvnw well. We can provide pointers, but I do think it may be too much if we're auto-acquiring build toolchains for them.

In my mind, not having maven installed but having pom.xml installed would be in a similar category as running Application.java without Java runtime installed -- this is something we can help users with but not abstract away.

}

// replace all placeholders with properties
str := replaceAllPlaceholders(unmarshalledPom, string(bytes))
Copy link
Contributor

@weikanglim weikanglim Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we replicating what maven would normally be doing as part of a build evaluation? If so, I'm wondering if there is a different way of doing this?

I know we have used mvn help:evaluate -Dexpression=propertyPath -q -DforceStdout in the past

if err != nil {
return pom{}, err
}
cmd := exec.Command(mvn, "help:effective-pom", "-f", pomPath)
Copy link
Contributor

@weikanglim weikanglim Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious here, are we evaluating an effective POM based on the active configuration? I'm wondering how this ends up impacting the overall e2e. Does a user get a different result if they switch their active build configuration?

if !commandExistsInPath("java") {
return pom{}, fmt.Errorf("can not get effective pom because java command not exist")
}
mvn, err := getMvnCommandFromPath(pomPath)
Copy link
Contributor

@weikanglim weikanglim Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is equivalent to using the existing maven package we have:

mavenCli := maven.NewCli(exec.NewCommandRunner(nil))
mavenCli.SetPath(filepath.Dir(pomPath), rootProjectPath)

I have to look at it again with a deeper set of eyes, but it doesn't look quite right that we're using os.Getwd() here. We should be rooted in root passed to appdetect.Detect call, or perhaps the parent pom.xml (whichever correctly replicates the logic that mvnw would use.).

If this works, I think we can remove the maven_command*.go files.

readPropertiesInPropertiesFile(filepath.Join(projectPath, "/src/main/resources/application.properties"), result)
readPropertiesInYamlFile(filepath.Join(projectPath, "/src/main/resources/application.yml"), result)
readPropertiesInYamlFile(filepath.Join(projectPath, "/src/main/resources/application.yaml"), result)
profile, profileSet := result["spring.profiles.active"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants