Skip to content

Commit

Permalink
refactor(planner/java): Clean up DetermineTargetExt
Browse files Browse the repository at this point in the history
  • Loading branch information
pan93412 committed Aug 6, 2023
1 parent 62f09e5 commit 7938bba
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions internal/java/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,15 @@ func DetermineJDKVersion(pj types.JavaProjectType, src afero.Fs) string {
return defaultVersion
}

// DetermineTargetExt determines the target extension of the Java project.
func DetermineTargetExt(src afero.Fs) string {
if utils.HasFile(src, "pom.xml") {
pom, err := afero.ReadFile(src, "pom.xml")
if err != nil {
return "jar"
}
re := regexp.MustCompile(`<packaging>(.*)</packaging>`)
matches := re.FindStringSubmatch(string(pom))
if len(matches) > 1 {
if matches[1] == "war" {
return "war"
}
}
pom, err := afero.ReadFile(src, "pom.xml")
if err != nil {
return "jar"
}

if strings.Contains(string(pom), "<packaging>war</packaging>") {
return "war"
}

return "jar"
Expand Down

0 comments on commit 7938bba

Please sign in to comment.