mirror of
https://github.com/anchore/syft.git
synced 2025-11-22 02:43:19 +01:00
* enhance pURL generation for java packages Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * optionally split out npm namespaces for pURL generation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * nit updates Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
26 lines
681 B
Go
26 lines
681 B
Go
package java
|
|
|
|
import (
|
|
"github.com/anchore/packageurl-go"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/pkg/cataloger/common/cpe"
|
|
)
|
|
|
|
// PackageURL returns the PURL for the specific java package (see https://github.com/package-url/purl-spec)
|
|
func packageURL(p pkg.Package) string {
|
|
var groupID = p.Name
|
|
groupIDs := cpe.GroupIDsFromJavaPackage(p)
|
|
if len(groupIDs) > 0 {
|
|
groupID = groupIDs[0]
|
|
}
|
|
|
|
pURL := packageurl.NewPackageURL(
|
|
packageurl.TypeMaven, // TODO: should we filter down by package types here?
|
|
groupID,
|
|
p.Name,
|
|
p.Version,
|
|
nil, // TODO: there are probably several qualifiers that can be specified here
|
|
"")
|
|
return pURL.ToString()
|
|
}
|