Skip to content

Commit 40baa7e

Browse files
committed
refactor: share license file name set via pkg/licensing
1 parent aef1854 commit 40baa7e

3 files changed

Lines changed: 6 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,10 @@ import (
2323
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
2424
"github.com/aquasecurity/trivy/pkg/licensing"
2525
"github.com/aquasecurity/trivy/pkg/log"
26-
"github.com/aquasecurity/trivy/pkg/set"
2726
xio "github.com/aquasecurity/trivy/pkg/x/io"
2827
xos "github.com/aquasecurity/trivy/pkg/x/os"
2928
)
3029

31-
// licenseFileStems are the base names (without extension) of files treated as
32-
// license files inside a jar, matched case-insensitively. It mirrors the set used
33-
// by the standalone license file analyzer (its acceptedFileNames), but matching is
34-
// done on the stem so common variants like LICENSE.txt are also recognized.
35-
var licenseFileStems = set.NewCaseInsensitive("license", "licence", "copyright")
36-
3730
var (
3831
jarFileRegEx = regexp.MustCompile(`^([a-zA-Z0-9\._-]*[^-*])-(\d\S*(?:-SNAPSHOT)?).jar$`)
3932
)
@@ -494,7 +487,7 @@ func isJarLicenseFile(name string) bool {
494487
return false // e.g. license.jar is a nested archive, not a license file
495488
}
496489
stem := strings.TrimSuffix(base, path.Ext(base))
497-
return licenseFileStems.Contains(stem)
490+
return licensing.LicenseFileNames.Contains(stem)
498491
}
499492

500493
// classifyPackedLicense classifies a LICENSE file packed in a jar and returns the

pkg/fanal/analyzer/licensing/license.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ var (
6969
".vue",
7070
".zsh",
7171
)
72-
73-
acceptedFileNames = set.NewCaseInsensitive(
74-
"license",
75-
"licence",
76-
"copyright",
77-
)
7872
)
7973

8074
func init() {
@@ -126,7 +120,7 @@ func (a *licenseFileAnalyzer) Required(filePath string, _ os.FileInfo) bool {
126120
return true
127121
}
128122

129-
return acceptedFileNames.Contains(filepath.Base(filePath))
123+
return licensing.LicenseFileNames.Contains(filepath.Base(filePath))
130124
}
131125

132126
func isHumanReadable(content xio.ReadSeekerAt, fileSize int64) (bool, error) {

pkg/licensing/classifier.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"github.com/aquasecurity/trivy/pkg/set"
1616
)
1717

18+
// LicenseFileNames are the base names (case-insensitive, without extension) of files
19+
// commonly used to hold a license, e.g. LICENSE, LICENCE, COPYRIGHT.
20+
var LicenseFileNames = set.NewCaseInsensitive("license", "licence", "copyright")
21+
1822
var (
1923
cf *classifier.Classifier
2024
classifierOnce sync.Once

0 commit comments

Comments
 (0)