Skip to content

Commit

Permalink
chore: address PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Oct 23, 2024
1 parent 85a9f2a commit 3875b4e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
12 changes: 6 additions & 6 deletions syft/pkg/cataloger/java/archive_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func newGenericArchiveParserAdapter(cfg ArchiveCatalogerConfig) genericArchivePa
return genericArchiveParserAdapter{cfg: cfg}
}

// parseJavaArchive is a parser function for java archive contents, returning all Java libraries and nested archives.
func (gap genericArchiveParserAdapter) parseJavaArchiveMain(ctx context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
return gap.parseJavaArchive(ctx, reader, nil)
// parseJavaArchive is a parser function for java archive contents, returning all Java libraries and nested archives
func (gap genericArchiveParserAdapter) parseJavaArchive(ctx context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
return gap.processJavaArchive(ctx, reader, nil)
}

// parseJavaArchive is a parser function for java archive contents, returning all Java libraries and nested archives.
func (gap genericArchiveParserAdapter) parseJavaArchive(ctx context.Context, reader file.LocationReadCloser, parentPkg *pkg.Package) ([]pkg.Package, []artifact.Relationship, error) {
// processJavaArchive processes an archive for java contents, returning all Java libraries and nested archives
func (gap genericArchiveParserAdapter) processJavaArchive(ctx context.Context, reader file.LocationReadCloser, parentPkg *pkg.Package) ([]pkg.Package, []artifact.Relationship, error) {
parser, cleanupFn, err := newJavaArchiveParser(ctx, reader, true, gap.cfg)
// note: even on error, we should always run cleanup functions
defer cleanupFn()
Expand Down Expand Up @@ -583,7 +583,7 @@ func discoverPkgsFromOpener(ctx context.Context, location file.Location, pathWit
nestedLocation := file.NewLocationFromCoordinates(location.Coordinates)
nestedLocation.AccessPath = nestedPath
gap := newGenericArchiveParserAdapter(cfg)
nestedPkgs, nestedRelationships, err := gap.parseJavaArchive(ctx, file.LocationReadCloser{
nestedPkgs, nestedRelationships, err := gap.processJavaArchive(ctx, file.LocationReadCloser{
Location: nestedLocation,
ReadCloser: archiveReadCloser,
}, parentPkg)
Expand Down
6 changes: 3 additions & 3 deletions syft/pkg/cataloger/java/archive_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ func TestParseNestedJar(t *testing.T) {
require.NoError(t, err)
gap := newGenericArchiveParserAdapter(ArchiveCatalogerConfig{})

actual, _, err := gap.parseJavaArchive(context.Background(), file.LocationReadCloser{
actual, _, err := gap.processJavaArchive(context.Background(), file.LocationReadCloser{
Location: file.NewLocation(fixture.Name()),
ReadCloser: fixture,
}, nil)
Expand Down Expand Up @@ -1368,7 +1368,7 @@ func Test_parseJavaArchive_regressions(t *testing.T) {
return true
}),
).
TestParser(t, gap.parseJavaArchiveMain)
TestParser(t, gap.parseJavaArchive)
})
}
}
Expand Down Expand Up @@ -1523,5 +1523,5 @@ func Test_corruptJarArchive(t *testing.T) {
pkgtest.NewCatalogTester().
FromFile(t, "test-fixtures/corrupt/example.jar").
WithError().
TestParser(t, ap.parseJavaArchiveMain)
TestParser(t, ap.parseJavaArchive)
}
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/java/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewArchiveCataloger(cfg ArchiveCatalogerConfig) pkg.Cataloger {
gap := newGenericArchiveParserAdapter(cfg)

c := generic.NewCataloger("java-archive-cataloger").
WithParserByGlobs(gap.parseJavaArchiveMain, archiveFormatGlobs...)
WithParserByGlobs(gap.parseJavaArchive, archiveFormatGlobs...)

if cfg.IncludeIndexedArchives {
// java archives wrapped within zip files
Expand Down
8 changes: 4 additions & 4 deletions syft/pkg/cataloger/java/internal/maven/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ func (r *Resolver) FindPom(ctx context.Context, groupID, artifactID, version str
}

id := ID{groupID, artifactID, version}
pom := r.resolved[id]
existingPom := r.resolved[id]

if pom != nil {
return pom, nil
if existingPom != nil {
return existingPom, nil
}

var errs error
Expand All @@ -334,7 +334,7 @@ func (r *Resolver) FindPom(ctx context.Context, groupID, artifactID, version str
}

// resolve via network maven repository
if pom == nil && r.cfg.UseNetwork {
if r.cfg.UseNetwork {
pom, err := r.findPomInRemotes(ctx, groupID, artifactID, version)
if pom != nil {
r.resolved[id] = pom
Expand Down
12 changes: 7 additions & 5 deletions syft/pkg/cataloger/java/parse_pom_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Test_parseCommonsTextPomXMLProject(t *testing.T) {
UseNetwork: false,
UseMavenLocalRepository: false,
},
expected: getCommonsTextExpectedPackages(file.NewLocation("pom.xml"), false),
expected: getCommonsTextExpectedPackages(false),
},
{
name: "use network",
Expand All @@ -148,7 +148,7 @@ func Test_parseCommonsTextPomXMLProject(t *testing.T) {
MavenBaseURL: mavenBaseURL,
UseMavenLocalRepository: false,
},
expected: getCommonsTextExpectedPackages(file.NewLocation("pom.xml"), true),
expected: getCommonsTextExpectedPackages(true),
},
{
name: "use local repository",
Expand All @@ -158,7 +158,7 @@ func Test_parseCommonsTextPomXMLProject(t *testing.T) {
UseMavenLocalRepository: true,
MavenLocalRepositoryDir: mavenLocalRepoDir,
},
expected: getCommonsTextExpectedPackages(file.NewLocation("pom.xml"), true),
expected: getCommonsTextExpectedPackages(true),
},
{
name: "transitive dependencies",
Expand Down Expand Up @@ -468,7 +468,9 @@ type expected struct {
relationships []artifact.Relationship
}

func getCommonsTextExpectedPackages(loc file.Location, resolved bool) expected {
func getCommonsTextExpectedPackages(resolved bool) expected {
pomXmlLocation := file.NewLocationSet(file.NewLocation("pom.xml"))

commonsText := pkg.Package{
Name: "commons-text",
Version: "1.10.0",
Expand Down Expand Up @@ -673,7 +675,7 @@ func getCommonsTextExpectedPackages(loc file.Location, resolved bool) expected {
var relationships []artifact.Relationship
for i := range pkgs {
p := &pkgs[i]
p.Locations = file.NewLocationSet(loc)
p.Locations = pomXmlLocation
finalizePackage(p)
if i == 0 {
continue
Expand Down

0 comments on commit 3875b4e

Please # to comment.