Add alternative versions of the GPL-3.0 and GPL 2.0 with autoconf exception headers.
This was originally flagged in cl/401324771
When making this change I hit an out of bands issue in the LicenseName function. I made a small change and included some basic unit tests.
TESTED: Unit tests
PiperOrigin-RevId: 402911320
diff --git a/v2/classifier.go b/v2/classifier.go
index f970543..e146968 100644
--- a/v2/classifier.go
+++ b/v2/classifier.go
@@ -263,13 +263,13 @@
// of the filename in use.
func LicenseName(in string) string {
out := in
- if idx := strings.Index(in, ".txt"); idx != -1 {
+ if idx := strings.Index(out, ".txt"); idx != -1 {
out = out[0:idx]
}
- if idx := strings.Index(in, "_"); idx != -1 {
+ if idx := strings.Index(out, "_"); idx != -1 {
out = out[0:idx]
}
- if idx := strings.Index(in, ".header"); idx != -1 {
+ if idx := strings.Index(out, ".header"); idx != -1 {
out = out[0:idx]
}
return out
diff --git a/v2/classifier_test.go b/v2/classifier_test.go
index b52b283..e4cab30 100644
--- a/v2/classifier_test.go
+++ b/v2/classifier_test.go
@@ -27,6 +27,7 @@
"testing/iotest"
"github.com/davecgh/go-spew/spew"
+ "github.com/google/go-cmp/cmp"
"path"
)
@@ -267,3 +268,44 @@
}
}
}
+
+func TestLicenseName(t *testing.T) {
+ tests := []struct {
+ input string
+ want string
+ }{
+ {
+ input: "example",
+ want: "example",
+ },
+ {
+ input: "example.txt",
+ want: "example",
+ },
+ {
+ input: "example_a",
+ want: "example",
+ },
+ {
+ input: "example.header",
+ want: "example",
+ },
+ {
+ input: "example.header",
+ want: "example",
+ },
+ {
+ input: "example_a.header.txt",
+ want: "example",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.input, func(t *testing.T) {
+ got := LicenseName(tt.input)
+ if diff := cmp.Diff(tt.want, got); diff != "" {
+ t.Errorf("Unexpected result; diff %v", diff)
+ }
+ })
+ }
+}
diff --git a/v2/licenses/GPL-2.0-with-autoconf-exception_a.header.txt b/v2/licenses/GPL-2.0-with-autoconf-exception_a.header.txt
new file mode 100644
index 0000000..11fc5ee
--- /dev/null
+++ b/v2/licenses/GPL-2.0-with-autoconf-exception_a.header.txt
@@ -0,0 +1,25 @@
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+
+As a special exception, the respective Autoconf Macro's copyright owner
+gives unlimited permission to copy, distribute and modify the configure
+scripts that are the output of Autoconf when processing the Macro. You
+need not follow the terms of the GNU General Public License when using
+or distributing such scripts, even though portions of the text of the
+Macro appear in them. The GNU General Public License (GPL) does govern
+all other use of the material that constitutes the Autoconf Macro.
+
+This special exception to the GPL applies to versions of the Autoconf
+Macro released by the Autoconf Archive. When you make and distribute a
+modified version of the Autoconf Macro, you may extend this special
+exception to the GPL to apply to your modified version as well.
diff --git a/v2/licenses/GPL-3.0-with-autoconf-exception_a.header.txt b/v2/licenses/GPL-3.0-with-autoconf-exception_a.header.txt
new file mode 100644
index 0000000..04dab71
--- /dev/null
+++ b/v2/licenses/GPL-3.0-with-autoconf-exception_a.header.txt
@@ -0,0 +1,25 @@
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+
+As a special exception, the respective Autoconf Macro's copyright owner
+gives unlimited permission to copy, distribute and modify the configure
+scripts that are the output of Autoconf when processing the Macro. You
+need not follow the terms of the GNU General Public License when using
+or distributing such scripts, even though portions of the text of the
+Macro appear in them. The GNU General Public License (GPL) does govern
+all other use of the material that constitutes the Autoconf Macro.
+
+This special exception to the GPL applies to versions of the Autoconf
+Macro released by the Autoconf Archive. When you make and distribute a
+modified version of the Autoconf Macro, you may extend this special
+exception to the GPL to apply to your modified version as well.