mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Merge pull request #348 from anchore/fix-java-pom-properties-parse-delimiter
Allow for multiple pom.properties delimiters
This commit is contained in:
commit
26a4dd36a8
@ -104,7 +104,7 @@ func (c *GenericCataloger) catalog(contents map[source.Location]io.ReadCloser) (
|
||||
entries, err := parser(location.RealPath, content)
|
||||
if err != nil {
|
||||
// TODO: should we fail? or only log?
|
||||
log.Warnf("cataloger '%s' failed to parse entries (location=%+v): %+v", c.upstreamCataloger, location, err)
|
||||
log.Warnf("cataloger '%s' failed to parse entries (%+v): %+v", c.upstreamCataloger, location, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +142,8 @@ func (j *archiveParser) discoverMainPackage() (*pkg.Package, error) {
|
||||
manifestContents := contents[manifestMatches[0]]
|
||||
manifest, err := parseJavaManifest(j.archivePath, strings.NewReader(manifestContents))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse java manifest (%s): %w", j.virtualPath, err)
|
||||
log.Warnf("failed to parse java manifest (%s): %+v", j.virtualPath, err)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &pkg.Package{
|
||||
@ -175,7 +176,8 @@ func (j *archiveParser) discoverPkgsFromPomProperties(parentPkg *pkg.Package) ([
|
||||
for propsPath, propsContents := range contents {
|
||||
propsObj, err := parsePomProperties(propsPath, strings.NewReader(propsContents))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse pom.properties (%s): %w", j.virtualPath, err)
|
||||
log.Warnf("failed to parse pom.properties (%s): %+v", j.virtualPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if propsObj == nil {
|
||||
|
||||
@ -24,7 +24,7 @@ func parsePomProperties(path string, reader io.Reader) (*pkg.PomProperties, erro
|
||||
continue
|
||||
}
|
||||
|
||||
idx := strings.Index(line, "=")
|
||||
idx := strings.IndexAny(line, "=:")
|
||||
if idx == -1 {
|
||||
return nil, fmt.Errorf("unable to split pom.properties key-value pairs: %q", line)
|
||||
}
|
||||
|
||||
@ -11,11 +11,9 @@ import (
|
||||
|
||||
func TestParseJavaPomProperties(t *testing.T) {
|
||||
tests := []struct {
|
||||
fixture string
|
||||
expected pkg.PomProperties
|
||||
}{
|
||||
{
|
||||
fixture: "test-fixtures/pom/small.pom.properties",
|
||||
expected: pkg.PomProperties{
|
||||
Path: "test-fixtures/pom/small.pom.properties",
|
||||
GroupID: "org.anchore",
|
||||
@ -25,7 +23,6 @@ func TestParseJavaPomProperties(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
fixture: "test-fixtures/pom/extra.pom.properties",
|
||||
expected: pkg.PomProperties{
|
||||
Path: "test-fixtures/pom/extra.pom.properties",
|
||||
GroupID: "org.anchore",
|
||||
@ -38,11 +35,38 @@ func TestParseJavaPomProperties(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
expected: pkg.PomProperties{
|
||||
Path: "test-fixtures/pom/colon-delimited.pom.properties",
|
||||
GroupID: "org.anchore",
|
||||
ArtifactID: "example-java-app-maven",
|
||||
Version: "0.1.0",
|
||||
Extra: map[string]string{},
|
||||
},
|
||||
},
|
||||
{
|
||||
expected: pkg.PomProperties{
|
||||
Path: "test-fixtures/pom/equals-delimited-with-colons.pom.properties",
|
||||
GroupID: "org.anchore",
|
||||
ArtifactID: "example-java:app-maven",
|
||||
Version: "0.1.0:something",
|
||||
Extra: map[string]string{},
|
||||
},
|
||||
},
|
||||
{
|
||||
expected: pkg.PomProperties{
|
||||
Path: "test-fixtures/pom/colon-delimited-with-equals.pom.properties",
|
||||
GroupID: "org.anchore",
|
||||
ArtifactID: "example-java=app-maven",
|
||||
Version: "0.1.0=something",
|
||||
Extra: map[string]string{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.fixture, func(t *testing.T) {
|
||||
fixture, err := os.Open(test.fixture)
|
||||
t.Run(test.expected.Path, func(t *testing.T) {
|
||||
fixture, err := os.Open(test.expected.Path)
|
||||
if err != nil {
|
||||
t.Fatalf("could not open fixture: %+v", err)
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Tue Jul 07 18:59:56 GMT 2020
|
||||
groupId:org.anchore
|
||||
artifactId: example-java=app-maven
|
||||
version: 0.1.0=something
|
||||
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Tue Jul 07 18:59:56 GMT 2020
|
||||
groupId:org.anchore
|
||||
artifactId: example-java-app-maven
|
||||
version: 0.1.0
|
||||
@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Tue Jul 07 18:59:56 GMT 2020
|
||||
groupId=org.anchore
|
||||
artifactId= example-java:app-maven
|
||||
version= 0.1.0:something
|
||||
@ -1,6 +1,8 @@
|
||||
package source
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/anchore/syft/internal/log"
|
||||
|
||||
"github.com/anchore/stereoscope/pkg/file"
|
||||
@ -42,3 +44,21 @@ func NewLocationFromImage(virtualPath string, ref file.Reference, img *image.Ima
|
||||
ref: ref,
|
||||
}
|
||||
}
|
||||
|
||||
func (l Location) String() string {
|
||||
str := ""
|
||||
if l.ref.ID() != 0 {
|
||||
str += fmt.Sprintf("id=%d ", l.ref.ID())
|
||||
}
|
||||
|
||||
str += fmt.Sprintf("RealPath=%q", l.RealPath)
|
||||
|
||||
if l.VirtualPath != "" {
|
||||
str += fmt.Sprintf(" VirtualPath=%q", l.VirtualPath)
|
||||
}
|
||||
|
||||
if l.FileSystemID != "" {
|
||||
str += fmt.Sprintf(" Layer=%q", l.FileSystemID)
|
||||
}
|
||||
return fmt.Sprintf("Location<%s>", str)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user