Skip to content

Commit

Permalink
refactor: check opts.lineNumber in ToArtifact function
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Jan 24, 2024
1 parent 365ac8d commit e8ff04c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 1 addition & 4 deletions pkg/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 15 additions & 9 deletions pkg/java/pom/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit e8ff04c

Please sign in to comment.