Skip to content

Commit

Permalink
fix: "or-later" suffix updated to consider deprecated "+" operator (a…
Browse files Browse the repository at this point in the history
…nchore#1907)

* fix: or-later suffix has been updated to consider deprecated +

If a given license has the suffix "or-later" it previously could have
been considered or represented with a "+". Example "GFDL-1.0-or-later"
could have been represented as "GFDL-1.0+". This PR allows the license
list generation to consider "or-later" as == to "+" when generating
permutations for upgrading deprecated licenses.

---------

Signed-off-by: Christopher Phillips <[email protected]>
  • Loading branch information
spiffcs authored Jul 11, 2023
1 parent 584261e commit d5d6fe3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
27 changes: 27 additions & 0 deletions internal/spdxlicense/generate/generate_license_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,23 @@ func Test_processSPDXLicense(t *testing.T) {
"afl3.0.0": "AFL-3.0",
"afmparse": "Afmparse",
"agpl1": "AGPL-1.0-only",
"agpl1+": "AGPL-1.0-or-later",
"agpl1.0": "AGPL-1.0-only",
"agpl1.0+": "AGPL-1.0-or-later",
"agpl1.0.0": "AGPL-1.0-only",
"agpl1.0.0+": "AGPL-1.0-or-later",
"agpl1.0.0only": "AGPL-1.0-only",
"agpl1.0.0orlater": "AGPL-1.0-or-later",
"agpl1.0only": "AGPL-1.0-only",
"agpl1.0orlater": "AGPL-1.0-or-later",
"agpl1only": "AGPL-1.0-only",
"agpl1orlater": "AGPL-1.0-or-later",
"agpl3": "AGPL-3.0-only",
"agpl3+": "AGPL-3.0-or-later",
"agpl3.0": "AGPL-3.0-only",
"agpl3.0+": "AGPL-3.0-or-later",
"agpl3.0.0": "AGPL-3.0-only",
"agpl3.0.0+": "AGPL-3.0-or-later",
"agpl3.0.0only": "AGPL-3.0-only",
"agpl3.0.0orlater": "AGPL-3.0-or-later",
"agpl3.0only": "AGPL-3.0-only",
Expand Down Expand Up @@ -548,8 +554,17 @@ func Test_processSPDXLicense(t *testing.T) {
"ftl": "FTL",
"gd": "GD",
"gfdl1": "GFDL-1.1-only",
"gfdl1+": "GFDL-1.1-or-later",
"gfdl1+invariants": "GFDL-1.1-invariants-or-later",
"gfdl1+noinvariants": "GFDL-1.1-no-invariants-or-later",
"gfdl1.1": "GFDL-1.1-only",
"gfdl1.1+": "GFDL-1.1-or-later",
"gfdl1.1+invariants": "GFDL-1.1-invariants-or-later",
"gfdl1.1+noinvariants": "GFDL-1.1-no-invariants-or-later",
"gfdl1.1.0": "GFDL-1.1-only",
"gfdl1.1.0+": "GFDL-1.1-or-later",
"gfdl1.1.0+invariants": "GFDL-1.1-invariants-or-later",
"gfdl1.1.0+noinvariants": "GFDL-1.1-no-invariants-or-later",
"gfdl1.1.0invariantsonly": "GFDL-1.1-invariants-only",
"gfdl1.1.0invariantsorlater": "GFDL-1.1-invariants-or-later",
"gfdl1.1.0noinvariantsonly": "GFDL-1.1-no-invariants-only",
Expand All @@ -563,7 +578,13 @@ func Test_processSPDXLicense(t *testing.T) {
"gfdl1.1only": "GFDL-1.1-only",
"gfdl1.1orlater": "GFDL-1.1-or-later",
"gfdl1.2": "GFDL-1.2-only",
"gfdl1.2+": "GFDL-1.2-or-later",
"gfdl1.2+invariants": "GFDL-1.2-invariants-or-later",
"gfdl1.2+noinvariants": "GFDL-1.2-no-invariants-or-later",
"gfdl1.2.0": "GFDL-1.2-only",
"gfdl1.2.0+": "GFDL-1.2-or-later",
"gfdl1.2.0+invariants": "GFDL-1.2-invariants-or-later",
"gfdl1.2.0+noinvariants": "GFDL-1.2-no-invariants-or-later",
"gfdl1.2.0invariantsonly": "GFDL-1.2-invariants-only",
"gfdl1.2.0invariantsorlater": "GFDL-1.2-invariants-or-later",
"gfdl1.2.0noinvariantsonly": "GFDL-1.2-no-invariants-only",
Expand All @@ -577,7 +598,13 @@ func Test_processSPDXLicense(t *testing.T) {
"gfdl1.2only": "GFDL-1.2-only",
"gfdl1.2orlater": "GFDL-1.2-or-later",
"gfdl1.3": "GFDL-1.3-only",
"gfdl1.3+": "GFDL-1.3-or-later",
"gfdl1.3+invariants": "GFDL-1.3-invariants-or-later",
"gfdl1.3+noinvariants": "GFDL-1.3-no-invariants-or-later",
"gfdl1.3.0": "GFDL-1.3-only",
"gfdl1.3.0+": "GFDL-1.3-or-later",
"gfdl1.3.0+invariants": "GFDL-1.3-invariants-or-later",
"gfdl1.3.0+noinvariants": "GFDL-1.3-no-invariants-or-later",
"gfdl1.3.0invariantsonly": "GFDL-1.3-invariants-only",
"gfdl1.3.0invariantsorlater": "GFDL-1.3-invariants-or-later",
"gfdl1.3.0noinvariantsonly": "GFDL-1.3-no-invariants-only",
Expand Down
7 changes: 6 additions & 1 deletion internal/spdxlicense/generate/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ func (l License) canReplace(deprecated License) bool {

func buildLicenseIDPermutations(cleanID string) (perms []string) {
lv := findLicenseVersion(cleanID)
addPlusPermutation := strings.HasSuffix(cleanID, "orlater")
vp := versionPermutations(lv)

permSet := strset.New()
version := strings.Join(lv, ".")
for _, p := range vp {
if addPlusPermutation {
base := strings.TrimSuffix(cleanID, "orlater")
plus := p + "+"
permSet.Add(strings.Replace(base, version, plus, 1))
}
permSet.Add(strings.Replace(cleanID, version, p, 1))
}

Expand Down
3 changes: 3 additions & 0 deletions internal/spdxlicense/generate/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func TestLicensePermutations(t *testing.T) {
"gpl3orlater",
"gpl3.0orlater",
"gpl3.0.0orlater",
"gpl3.0.0+",
"gpl3.0+",
"gpl3+",
},
},
{
Expand Down
29 changes: 28 additions & 1 deletion internal/spdxlicense/license_list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/spdxlicense/license_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ func TestLicenceListIDs(t *testing.T) {
assert.Equal(t, "ZPL-2.1", licenseIDs["zpl2.1"])
assert.Equal(t, "GPL-2.0-only", licenseIDs["gpl2"])
assert.Equal(t, "GPL-2.0-or-later", licenseIDs["gpl2+"])
assert.Equal(t, "GFDL-1.2-or-later", licenseIDs["gfdl1.2+"])
assert.NotEmpty(t, Version)
}

0 comments on commit d5d6fe3

Please sign in to comment.