Add a license-checking Python script (#123)

* Add a license-checking Python script

* Responses to CR
This commit is contained in:
gbrodman 2019-06-21 12:25:35 -04:00 committed by GitHub
parent 00147c1bc4
commit 3a485a03a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 4 deletions

View file

@ -108,6 +108,11 @@ allprojects {
}
}
task licenseCheck(type: Exec) {
executable '/usr/bin/python'
args('config/check_license.py')
}
subprojects {
// Skip no-op project
if (project.name == 'services') return
@ -164,6 +169,8 @@ subprojects {
if (project.name == 'third_party') return
project.tasks.test.dependsOn licenseCheck
// Path to code generated with annotation processors. Note that this path is
// chosen by the 'net.ltgt.apt' plugin, and may change if IDE-specific plugins
// are applied, e.g., 'idea' or 'eclipse'

47
config/check_license.py Normal file
View file

@ -0,0 +1,47 @@
# Copyright 2019 The Nomulus Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
license = r".*Copyright \d{4} The Nomulus Authors\. All Rights Reserved\."
extensions = ("java", "js", "soy", "sql", "py", "sh")
non_included_patterns = {".git", "/build/", "/generated/", "node_modules/", "JUnitBackports.java", }
def should_include_path(path):
for pattern in non_included_patterns:
if pattern in path: return False
return path.endswith(extensions)
def get_files():
result = []
for root, dirnames, filenames in os.walk("."):
paths = [os.path.join(root, filename) for filename in filenames]
result.extend(filter(should_include_path, paths))
return result
if __name__ == "__main__":
all_files = get_files()
failed_files = []
for file in all_files:
with open(file, 'r') as f:
file_content = f.read()
if not re.match(license, file_content, re.DOTALL):
failed_files.append(file)
if failed_files:
print("The following files did not match the license header: " + str(failed_files))
sys.exit(1)

View file

@ -1,3 +1,17 @@
// Copyright 2019 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
process.env.CHROME_BIN = require('puppeteer').executablePath()
module.exports = function(config) {