append java nested package names to the virtual path

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2020-10-29 13:52:34 -04:00
parent fc991bc62e
commit ab45be98b8
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
5 changed files with 13 additions and 29 deletions

View File

@ -194,38 +194,19 @@
"implementationTitle": { "implementationTitle": {
"type": "string" "type": "string"
}, },
"implementationVendor": {
"type": "string"
},
"implementationVersion": { "implementationVersion": {
"type": "string" "type": "string"
}, },
"manifestVersion": { "manifestVersion": {
"type": "string" "type": "string"
}, },
"name": {
"type": "string"
},
"specificationTitle": { "specificationTitle": {
"type": "string" "type": "string"
},
"specificationVendor": {
"type": "string"
},
"specificationVersion": {
"type": "string"
} }
}, },
"required": [ "required": [
"extraFields", "extraFields",
"implementationTitle", "manifestVersion"
"implementationVendor",
"implementationVersion",
"manifestVersion",
"name",
"specificationTitle",
"specificationVendor",
"specificationVersion"
], ],
"type": "object" "type": "object"
}, },

View File

@ -177,6 +177,12 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
if propsObj.Version != "" && propsObj.ArtifactID != "" { if propsObj.Version != "" && propsObj.ArtifactID != "" {
// TODO: if there is no parentPkg (no java manifest) one of these poms could be the parent. We should discover the right parent and attach the correct info accordingly to each discovered package // TODO: if there is no parentPkg (no java manifest) one of these poms could be the parent. We should discover the right parent and attach the correct info accordingly to each discovered package
// keep the artifact name within the virtual path if this package does not match the parent package
vPathSuffix := ""
if !strings.HasPrefix(propsObj.ArtifactID, parentPkg.Name) {
vPathSuffix += ":" + propsObj.ArtifactID
}
// discovered props = new package // discovered props = new package
p := pkg.Package{ p := pkg.Package{
Name: propsObj.ArtifactID, Name: propsObj.ArtifactID,
@ -185,7 +191,7 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
Type: pkg.JavaPkg, Type: pkg.JavaPkg,
MetadataType: pkg.JavaMetadataType, MetadataType: pkg.JavaMetadataType,
Metadata: pkg.JavaMetadata{ Metadata: pkg.JavaMetadata{
VirtualPath: j.virtualPath, VirtualPath: j.virtualPath + vPathSuffix,
PomProperties: propsObj, PomProperties: propsObj,
Parent: parentPkg, Parent: parentPkg,
}, },

View File

@ -236,7 +236,9 @@ func TestParseJar(t *testing.T) {
Type: pkg.JavaPkg, Type: pkg.JavaPkg,
MetadataType: pkg.JavaMetadataType, MetadataType: pkg.JavaMetadataType,
Metadata: pkg.JavaMetadata{ Metadata: pkg.JavaMetadata{
VirtualPath: "test-fixtures/java-builds/packages/example-java-app-maven-0.1.0.jar", // ensure that nested packages with different names than that of the parent are appended as
// a suffix on the virtual path
VirtualPath: "test-fixtures/java-builds/packages/example-java-app-maven-0.1.0.jar:joda-time",
PomProperties: &pkg.PomProperties{ PomProperties: &pkg.PomProperties{
Path: "META-INF/maven/joda-time/joda-time/pom.properties", Path: "META-INF/maven/joda-time/joda-time/pom.properties",
GroupID: "joda-time", GroupID: "joda-time",

View File

@ -72,12 +72,6 @@ func parseJavaManifest(reader io.Reader) (*pkg.JavaManifest, error) {
manifest.Sections = sections[1:] manifest.Sections = sections[1:]
} }
// clean select fields
if strings.Trim(manifest.ImplVersion, " ") != "" {
// transform versions with dates attached to just versions (e.g. "1.3 2244 October 5 2008" --> "1.3")
manifest.ImplVersion = strings.Split(manifest.ImplVersion, " ")[0]
}
return &manifest, nil return &manifest, nil
} }

View File

@ -62,10 +62,11 @@ func TestParseJavaManifest(t *testing.T) {
}, },
}, },
{ {
// regression test, we should always keep the full version
fixture: "test-fixtures/manifest/version-with-date", fixture: "test-fixtures/manifest/version-with-date",
expected: pkg.JavaManifest{ expected: pkg.JavaManifest{
ManifestVersion: "1.0", ManifestVersion: "1.0",
ImplVersion: "1.3", // ensure the date is stripped off during processing ImplVersion: "1.3 2244 October 5 2005",
}, },
}, },
} }