From 12f10136e4845249367b54147055a0055fc4b47f Mon Sep 17 00:00:00 2001 From: Daniel Seymour Date: Tue, 18 Dec 2018 17:21:13 -0800 Subject: [PATCH 1/3] Add support for several other file types Adds support for Dockerfiles, Gemfiles, Ruby files, and Groovy files. Also, in order to fully support Dockerfile and Gemfiles, a new file extension parser was created to deal with files that do not have an extension. --- main.go | 21 +++++++++++++++------ testdata/expected/Gemfile | 15 +++++++++++++++ testdata/expected/file.Dockerfile | 16 ++++++++++++++++ testdata/expected/file.groovy | 17 +++++++++++++++++ testdata/expected/file.rb | 16 ++++++++++++++++ testdata/initial/Gemfile | 1 + testdata/initial/file.Dockerfile | 2 ++ testdata/initial/file.groovy | 3 +++ testdata/initial/file.rb | 2 ++ 9 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 testdata/expected/Gemfile create mode 100644 testdata/expected/file.Dockerfile create mode 100644 testdata/expected/file.groovy create mode 100644 testdata/expected/file.rb create mode 100644 testdata/initial/Gemfile create mode 100644 testdata/initial/file.Dockerfile create mode 100644 testdata/initial/file.groovy create mode 100644 testdata/initial/file.rb diff --git a/main.go b/main.go index 90a0445..352d497 100644 --- a/main.go +++ b/main.go @@ -135,16 +135,16 @@ func walk(ch chan<- *file, start string) { func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *copyrightData) error { var lic []byte var err error - switch filepath.Ext(path) { + switch fileExtension(path) { default: return nil case ".c", ".h": lic, err = prefix(tmpl, data, "/*", " * ", " */") case ".js", ".jsx", ".tsx", ".css", ".tf": lic, err = prefix(tmpl, data, "/**", " * ", " */") - case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart": + case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart", ".groovy": lic, err = prefix(tmpl, data, "", "// ", "") - case ".py", ".sh", ".yaml", ".yml": + case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile": lic, err = prefix(tmpl, data, "", "# ", "") case ".el", ".lisp": lic, err = prefix(tmpl, data, "", ";; ", "") @@ -178,10 +178,19 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *c return ioutil.WriteFile(path, b, fmode) } +func fileExtension(name string) string { + if v := filepath.Ext(name); v != "" { + return strings.ToLower(v) + } + return strings.ToLower(filepath.Base(name)) +} + var head = []string{ - "#!", // shell script - " Date: Wed, 19 Dec 2018 12:31:59 -0800 Subject: [PATCH 2/3] Update test data licenses to use the current year and copyright holder --- main.go | 2 +- main_test.go | 4 ++-- testdata/expected/Gemfile | 2 +- testdata/expected/file.Dockerfile | 2 +- testdata/expected/file.c | 2 +- testdata/expected/file.cc | 2 +- testdata/expected/file.cpp | 2 +- testdata/expected/file.cs | 2 +- testdata/expected/file.css | 2 +- testdata/expected/file.dart | 2 +- testdata/expected/file.el | 2 +- testdata/expected/file.erl | 2 +- testdata/expected/file.go | 2 +- testdata/expected/file.groovy | 2 +- testdata/expected/file.h | 2 +- testdata/expected/file.hh | 2 +- testdata/expected/file.hpp | 2 +- testdata/expected/file.hs | 2 +- testdata/expected/file.html | 2 +- testdata/expected/file.java | 2 +- testdata/expected/file.js | 2 +- testdata/expected/file.lisp | 2 +- testdata/expected/file.m | 2 +- testdata/expected/file.mm | 2 +- testdata/expected/file.php | 2 +- testdata/expected/file.proto | 2 +- testdata/expected/file.py | 2 +- testdata/expected/file.rb | 2 +- testdata/expected/file.rs | 2 +- testdata/expected/file.scala | 2 +- testdata/expected/file.swift | 2 +- testdata/expected/file.tf | 2 +- testdata/expected/file.xml | 2 +- testdata/expected/file1.sh | 2 +- testdata/expected/file2.sh | 2 +- testdata/expected/file2.xml | 2 +- tmpl.go | 2 +- 37 files changed, 38 insertions(+), 38 deletions(-) diff --git a/main.go b/main.go index 352d497..21e317d 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/main_test.go b/main_test.go index c2c0a67..41a95fa 100644 --- a/main_test.go +++ b/main_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ func TestInitial(t *testing.T) { for i := 0; i < 2; i++ { t.Logf("run #%d", i) targs := []string{"-test.run=TestInitial"} - cargs := []string{"-l", "apache", "-c", "Google Inc.", "-y", "2016", tmp} + cargs := []string{"-l", "apache", "-c", "Google LLC", "-y", "2018", tmp} c := exec.Command(os.Args[0], append(targs, cargs...)...) c.Env = []string{"RUNME=1"} if out, err := c.CombinedOutput(); err != nil { diff --git a/testdata/expected/Gemfile b/testdata/expected/Gemfile index 919c8b1..1a245c7 100644 --- a/testdata/expected/Gemfile +++ b/testdata/expected/Gemfile @@ -1,4 +1,4 @@ -# Copyright 2016 Google Inc. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.Dockerfile b/testdata/expected/file.Dockerfile index e08f020..a23d19e 100644 --- a/testdata/expected/file.Dockerfile +++ b/testdata/expected/file.Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2016 Google Inc. +# Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.c b/testdata/expected/file.c index 7876b80..f5f0efd 100644 --- a/testdata/expected/file.c +++ b/testdata/expected/file.c @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.cc b/testdata/expected/file.cc index 53656ed..683ae6b 100644 --- a/testdata/expected/file.cc +++ b/testdata/expected/file.cc @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.cpp b/testdata/expected/file.cpp index 53656ed..683ae6b 100644 --- a/testdata/expected/file.cpp +++ b/testdata/expected/file.cpp @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.cs b/testdata/expected/file.cs index 8137f4f..b2700ef 100644 --- a/testdata/expected/file.cs +++ b/testdata/expected/file.cs @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.css b/testdata/expected/file.css index 8c01d2d..e0ecb5d 100644 --- a/testdata/expected/file.css +++ b/testdata/expected/file.css @@ -1,5 +1,5 @@ /** - * Copyright 2016 Google Inc. + * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.dart b/testdata/expected/file.dart index 8902b4a..e72661d 100644 --- a/testdata/expected/file.dart +++ b/testdata/expected/file.dart @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.el b/testdata/expected/file.el index aa2a060..ab301b8 100644 --- a/testdata/expected/file.el +++ b/testdata/expected/file.el @@ -1,4 +1,4 @@ -;; Copyright 2016 Google Inc. +;; Copyright 2018 Google LLC ;; ;; Licensed under the Apache License, Version 2.0 (the "License"); ;; you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.erl b/testdata/expected/file.erl index 190d223..fdebbaa 100644 --- a/testdata/expected/file.erl +++ b/testdata/expected/file.erl @@ -1,4 +1,4 @@ -% Copyright 2016 Google Inc. +% Copyright 2018 Google LLC % % Licensed under the Apache License, Version 2.0 (the "License"); % you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.go b/testdata/expected/file.go index 7efc920..6a3666a 100644 --- a/testdata/expected/file.go +++ b/testdata/expected/file.go @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.groovy b/testdata/expected/file.groovy index 0bec985..fc86d5b 100644 --- a/testdata/expected/file.groovy +++ b/testdata/expected/file.groovy @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.h b/testdata/expected/file.h index fddab60..eacb361 100644 --- a/testdata/expected/file.h +++ b/testdata/expected/file.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Google Inc. + * Copyright 2018 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.hh b/testdata/expected/file.hh index 817dc30..a2bcb35 100644 --- a/testdata/expected/file.hh +++ b/testdata/expected/file.hh @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.hpp b/testdata/expected/file.hpp index 817dc30..a2bcb35 100644 --- a/testdata/expected/file.hpp +++ b/testdata/expected/file.hpp @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.hs b/testdata/expected/file.hs index 92f22dc..d2e1cb3 100644 --- a/testdata/expected/file.hs +++ b/testdata/expected/file.hs @@ -1,4 +1,4 @@ --- Copyright 2016 Google Inc. +-- Copyright 2018 Google LLC -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. diff --git a/testdata/expected/file.html b/testdata/expected/file.html index 0093653..25d75e7 100644 --- a/testdata/expected/file.html +++ b/testdata/expected/file.html @@ -1,6 +1,6 @@