Skip to content

Commit 7af3504

Browse files
authored
Merge pull request #15 from thefirstofthe300/master
Add support for more file types
2 parents 84b339f + 76290e6 commit 7af3504

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+124
-42
lines changed

README.md

+3-2

main.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -135,16 +135,16 @@ func walk(ch chan<- *file, start string) {
135135
func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *copyrightData) error {
136136
var lic []byte
137137
var err error
138-
switch filepath.Ext(path) {
138+
switch fileExtension(path) {
139139
default:
140140
return nil
141141
case ".c", ".h":
142142
lic, err = prefix(tmpl, data, "/*", " * ", " */")
143143
case ".js", ".jsx", ".tsx", ".css", ".tf":
144144
lic, err = prefix(tmpl, data, "/**", " * ", " */")
145-
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart":
145+
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart", ".groovy":
146146
lic, err = prefix(tmpl, data, "", "// ", "")
147-
case ".py", ".sh", ".yaml", ".yml":
147+
case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile":
148148
lic, err = prefix(tmpl, data, "", "# ", "")
149149
case ".el", ".lisp":
150150
lic, err = prefix(tmpl, data, "", ";; ", "")
@@ -178,10 +178,19 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *c
178178
return ioutil.WriteFile(path, b, fmode)
179179
}
180180

181+
func fileExtension(name string) string {
182+
if v := filepath.Ext(name); v != "" {
183+
return strings.ToLower(v)
184+
}
185+
return strings.ToLower(filepath.Base(name))
186+
}
187+
181188
var head = []string{
182-
"#!", // shell script
183-
"<?xml", // XML declaratioon
184-
"<!doctype", // HTML doctype
189+
"#!", // shell script
190+
"<?xml", // XML declaratioon
191+
"<!doctype", // HTML doctype
192+
"# encoding:", // Ruby encoding
193+
"# frozen_string_literal:", // Ruby interpreter instruction
185194
}
186195

187196
func hashBang(b []byte) []byte {

main_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ func TestInitial(t *testing.T) {
5353
for i := 0; i < 2; i++ {
5454
t.Logf("run #%d", i)
5555
targs := []string{"-test.run=TestInitial"}
56-
cargs := []string{"-l", "apache", "-c", "Google Inc.", "-y", "2016", tmp}
56+
cargs := []string{"-l", "apache", "-c", "Google LLC", "-y", "2018", tmp}
5757
c := exec.Command(os.Args[0], append(targs, cargs...)...)
5858
c.Env = []string{"RUNME=1"}
5959
if out, err := c.CombinedOutput(); err != nil {

testdata/expected/Gemfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
puts "Hello world!"

testdata/expected/file.Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM scratch
16+
CMD ["echo", "hello world"]

testdata/expected/file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Google Inc.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testdata/expected/file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016 Google Inc.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testdata/expected/file.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; Copyright 2016 Google Inc.
1+
;; Copyright 2018 Google LLC
22
;;
33
;; Licensed under the Apache License, Version 2.0 (the "License");
44
;; you may not use this file except in compliance with the License.

testdata/expected/file.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Copyright 2016 Google Inc.
1+
% Copyright 2018 Google LLC
22
%
33
% Licensed under the Apache License, Version 2.0 (the "License");
44
% you may not use this file except in compliance with the License.

testdata/expected/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.groovy

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
def dummy_function() {
16+
println "Hello world"
17+
}

testdata/expected/file.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 Google Inc.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testdata/expected/file.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Copyright 2016 Google Inc.
1+
-- Copyright 2018 Google LLC
22
--
33
-- Licensed under the Apache License, Version 2.0 (the "License");
44
-- you may not use this file except in compliance with the License.

testdata/expected/file.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<!--
3-
Copyright 2016 Google Inc.
3+
Copyright 2018 Google LLC
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.

testdata/expected/file.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016 Google Inc.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testdata/expected/file.lisp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; Copyright 2016 Google Inc.
1+
;; Copyright 2018 Google LLC
22
;;
33
;; Licensed under the Apache License, Version 2.0 (the "License");
44
;; you may not use this file except in compliance with the License.

testdata/expected/file.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// Copyright 2016 Google Inc.
2+
// Copyright 2018 Google LLC
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.

testdata/expected/file.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016 Google Inc.
1+
# Copyright 2018 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

testdata/expected/file.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
# Copyright 2018 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
puts "Hello world!"

testdata/expected/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

testdata/expected/file.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016 Google Inc.
2+
* Copyright 2018 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

testdata/expected/file.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2016 Google Inc.
2+
Copyright 2018 Google LLC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

testdata/expected/file1.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2016 Google Inc.
2+
# Copyright 2018 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

testdata/expected/file2.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/go run prog.go $*
2-
# Copyright 2016 Google Inc.
2+
# Copyright 2018 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

testdata/expected/file2.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
22
<!--
3-
Copyright 2016 Google Inc.
3+
Copyright 2018 Google LLC
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.

testdata/initial/Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
puts "Hello world!"

testdata/initial/file.Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM scratch
2+
CMD ["echo", "hello world"]

testdata/initial/file.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def dummy_function() {
2+
println "Hello world"
3+
}

testdata/initial/file.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# frozen_string_literal: true
2+
puts "Hello world!"

tmpl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)