Skip to content

Commit ceedcd5

Browse files
committed
always set the package ID for java packages
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
1 parent f29bea5 commit ceedcd5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

syft/pkg/cataloger/java/archive_parser.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ func (j *archiveParser) parse() ([]pkg.Package, []artifact.Relationship, error)
133133
// add pURLs to all packages found
134134
// note: since package information may change after initial creation when parsing multiple locations within the
135135
// jar, we wait until the conclusion of the parsing process before synthesizing pURLs.
136-
for i, p := range pkgs {
136+
for i := range pkgs {
137+
p := &pkgs[i]
137138
if m, ok := p.Metadata.(pkg.JavaMetadata); ok {
138-
pkgs[i].PURL = packageURL(p.Name, p.Version, m)
139+
p.PURL = packageURL(p.Name, p.Version, m)
139140
} else {
140141
log.WithFields("package", p.String()).Warn("unable to extract java metadata to generate purl")
141142
}
143+
p.SetID()
142144
}
143145

144146
return pkgs, relationships, nil

syft/pkg/cataloger/java/archive_parser_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ func TestParseJar(t *testing.T) {
277277
}
278278

279279
for _, a := range actual {
280+
if a.ID() == "" {
281+
t.Fatalf("empty package ID: %+v", a)
282+
}
283+
280284
e, ok := test.expected[a.Name]
281285
if !ok {
282286
t.Errorf("entry not found: %s", a.Name)

0 commit comments

Comments
 (0)