diff --git a/pkg/java/pom/parse.go b/pkg/java/pom/parse.go index 7ce6880e..90d03b72 100644 --- a/pkg/java/pom/parse.go +++ b/pkg/java/pom/parse.go @@ -382,10 +382,7 @@ func (p *parser) parseDependencies(deps []pomDependency, props map[string]string continue } - art := d.ToArtifact(opts.exclusions) - if !opts.lineNumber { - art.Locations = nil - } + art := d.ToArtifact(opts) dependencies = append(dependencies, art) } diff --git a/pkg/java/pom/pom.go b/pkg/java/pom/pom.go index 15fff843..48ce0c44 100644 --- a/pkg/java/pom/pom.go +++ b/pkg/java/pom/pom.go @@ -260,28 +260,34 @@ func (d pomDependency) Resolve(props map[string]string, depManagement, rootDepMa // ToArtifact converts dependency to artifact. // It should be called after calling Resolve() so that variables can be evaluated. -func (d pomDependency) ToArtifact(ex map[string]struct{}) artifact { +func (d pomDependency) ToArtifact(opts analysisOptions) artifact { // To avoid shadow adding exclusions to top pom's, // we need to initialize a new map for each new artifact // See `exclusions in child` test for more information exclusions := map[string]struct{}{} - if ex != nil { - exclusions = maps.Clone(ex) + if opts.exclusions != nil { + exclusions = maps.Clone(opts.exclusions) } for _, e := range d.Exclusions.Exclusion { exclusions[fmt.Sprintf("%s:%s", e.GroupID, e.ArtifactID)] = struct{}{} } + + var locations types.Locations + if opts.lineNumber { + locations = types.Locations{ + { + StartLine: d.StartLine, + EndLine: d.EndLine, + }, + } + } + return artifact{ GroupID: d.GroupID, ArtifactID: d.ArtifactID, Version: newVersion(d.Version), Exclusions: exclusions, - Locations: types.Locations{ - { - StartLine: d.StartLine, - EndLine: d.EndLine, - }, - }, + Locations: locations, } }