Skip to content

Commit c9ef275

Browse files
committed
refactor: simplify owner package lookup in attachFileLicenses
1 parent 2c59218 commit c9ef275

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

pkg/dependency/parser/java/jar/parse.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,22 @@ func (p *Parser) attachFileLicenses(pkgs []ftypes.Package, filePath string, lice
285285
return
286286
}
287287

288-
var own []int
288+
var pkg *ftypes.Package
289+
289290
for i := range pkgs {
290-
if pkgs[i].FilePath == filePath {
291-
own = append(own, i)
291+
if pkgs[i].FilePath != filePath {
292+
continue
293+
}
294+
if pkg != nil {
295+
return // more than one package belongs to this jar
292296
}
297+
pkg = &pkgs[i]
293298
}
294-
if len(own) != 1 {
295-
return
299+
300+
if pkg == nil {
301+
return // no package belongs to this jar
296302
}
297303

298-
pkg := &pkgs[own[0]]
299304
if len(pkg.Licenses) > 0 {
300305
return
301306
}

0 commit comments

Comments
 (0)