-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sbom-cataloger
- Loading branch information
Showing
103 changed files
with
845 additions
and
11,978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,54 @@ import ( | |
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_parsePomXML(t *testing.T) { | ||
func Test_parserPomXML(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
expected []*pkg.Package | ||
}{ | ||
{ | ||
input: "test-fixtures/pom/pom.xml", | ||
expected: []*pkg.Package{ | ||
{ | ||
Name: "joda-time", | ||
Version: "2.9.2", | ||
FoundBy: javaPomCataloger, | ||
Language: pkg.Java, | ||
Type: pkg.JavaPkg, | ||
MetadataType: pkg.JavaMetadataType, | ||
Metadata: pkg.JavaMetadata{ | ||
PURL: "pkg:maven/joda-time/[email protected]", | ||
}, | ||
}, | ||
{ | ||
Name: "junit", | ||
Version: "4.12", | ||
FoundBy: "java-pom-cataloger", | ||
Language: pkg.Java, | ||
Type: pkg.JavaPkg, | ||
MetadataType: pkg.JavaMetadataType, | ||
Metadata: pkg.JavaMetadata{ | ||
PURL: "pkg:maven/junit/[email protected]", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.input, func(t *testing.T) { | ||
fixture, err := os.Open(test.input) | ||
assert.NoError(t, err) | ||
|
||
actual, relationships, err := parserPomXML(fixture.Name(), fixture) | ||
assert.NoError(t, err) | ||
assert.Nil(t, relationships) | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
func Test_parsePomXMLProject(t *testing.T) { | ||
tests := []struct { | ||
expected pkg.PomProject | ||
}{ | ||
|
@@ -37,7 +84,7 @@ func Test_parsePomXML(t *testing.T) { | |
fixture, err := os.Open(test.expected.Path) | ||
assert.NoError(t, err) | ||
|
||
actual, err := parsePomXML(fixture.Name(), fixture) | ||
actual, err := parsePomXMLProject(fixture.Name(), fixture) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, &test.expected, actual) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package java | ||
|
||
import "github.com/anchore/syft/syft/pkg/cataloger/common" | ||
|
||
const javaPomCataloger = "java-pom-cataloger" | ||
|
||
// NewJavaPomCataloger returns a cataloger capable of parsing | ||
// dependencies from a pom.xml file. | ||
// Pom files list dependencies that maybe not be locally installed yet. | ||
func NewJavaPomCataloger() *common.GenericCataloger { | ||
globParsers := make(map[string]common.ParserFn) | ||
|
||
// java project files | ||
globParsers[pomXMLDirGlob] = parserPomXML | ||
|
||
return common.NewGenericCataloger(nil, globParsers, javaPomCataloger) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.anchore</groupId> | ||
<artifactId>example-java-app-maven</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.1.0</version> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- tag::joda[] --> | ||
<dependency> | ||
<groupId>joda-time</groupId> | ||
<artifactId>joda-time</artifactId> | ||
<version>2.9.2</version> | ||
</dependency> | ||
<!-- end::joda[] --> | ||
<!-- tag::junit[] --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- end::junit[] --> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.1</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>hello.HelloWorld</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.