Skip to content

Commit

Permalink
feat: add manifest field discovery back
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
spiffcs committed Aug 17, 2023
1 parent f8a6582 commit fe85967
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions syft/pkg/cataloger/common/cpe/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ var (
}

primaryJavaManifestGroupIDFields = []string{
"Bundle-SymbolicName",
"Extension-Name",
"Specification-Vendor",
"Implementation-Vendor",
"Bundle-SymbolicName",
"Implementation-Vendor-Id",
"Implementation-Title",
"Bundle-Activator",
Expand Down Expand Up @@ -223,15 +223,6 @@ func GroupIDsFromJavaPackage(p pkg.Package) (groupIDs []string) {
// 2. The group ID from the POM project
// 3. The group ID from a select map of known group IDs
// 3. The group ID from the Java manifest
func GroupIDFromJavaPackage(p pkg.Package) string {
metadata, ok := p.Metadata.(pkg.JavaMetadata)
if !ok {
return ""
}

return GroupIDFromJavaMetadata(p.Name, metadata)
}

func GroupIDFromJavaMetadata(pkgName string, metadata pkg.JavaMetadata) (groupID string) {
if groupID = groupIDFromPomProperties(metadata.PomProperties); groupID != "" {
return groupID
Expand All @@ -245,9 +236,9 @@ func GroupIDFromJavaMetadata(pkgName string, metadata pkg.JavaMetadata) (groupID
return groupID
}

// if groupID = groupIDFromJavaManifest(pkgName, metadata.Manifest); groupID != "" {
// return groupID
// }
if groupID = groupIDFromJavaManifest(metadata.Manifest); groupID != "" {
return groupID
}

return groupID
}
Expand All @@ -259,9 +250,25 @@ func groupIDFromKnownPackageList(pkgName string) (groupID string) {
return groupID
}

// func groupIDFromJavaManifest(pkgName string, manifest *pkg.JavaManifest) (groupID string) {
// return groupID
// }
func groupIDFromJavaManifest(manifest *pkg.JavaManifest) (groupID string) {
if manifest == nil {
return groupID
}

groupIDS := getManifestFieldGroupIDs(manifest, primaryJavaManifestGroupIDFields)
// assumes that primaryJavaManifestNameFields are ordered by priority
if len(groupIDS) != 0 {
return groupIDS[0]
}

groupIDS = getManifestFieldGroupIDs(manifest, secondaryJavaManifestGroupIDFields)

if len(groupIDS) != 0 {
return groupIDS[0]
}

return groupID
}

func groupIDFromPomProperties(properties *pkg.PomProperties) (groupID string) {
if properties == nil {
Expand Down

0 comments on commit fe85967

Please sign in to comment.