Skip to content

Commit

Permalink
fix(java): improve identification for org.eclipse.platform artifacts
Browse files Browse the repository at this point in the history
Signed-off-by: Weston Steimel <[email protected]>
  • Loading branch information
westonsteimel committed Nov 22, 2023
1 parent 8ee209a commit 5e7adef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions syft/pkg/cataloger/common/cpe/java_groupid_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,4 +1199,5 @@ var DefaultArtifactIDToGroupID = map[string]string{
"spring-webflow": "org.springframework.webflow",
"spring-ws": "org.springframework.ws",
"spring-xml": "org.springframework.ws",
"org.eclipse.ant.core": "org.eclipse.platform",
}
26 changes: 19 additions & 7 deletions syft/pkg/cataloger/java/parse_java_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,32 @@ func extractNameFromApacheMavenBundlePlugin(manifest *pkg.JavaManifest) string {
return ""
}

func extractNameFromArchiveFilename(a archiveFilename) string {
if strings.Contains(a.name, ".") {
// special case: this *might* be a group id + artifact id. By convention artifact ids do not have "." in them;
// however, there are some specific exceptions like with the artifacts under
// https://repo1.maven.org/maven2/org/eclipse/platform/
if strings.HasPrefix(a.name, "org.eclipse.") {
return a.name
}

fields := strings.Split(a.name, ".")
return fields[len(fields)-1]
}

return a.name
}

func selectName(manifest *pkg.JavaManifest, filenameObj archiveFilename) string {
name := extractNameFromApacheMavenBundlePlugin(manifest)
if name != "" {
return name
}

// the filename tends to be the next-best reference for the package name
if filenameObj.name != "" {
if strings.Contains(filenameObj.name, ".") {
// special case: this *might* be a group id + artifact id. By convention artifact ids do not have "." in them.
fields := strings.Split(filenameObj.name, ".")
return fields[len(fields)-1]
}
return filenameObj.name
name = extractNameFromArchiveFilename(filenameObj)
if name != "" {
return name
}

// remaining fields in the manifest is a bit of a free-for-all depending on the build tooling used and package maintainer preferences
Expand Down

0 comments on commit 5e7adef

Please sign in to comment.