Skip to content

Commit fb22319

Browse files
author
Tim Clifford
committed
add support for MPL license
1 parent 7c013a1 commit fb22319

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ to any file that already has one.
1616

1717
-c copyright holder (defaults to "Google LLC")
1818
-f custom license file (no default)
19-
-l license type: apache, bsd, mit (defaults to "apache")
19+
-l license type: apache, bsd, mit, mpl (defaults to "apache")
2020
-y year (defaults to current year)
2121
-check check only mode: verify presence of license headers and exit with non-zero code if missing
2222

main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Flags:
4848

4949
var (
5050
holder = flag.String("c", "Google LLC", "copyright holder")
51-
license = flag.String("l", "apache", "license type: apache, bsd, mit")
51+
license = flag.String("l", "apache", "license type: apache, bsd, mit, mpl")
5252
licensef = flag.String("f", "", "license file")
5353
year = flag.String("y", fmt.Sprint(time.Now().Year()), "copyright year(s)")
5454
verbose = flag.Bool("v", false, "verbose mode: print the name of the files that are modified")
@@ -267,5 +267,6 @@ func hasLicense(b []byte) bool {
267267
if len(b) < 1000 {
268268
n = len(b)
269269
}
270-
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright"))
270+
return bytes.Contains(bytes.ToLower(b[:n]), []byte("copyright")) ||
271+
bytes.Contains(bytes.ToLower(b[:n]), []byte("mozilla public"))
271272
}

main_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,25 @@ func TestCheckFail(t *testing.T) {
184184
t.Fatalf("TestCheckFail exited with a zero exit code.\n%s", out)
185185
}
186186
}
187+
188+
func TestMPL(t *testing.T) {
189+
if os.Getenv("RUNME") != "" {
190+
main()
191+
return
192+
}
193+
194+
tmp := tempDir(t)
195+
t.Logf("tmp dir: %s", tmp)
196+
samplefile := filepath.Join(tmp, "file.c")
197+
198+
run(t, "cp", "testdata/expected/file.c", samplefile)
199+
cmd := exec.Command(os.Args[0],
200+
"-test.run=TestMPL",
201+
"-l", "mpl", "-c", "Google LLC", "-y", "2018",
202+
"-check", samplefile,
203+
)
204+
cmd.Env = []string{"RUNME=1"}
205+
if out, err := cmd.CombinedOutput(); err != nil {
206+
t.Fatalf("%v\n%s", err, out)
207+
}
208+
}

tmpl.go

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func init() {
2929
licenseTemplate["apache"] = template.Must(template.New("").Parse(tmplApache))
3030
licenseTemplate["mit"] = template.Must(template.New("").Parse(tmplMIT))
3131
licenseTemplate["bsd"] = template.Must(template.New("").Parse(tmplBSD))
32+
licenseTemplate["mpl"] = template.Must(template.New("").Parse(tmplMPL))
3233
}
3334

3435
type copyrightData struct {
@@ -94,3 +95,7 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
9495
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
9596
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
9697
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.`
98+
99+
const tmplMPL = `This Source Code Form is subject to the terms of the Mozilla Public
100+
License, v. 2.0. If a copy of the MPL was not distributed with this
101+
file, You can obtain one at https://mozilla.org/MPL/2.0/.`

0 commit comments

Comments
 (0)