mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 02:26:42 +01:00
Fix: map license URLs to SPDX IDs for machine readable format
Signed-off-by: Avadhut03 <avadhutkul60@gmail.com>
This commit is contained in:
parent
323fd3e34c
commit
d02e3bcf62
@ -1426,6 +1426,8 @@ var licenseIDs = map[string]string{
|
||||
var urlToLicense = map[string]string{
|
||||
"ftp://ftp.tin.org/pub/news/utils/newsx/newsx-1.6.tar.gz": "Zeeff",
|
||||
"http://apache.org/licenses/LICENSE-1.1": "Apache-1.1",
|
||||
"http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html": "LGPL-2.1-only",
|
||||
"http://www.eclipse.org/org/documents/edl-v10.php": "BSD-3-Clause",
|
||||
"http://artlibre.org/licence/lal/licence-art-libre-12/": "LAL-1.2",
|
||||
"http://bits.netizen.com.au/licenses/NOSL/nosl.txt": "NOSL",
|
||||
"http://bzip.org/1.0.5/bzip2-manual-1.0.5.html": "bzip2-1.0.6",
|
||||
|
||||
@ -53,6 +53,18 @@ func TestLicenseByURL(t *testing.T) {
|
||||
wantID: "",
|
||||
wantFound: false,
|
||||
},
|
||||
{
|
||||
name: "EPL-1.0 license URL",
|
||||
url: "http://www.eclipse.org/legal/epl-v10.html",
|
||||
wantID: "EPL-1.0",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "LGPL-2.1-only license URL",
|
||||
url: "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html",
|
||||
wantID: "LGPL-2.1-only",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "Empty URL",
|
||||
url: "",
|
||||
|
||||
@ -25,6 +25,7 @@ import (
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/java/internal/maven"
|
||||
"github.com/anchore/syft/internal/spdxlicense"
|
||||
)
|
||||
|
||||
var archiveFormatGlobs = []string{
|
||||
@ -375,6 +376,11 @@ func toPkgLicenses(ctx context.Context, location *file.Location, licenses []mave
|
||||
if name == "" && url == "" {
|
||||
continue
|
||||
}
|
||||
if licInfo, ok := spdxlicense.LicenseByURL(url); ok {
|
||||
if name == "" {
|
||||
name = licInfo.ID // use detected license ID if no name given
|
||||
}
|
||||
}
|
||||
out = append(out, pkg.NewLicenseFromFieldsWithContext(ctx, name, url, location))
|
||||
}
|
||||
return out
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user