Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always set the package ID for java packages #1493

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
always set the package ID for java packages
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
wagoodman committed Jan 20, 2023

Verified

This commit was signed with the committer’s verified signature.
wagoodman Alex Goodman
commit ceedcd5b6505807f25296c61e60b4389df6e59fe
6 changes: 4 additions & 2 deletions syft/pkg/cataloger/java/archive_parser.go
Original file line number Diff line number Diff line change
@@ -133,12 +133,14 @@ func (j *archiveParser) parse() ([]pkg.Package, []artifact.Relationship, error)
// add pURLs to all packages found
// note: since package information may change after initial creation when parsing multiple locations within the
// jar, we wait until the conclusion of the parsing process before synthesizing pURLs.
for i, p := range pkgs {
for i := range pkgs {
p := &pkgs[i]
if m, ok := p.Metadata.(pkg.JavaMetadata); ok {
pkgs[i].PURL = packageURL(p.Name, p.Version, m)
p.PURL = packageURL(p.Name, p.Version, m)
} else {
log.WithFields("package", p.String()).Warn("unable to extract java metadata to generate purl")
}
p.SetID()
}

return pkgs, relationships, nil
4 changes: 4 additions & 0 deletions syft/pkg/cataloger/java/archive_parser_test.go
Original file line number Diff line number Diff line change
@@ -277,6 +277,10 @@ func TestParseJar(t *testing.T) {
}

for _, a := range actual {
if a.ID() == "" {
t.Fatalf("empty package ID: %+v", a)
}

e, ok := test.expected[a.Name]
if !ok {
t.Errorf("entry not found: %s", a.Name)