Skip to content

Commit

Permalink
konveyor#390 Workaround to prevent SEGV when POM file has no properties
Browse files Browse the repository at this point in the history
CAUTION: The property search should be extended to the parent
POM (hierarchy).
  • Loading branch information
ascheman committed Oct 31, 2023
1 parent 396657f commit 749f298
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions provider/internal/java/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
path = location
}
pom, err := gopom.Parse(path)
p.log.V(10).Info("Analyzing POM",
"POM", fmt.Sprintf("%s:%s:%s", pomCoordinate(pom.GroupID), pomCoordinate(pom.ArtifactID), pomCoordinate(pom.Version)),
"error", err)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,9 +141,20 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
if *d.Version != "" {
if strings.Contains(*d.Version, "$") {
version := strings.TrimSuffix(strings.TrimPrefix(*d.Version, "${"), "}")
version = pom.Properties.Entries[version]
if version != "" {
p.log.V(10).Info("Searching for property in properties",
"property", version,
"properties", pom.Properties)
if pom.Properties == nil {
p.log.Info("Cannot resolve version property value as POM does not have properties",
"POM", fmt.Sprintf("%s.%s", pomCoordinate(pom.GroupID), pomCoordinate(pom.ArtifactID)),
"property", version,
"dependency", dep.Name)
dep.Version = version
} else {
version = pom.Properties.Entries[version]
if version != "" {
dep.Version = version
}
}
} else {
dep.Version = *d.Version
Expand Down Expand Up @@ -172,6 +186,13 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
return m, nil
}

func pomCoordinate(value *string) string {
if value != nil {
return *value
}
return "unknown"
}

func (p *javaServiceClient) GetDependenciesDAG(ctx context.Context) (map[uri.URI][]provider.DepDAGItem, error) {
localRepoPath := getMavenLocalRepoPath(p.mvnSettingsFile)

Expand Down

0 comments on commit 749f298

Please sign in to comment.