Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

vr = append(vr, deprecatedLicenseWarnings("legal.license", publiccodev0.Legal.License)...)

if len(vr) == 0 {
return nil
}
Expand Down Expand Up @@ -464,6 +466,8 @@ func validateFieldsV1(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

vr = append(vr, deprecatedLicenseWarnings("legal.license", publiccodev1.Legal.License)...)

if len(vr) == 0 {
return nil
}
Expand Down
57 changes: 57 additions & 0 deletions licenses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package publiccode

import (
"slices"
"strings"

"github.com/github/go-spdx/v2/spdxexp"
"github.com/github/go-spdx/v2/spdxexp/spdxlicenses"
)

// deprecatedLicenseWarnings warns once for every license identifier in the
// SPDX expression that the SPDX License List marks as deprecated. These
// identifiers are still valid, so the manifest is too, but some of them,
// like GPL-3.0, don't say whether later versions of the license apply.
func deprecatedLicenseWarnings(key string, expression string) ValidationResults {
// An invalid expression gives no licenses here: is_spdx_expression
// already reports it.
licenses, _ := spdxexp.ExtractLicenses(expression)

var deprecated []string

for _, license := range licenses {
// A license with an exception comes back as "<id> WITH <exception>".
id, _, _ := strings.Cut(license, " WITH ")

if isDeprecated, canonical := spdxlicenses.IsDeprecatedLicense(id); isDeprecated &&
!slices.Contains(deprecated, canonical) {
deprecated = append(deprecated, canonical)
}
}

slices.Sort(deprecated)

var vr ValidationResults

for _, id := range deprecated {
only, orLater := id+"-only", id+"-or-later"

if valid, _ := spdxexp.ValidateLicenses([]string{only, orLater}); valid {
vr = append(vr, newValidationWarningf(
key,
"'%s' is a DEPRECATED SPDX license identifier. Use '%s' or '%s' instead",
id, only, orLater,
))

continue
}

vr = append(vr, newValidationWarningf(
key,
"'%s' is a DEPRECATED SPDX license identifier. Use its replacement from https://spdx.org/licenses instead",
id,
))
}

return vr
}
43 changes: 43 additions & 0 deletions licenses_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package publiccode

import (
"errors"
"slices"
"testing"
)

func TestDeprecatedLicenseWarnings(t *testing.T) {
tests := []struct {
expression string
want []string
}{
{"AGPL-3.0-or-later", nil},
{"GPL-3.0+", nil},
{"MIT OR Apache-2.0", nil},
{"Invalid License", nil},
{"", nil},
{"gpl-3.0", []string{"'GPL-3.0' is a DEPRECATED SPDX license identifier. Use 'GPL-3.0-only' or 'GPL-3.0-or-later' instead"}},
{"LGPL-2.1 OR LGPL-2.1", []string{"'LGPL-2.1' is a DEPRECATED SPDX license identifier. Use 'LGPL-2.1-only' or 'LGPL-2.1-or-later' instead"}},
{"GPL-2.0 WITH Classpath-exception-2.0", []string{"'GPL-2.0' is a DEPRECATED SPDX license identifier. Use 'GPL-2.0-only' or 'GPL-2.0-or-later' instead"}},
{"GPL-2.0-with-classpath-exception", []string{"'GPL-2.0-with-classpath-exception' is a DEPRECATED SPDX license identifier. Use its replacement from https://spdx.org/licenses instead"}},
}

for _, test := range tests {
t.Run(test.expression, func(t *testing.T) {
var got []string

for _, result := range deprecatedLicenseWarnings("legal.license", test.expression) {
warning, ok := errors.AsType[ValidationWarning](result)
if !ok || warning.Key != "legal.license" {
t.Fatalf("got %#v, want a legal.license ValidationWarning", result)
}

got = append(got, warning.Description)
}

if !slices.Equal(got, test.want) {
t.Errorf("got %q, want %q", got, test.want)
}
})
}
}
50 changes: 50 additions & 0 deletions testdata/v0/valid_with_warnings/no-network/license_deprecated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
publiccodeYmlVersion: "0"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"

platforms:
- web

categories:
- cloud-management

developmentStatus: development

softwareType: "standalone/other"

description:
en-GB:
localisedName: Medusa
shortDescription: >
A rather short description which
is probably useless
longDescription: >
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 158 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 316 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 474 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 632 characters.
features:
- Just one feature

legal:
license: GPL-3.0 # Deprecated SPDX identifier: valid, but should produce a warning.

maintenance:
type: "community"

contacts:
- name: Francesco Rossi

localisation:
localisationReady: true
availableLanguages:
- en
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
publiccodeYmlVersion: "0"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"

platforms:
- web

categories:
- cloud-management

developmentStatus: development

softwareType: "standalone/other"

description:
en-GB:
localisedName: Medusa
shortDescription: >
A rather short description which
is probably useless
longDescription: >
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 158 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 316 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 474 characters.
Very long description of this software, also split
on multiple rows. You should note what the software
is and why one should need it. This is 632 characters.
features:
- Just one feature

legal:
license: EUPL-1.2 OR GPL-2.0 WITH Classpath-exception-2.0 OR (AGPL-3.0 AND eCos-2.0) OR GPL-3.0+ # Warn for each deprecated identifier within the SPDX expression.

maintenance:
type: "community"

contacts:
- name: Francesco Rossi

localisation:
localisationReady: true
availableLanguages:
- en
28 changes: 28 additions & 0 deletions testdata/v1/valid_with_warnings/license_deprecated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
publiccodeYmlVersion: "1"
name: Firefax
url: https://example.com/firefax.git
softwareType: standalone/desktop
platforms:
- linux
- windows
- mac
developmentStatus: stable
description:
en:
shortDescription: Send and receive faxes from the desktop
longDescription: >
Firefax lets you send and receive faxes from a desktop computer
without a fax machine. You can search received faxes in an archive,
schedule outgoing faxes and track their delivery.
legal:
license: AGPL-3.0 OR MIT # AGPL-3.0 is deprecated even when combined with a current identifier.
maintenance:
type: community
contacts:
- name: Jane Doe
localisation:
localisationReady: true
availableLanguages:
- en
- it
- fr
8 changes: 8 additions & 0 deletions v0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func TestValidWithWarningTestcasesV0_NoNetwork(t *testing.T) {
ValidationWarning{File: "", Key: "legal.authorsFile", Description: "This key is DEPRECATED and will be removed in the future. It's safe to drop it", Line: 63, Column: 3},
ValidationWarning{File: "", Key: "IT", Description: "This key is DEPRECATED and will be removed in the future. Migrate its keys as their warnings say, then drop it", Line: 95, Column: 1},
},
"license_deprecated.yml": ValidationResults{
ValidationWarning{Key: "legal.license", Description: "'GPL-3.0' is a DEPRECATED SPDX license identifier. Use 'GPL-3.0-only' or 'GPL-3.0-or-later' instead", Line: 39, Column: 3},
},
"license_deprecated_expression.yml": ValidationResults{
ValidationWarning{Key: "legal.license", Description: "'AGPL-3.0' is a DEPRECATED SPDX license identifier. Use 'AGPL-3.0-only' or 'AGPL-3.0-or-later' instead", Line: 39, Column: 3},
ValidationWarning{Key: "legal.license", Description: "'GPL-2.0' is a DEPRECATED SPDX license identifier. Use 'GPL-2.0-only' or 'GPL-2.0-or-later' instead", Line: 39, Column: 3},
ValidationWarning{Key: "legal.license", Description: "'eCos-2.0' is a DEPRECATED SPDX license identifier. Use its replacement from https://spdx.org/licenses instead", Line: 39, Column: 3},
},
}

dir := "testdata/v0/valid_with_warnings/no-network/"
Expand Down