ensure java parent pkg ref isnt nil when looking for parent matches

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2020-12-16 17:23:39 -05:00 committed by Dan Luhring
parent ae7cd6bbb7
commit bb1facbf81
No known key found for this signature in database
GPG Key ID: 9CEE23D079426CEF

View File

@ -184,7 +184,7 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
// keep the artifact name within the virtual path if this package does not match the parent package // keep the artifact name within the virtual path if this package does not match the parent package
vPathSuffix := "" vPathSuffix := ""
if !strings.HasPrefix(propsObj.ArtifactID, parentPkg.Name) { if parentPkg != nil && !strings.HasPrefix(propsObj.ArtifactID, parentPkg.Name) {
vPathSuffix += ":" + propsObj.ArtifactID vPathSuffix += ":" + propsObj.ArtifactID
} }
virtualPath := j.virtualPath + vPathSuffix virtualPath := j.virtualPath + vPathSuffix
@ -208,6 +208,7 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
// the name/version pair matches... // the name/version pair matches...
matchesParentPkg := pkgKey == parentKey matchesParentPkg := pkgKey == parentKey
if parentPkg != nil {
// the virtual path matches... // the virtual path matches...
matchesParentPkg = matchesParentPkg || parentPkg.Metadata.(pkg.JavaMetadata).VirtualPath == virtualPath matchesParentPkg = matchesParentPkg || parentPkg.Metadata.(pkg.JavaMetadata).VirtualPath == virtualPath
@ -231,7 +232,10 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
parentMetadata.PomProperties = propsObj parentMetadata.PomProperties = propsObj
parentPkg.Metadata = parentMetadata parentPkg.Metadata = parentMetadata
} }
} else if !j.discoveredPkgs.Contains(pkgKey) { }
}
if !matchesParentPkg && !j.discoveredPkgs.Contains(pkgKey) {
// only keep packages we haven't seen yet (and are not related to the parent package) // only keep packages we haven't seen yet (and are not related to the parent package)
pkgs = append(pkgs, p) pkgs = append(pkgs, p)
} }