Fixes #1179 Deprecated SPDX license (#1263)

This commit is contained in:
Marc-Etienne Vargenau 2022-10-14 21:54:57 +02:00 committed by GitHub
parent 89575199b8
commit 41bc6bb410
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 65 deletions

View file

@ -22,18 +22,18 @@ func TestReplaceDeprecatedLicenses(t *testing.T) {
}
expected := map[string]string{
"abc-1": "ABC-1.0-Only",
"abc-1-only": "ABC-1.0-Only",
"abc-1.0": "ABC-1.0-Only",
"abc-1.0.0": "ABC-1.0-Only",
"abc-1.0-only": "ABC-1.0-Only",
"abc-1.0.0-only": "ABC-1.0-Only",
"abc-1+": "ABC-1.0-Or-later",
"abc-1.0+": "ABC-1.0-Or-later",
"abc-1.0.0+": "ABC-1.0-Or-later",
"abc-1-or-later": "ABC-1.0-Or-later",
"abc-1.0-or-later": "ABC-1.0-Or-later",
"abc-1.0.0-or-later": "ABC-1.0-Or-later",
"abc-1": "ABC-1.0-only",
"abc-1-only": "ABC-1.0-only",
"abc-1.0": "ABC-1.0-only",
"abc-1.0.0": "ABC-1.0-only",
"abc-1.0-only": "ABC-1.0-only",
"abc-1.0.0-only": "ABC-1.0-only",
"abc-1+": "ABC-1.0-or-later",
"abc-1.0+": "ABC-1.0-or-later",
"abc-1.0.0+": "ABC-1.0-or-later",
"abc-1-or-later": "ABC-1.0-or-later",
"abc-1.0-or-later": "ABC-1.0-or-later",
"abc-1.0.0-or-later": "ABC-1.0-or-later",
"duh-1": "Duh-1.0",
"duh-1.0": "Duh-1.0",
"duh-1.0.0": "Duh-1.0",
@ -79,22 +79,22 @@ func Test_processSPDXLicense(t *testing.T) {
"afl-3.0": "AFL-3.0",
"afl-3.0.0": "AFL-3.0",
"afmparse": "Afmparse",
"agpl-1": "AGPL-1.0",
"agpl-1": "AGPL-1.0-only",
"agpl-1-only": "AGPL-1.0-only",
"agpl-1-or-later": "AGPL-1.0-or-later",
"agpl-1.0": "AGPL-1.0",
"agpl-1.0": "AGPL-1.0-only",
"agpl-1.0-only": "AGPL-1.0-only",
"agpl-1.0-or-later": "AGPL-1.0-or-later",
"agpl-1.0.0": "AGPL-1.0",
"agpl-1.0.0": "AGPL-1.0-only",
"agpl-1.0.0-only": "AGPL-1.0-only",
"agpl-1.0.0-or-later": "AGPL-1.0-or-later",
"agpl-3": "AGPL-3.0",
"agpl-3": "AGPL-3.0-only",
"agpl-3-only": "AGPL-3.0-only",
"agpl-3-or-later": "AGPL-3.0-or-later",
"agpl-3.0": "AGPL-3.0",
"agpl-3.0": "AGPL-3.0-only",
"agpl-3.0-only": "AGPL-3.0-only",
"agpl-3.0-or-later": "AGPL-3.0-or-later",
"agpl-3.0.0": "AGPL-3.0",
"agpl-3.0.0": "AGPL-3.0-only",
"agpl-3.0.0-only": "AGPL-3.0-only",
"agpl-3.0.0-or-later": "AGPL-3.0-or-later",
"aladdin": "Aladdin",
@ -160,18 +160,18 @@ func Test_processSPDXLicense(t *testing.T) {
"bsd-1.0-clause": "BSD-1-Clause",
"bsd-1.0.0-clause": "BSD-1-Clause",
"bsd-2-clause": "BSD-2-Clause",
"bsd-2-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2-clause-netbsd": "BSD-2-Clause",
"bsd-2-clause-patent": "BSD-2-Clause-Patent",
"bsd-2-clause-views": "BSD-2-Clause-Views",
"bsd-2.0-clause": "BSD-2-Clause",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0-clause-views": "BSD-2-Clause-Views",
"bsd-2.0.0-clause": "BSD-2-Clause",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0.0-clause-views": "BSD-2-Clause-Views",
"bsd-3-clause": "BSD-3-Clause",
@ -221,9 +221,9 @@ func Test_processSPDXLicense(t *testing.T) {
"busl-1": "BUSL-1.1",
"busl-1.1": "BUSL-1.1",
"busl-1.1.0": "BUSL-1.1",
"bzip2-1": "bzip2-1.0.5",
"bzip2-1.0": "bzip2-1.0.5",
"bzip2-1.0.5": "bzip2-1.0.5",
"bzip2-1": "bzip2-1.0.6",
"bzip2-1.0": "bzip2-1.0.6",
"bzip2-1.0.5": "bzip2-1.0.6",
"bzip2-1.0.6": "bzip2-1.0.6",
"c-uda-1": "C-UDA-1.0",
"c-uda-1.0": "C-UDA-1.0",
@ -520,49 +520,49 @@ func Test_processSPDXLicense(t *testing.T) {
"fsfullr": "FSFULLR",
"ftl": "FTL",
"gd": "GD",
"gfdl-1": "GFDL-1.1",
"gfdl-1": "GFDL-1.1-only",
"gfdl-1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1-only": "GFDL-1.1-only",
"gfdl-1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1": "GFDL-1.1",
"gfdl-1.1": "GFDL-1.1-only",
"gfdl-1.1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1-only": "GFDL-1.1-only",
"gfdl-1.1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1.0": "GFDL-1.1",
"gfdl-1.1.0": "GFDL-1.1-only",
"gfdl-1.1.0-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1.0-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1.0-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1.0-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1.0-only": "GFDL-1.1-only",
"gfdl-1.1.0-or-later": "GFDL-1.1-or-later",
"gfdl-1.2": "GFDL-1.2",
"gfdl-1.2": "GFDL-1.2-only",
"gfdl-1.2-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2-only": "GFDL-1.2-only",
"gfdl-1.2-or-later": "GFDL-1.2-or-later",
"gfdl-1.2.0": "GFDL-1.2",
"gfdl-1.2.0": "GFDL-1.2-only",
"gfdl-1.2.0-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2.0-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2.0-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2.0-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2.0-only": "GFDL-1.2-only",
"gfdl-1.2.0-or-later": "GFDL-1.2-or-later",
"gfdl-1.3": "GFDL-1.3",
"gfdl-1.3": "GFDL-1.3-only",
"gfdl-1.3-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3-no-invariants-only": "GFDL-1.3-no-invariants-only",
"gfdl-1.3-no-invariants-or-later": "GFDL-1.3-no-invariants-or-later",
"gfdl-1.3-only": "GFDL-1.3-only",
"gfdl-1.3-or-later": "GFDL-1.3-or-later",
"gfdl-1.3.0": "GFDL-1.3",
"gfdl-1.3.0": "GFDL-1.3-only",
"gfdl-1.3.0-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3.0-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3.0-no-invariants-only": "GFDL-1.3-no-invariants-only",
@ -686,11 +686,11 @@ func Test_processSPDXLicense(t *testing.T) {
"lgpl-2.0.0-only": "LGPL-2.0-only",
"lgpl-2.0.0-or-later": "LGPL-2.0-or-later",
"lgpl-2.1": "LGPL-2.1-only",
"lgpl-2.1+": "LGPL-2.1+",
"lgpl-2.1+": "LGPL-2.1-or-later",
"lgpl-2.1-only": "LGPL-2.1-only",
"lgpl-2.1-or-later": "LGPL-2.1-or-later",
"lgpl-2.1.0": "LGPL-2.1-only",
"lgpl-2.1.0+": "LGPL-2.1+",
"lgpl-2.1.0+": "LGPL-2.1-or-later",
"lgpl-2.1.0-only": "LGPL-2.1-only",
"lgpl-2.1.0-or-later": "LGPL-2.1-or-later",
"lgpl-3": "LGPL-3.0-only",

View file

@ -25,6 +25,23 @@ func (l License) canReplace(other License) bool {
return false
}
// We want to replace deprecated licenses with non-deprecated counterparts
// For more information, see: https://github.com/spdx/license-list-XML/issues/1676
if other.Deprecated {
switch {
case strings.ReplaceAll(l.ID, "-only", "") == other.ID:
return true
case strings.ReplaceAll(l.ID, "-or-later", "+") == other.ID:
return true
case l.ID == "BSD-2-Clause" && other.ID == "BSD-2-Clause-NetBSD":
return true
case l.ID == "BSD-2-Clause-Views" && other.ID == "BSD-2-Clause-FreeBSD":
return true
case l.ID == "bzip2-1.0.6" && other.ID == "bzip2-1.0.5":
return true
}
}
if l.Name != other.Name {
return false
}
@ -43,7 +60,7 @@ func (l License) canReplace(other License) bool {
}
}
return l.ID != other.ID
return l.ID == other.ID
}
func (ll LicenseList) findReplacementLicense(deprecated License) *License {

View file

@ -15,7 +15,7 @@ var (
}
license2 = License{
ID: "ABC-1.0-Or-later",
ID: "ABC-1.0-or-later",
Name: "The ABC License 1.0",
}
@ -26,7 +26,7 @@ var (
}
license4 = License{
ID: "ABC-1.0-Only",
ID: "ABC-1.0-only",
Name: "The ABC License 1.0 Only",
}
license5 = License{
@ -53,7 +53,9 @@ func TestLicense_canReplace(t *testing.T) {
}
for _, tt := range tests {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
t.Run(tt.l1.ID+" - "+tt.l2.ID, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.l1.canReplace(tt.l2))
})
}
}

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at 2022-08-16 13:37:43.053262 -0400 EDT m=+0.183888850
// This file was generated by robots at 2022-10-14 11:46:16.097525 -0400 EDT m=+0.276930979
// using data from https://spdx.org/licenses/licenses.json
package spdxlicense
@ -28,22 +28,22 @@ var licenseIDs = map[string]string{
"afl-3.0": "AFL-3.0",
"afl-3.0.0": "AFL-3.0",
"afmparse": "Afmparse",
"agpl-1": "AGPL-1.0",
"agpl-1": "AGPL-1.0-only",
"agpl-1-only": "AGPL-1.0-only",
"agpl-1-or-later": "AGPL-1.0-or-later",
"agpl-1.0": "AGPL-1.0",
"agpl-1.0": "AGPL-1.0-only",
"agpl-1.0-only": "AGPL-1.0-only",
"agpl-1.0-or-later": "AGPL-1.0-or-later",
"agpl-1.0.0": "AGPL-1.0",
"agpl-1.0.0": "AGPL-1.0-only",
"agpl-1.0.0-only": "AGPL-1.0-only",
"agpl-1.0.0-or-later": "AGPL-1.0-or-later",
"agpl-3": "AGPL-3.0",
"agpl-3": "AGPL-3.0-only",
"agpl-3-only": "AGPL-3.0-only",
"agpl-3-or-later": "AGPL-3.0-or-later",
"agpl-3.0": "AGPL-3.0",
"agpl-3.0": "AGPL-3.0-only",
"agpl-3.0-only": "AGPL-3.0-only",
"agpl-3.0-or-later": "AGPL-3.0-or-later",
"agpl-3.0.0": "AGPL-3.0",
"agpl-3.0.0": "AGPL-3.0-only",
"agpl-3.0.0-only": "AGPL-3.0-only",
"agpl-3.0.0-or-later": "AGPL-3.0-or-later",
"aladdin": "Aladdin",
@ -109,18 +109,18 @@ var licenseIDs = map[string]string{
"bsd-1.0-clause": "BSD-1-Clause",
"bsd-1.0.0-clause": "BSD-1-Clause",
"bsd-2-clause": "BSD-2-Clause",
"bsd-2-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2-clause-netbsd": "BSD-2-Clause",
"bsd-2-clause-patent": "BSD-2-Clause-Patent",
"bsd-2-clause-views": "BSD-2-Clause-Views",
"bsd-2.0-clause": "BSD-2-Clause",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0-clause-views": "BSD-2-Clause-Views",
"bsd-2.0.0-clause": "BSD-2-Clause",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-FreeBSD",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause-NetBSD",
"bsd-2.0.0-clause-freebsd": "BSD-2-Clause-Views",
"bsd-2.0.0-clause-netbsd": "BSD-2-Clause",
"bsd-2.0.0-clause-patent": "BSD-2-Clause-Patent",
"bsd-2.0.0-clause-views": "BSD-2-Clause-Views",
"bsd-3-clause": "BSD-3-Clause",
@ -170,9 +170,9 @@ var licenseIDs = map[string]string{
"busl-1": "BUSL-1.1",
"busl-1.1": "BUSL-1.1",
"busl-1.1.0": "BUSL-1.1",
"bzip2-1": "bzip2-1.0.5",
"bzip2-1.0": "bzip2-1.0.5",
"bzip2-1.0.5": "bzip2-1.0.5",
"bzip2-1": "bzip2-1.0.6",
"bzip2-1.0": "bzip2-1.0.6",
"bzip2-1.0.5": "bzip2-1.0.6",
"bzip2-1.0.6": "bzip2-1.0.6",
"c-uda-1": "C-UDA-1.0",
"c-uda-1.0": "C-UDA-1.0",
@ -472,49 +472,49 @@ var licenseIDs = map[string]string{
"fsfullr": "FSFULLR",
"ftl": "FTL",
"gd": "GD",
"gfdl-1": "GFDL-1.1",
"gfdl-1": "GFDL-1.1-only",
"gfdl-1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1-only": "GFDL-1.1-only",
"gfdl-1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1": "GFDL-1.1",
"gfdl-1.1": "GFDL-1.1-only",
"gfdl-1.1-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1-only": "GFDL-1.1-only",
"gfdl-1.1-or-later": "GFDL-1.1-or-later",
"gfdl-1.1.0": "GFDL-1.1",
"gfdl-1.1.0": "GFDL-1.1-only",
"gfdl-1.1.0-invariants-only": "GFDL-1.1-invariants-only",
"gfdl-1.1.0-invariants-or-later": "GFDL-1.1-invariants-or-later",
"gfdl-1.1.0-no-invariants-only": "GFDL-1.1-no-invariants-only",
"gfdl-1.1.0-no-invariants-or-later": "GFDL-1.1-no-invariants-or-later",
"gfdl-1.1.0-only": "GFDL-1.1-only",
"gfdl-1.1.0-or-later": "GFDL-1.1-or-later",
"gfdl-1.2": "GFDL-1.2",
"gfdl-1.2": "GFDL-1.2-only",
"gfdl-1.2-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2-only": "GFDL-1.2-only",
"gfdl-1.2-or-later": "GFDL-1.2-or-later",
"gfdl-1.2.0": "GFDL-1.2",
"gfdl-1.2.0": "GFDL-1.2-only",
"gfdl-1.2.0-invariants-only": "GFDL-1.2-invariants-only",
"gfdl-1.2.0-invariants-or-later": "GFDL-1.2-invariants-or-later",
"gfdl-1.2.0-no-invariants-only": "GFDL-1.2-no-invariants-only",
"gfdl-1.2.0-no-invariants-or-later": "GFDL-1.2-no-invariants-or-later",
"gfdl-1.2.0-only": "GFDL-1.2-only",
"gfdl-1.2.0-or-later": "GFDL-1.2-or-later",
"gfdl-1.3": "GFDL-1.3",
"gfdl-1.3": "GFDL-1.3-only",
"gfdl-1.3-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3-no-invariants-only": "GFDL-1.3-no-invariants-only",
"gfdl-1.3-no-invariants-or-later": "GFDL-1.3-no-invariants-or-later",
"gfdl-1.3-only": "GFDL-1.3-only",
"gfdl-1.3-or-later": "GFDL-1.3-or-later",
"gfdl-1.3.0": "GFDL-1.3",
"gfdl-1.3.0": "GFDL-1.3-only",
"gfdl-1.3.0-invariants-only": "GFDL-1.3-invariants-only",
"gfdl-1.3.0-invariants-or-later": "GFDL-1.3-invariants-or-later",
"gfdl-1.3.0-no-invariants-only": "GFDL-1.3-no-invariants-only",
@ -637,11 +637,11 @@ var licenseIDs = map[string]string{
"lgpl-2.0.0-only": "LGPL-2.0-only",
"lgpl-2.0.0-or-later": "LGPL-2.0-or-later",
"lgpl-2.1": "LGPL-2.1-only",
"lgpl-2.1+": "LGPL-2.1+",
"lgpl-2.1+": "LGPL-2.1-or-later",
"lgpl-2.1-only": "LGPL-2.1-only",
"lgpl-2.1-or-later": "LGPL-2.1-or-later",
"lgpl-2.1.0": "LGPL-2.1-only",
"lgpl-2.1.0+": "LGPL-2.1+",
"lgpl-2.1.0+": "LGPL-2.1-or-later",
"lgpl-2.1.0-only": "LGPL-2.1-only",
"lgpl-2.1.0-or-later": "LGPL-2.1-or-later",
"lgpl-3": "LGPL-3.0-only",