diff --git a/syft/pkg/cataloger/java/archive_parser.go b/syft/pkg/cataloger/java/archive_parser.go index cc92798cf04..e1b03b4379a 100644 --- a/syft/pkg/cataloger/java/archive_parser.go +++ b/syft/pkg/cataloger/java/archive_parser.go @@ -181,6 +181,7 @@ func (j *archiveParser) discoverMainPackage() (*pkg.Package, error) { return &pkg.Package{ Name: selectName(manifest, j.fileInfo), Version: selectVersion(manifest, j.fileInfo), + Licenses: selectLicense(manifest), Language: pkg.Java, Locations: source.NewLocationSet(j.location), Type: j.fileInfo.pkgType(), diff --git a/syft/pkg/cataloger/java/archive_parser_test.go b/syft/pkg/cataloger/java/archive_parser_test.go index 480528b025c..c331dbbf89b 100644 --- a/syft/pkg/cataloger/java/archive_parser_test.go +++ b/syft/pkg/cataloger/java/archive_parser_test.go @@ -99,6 +99,7 @@ func TestParseJar(t *testing.T) { Name: "example-jenkins-plugin", Version: "1.0-SNAPSHOT", PURL: "pkg:maven/io.jenkins.plugins/example-jenkins-plugin@1.0-SNAPSHOT", + Licenses: []string{"MIT License"}, Language: pkg.Java, Type: pkg.JenkinsPluginPkg, MetadataType: pkg.JavaMetadataType, @@ -149,6 +150,7 @@ func TestParseJar(t *testing.T) { Name: "example-java-app-gradle", Version: "0.1.0", PURL: "pkg:maven/example-java-app-gradle/example-java-app-gradle@0.1.0", + Licenses: []string{}, Language: pkg.Java, Type: pkg.JavaPkg, MetadataType: pkg.JavaMetadataType, @@ -174,6 +176,7 @@ func TestParseJar(t *testing.T) { Name: "example-java-app-maven", Version: "0.1.0", PURL: "pkg:maven/org.anchore/example-java-app-maven@0.1.0", + Licenses: []string{}, Language: pkg.Java, Type: pkg.JavaPkg, MetadataType: pkg.JavaMetadataType, diff --git a/syft/pkg/cataloger/java/parse_java_manifest.go b/syft/pkg/cataloger/java/parse_java_manifest.go index 93e2823ff4c..134aa22976c 100644 --- a/syft/pkg/cataloger/java/parse_java_manifest.go +++ b/syft/pkg/cataloger/java/parse_java_manifest.go @@ -157,6 +157,26 @@ func selectVersion(manifest *pkg.JavaManifest, filenameObj archiveFilename) stri return "" } +func selectLicense(manifest *pkg.JavaManifest) []string { + result := []string{} + if manifest == nil { + return result + } + + fieldNames := []string{ + "Bundle-License", + "Plugin-License-Name", + } + + for _, fieldName := range fieldNames { + if v := fieldValueFromManifest(*manifest, fieldName); v != "" { + result = append(result, v) + } + } + + return result +} + func fieldValueFromManifest(manifest pkg.JavaManifest, fieldName string) string { if value := manifest.Main[fieldName]; value != "" { return value