michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import unittest michael@0: import os.path michael@0: michael@0: parent = os.path.dirname michael@0: test_dir = parent(os.path.abspath(__file__)) michael@0: sdk_root = parent(parent(parent(test_dir))) michael@0: michael@0: def from_sdk_top(fn): michael@0: return os.path.abspath(os.path.join(sdk_root, fn)) michael@0: michael@0: MPL2_URL = "http://mozilla.org/MPL/2.0/" michael@0: michael@0: # These files all come with their own license headers michael@0: skip = [ michael@0: "python-lib/cuddlefish/_version.py", # generated, public domain michael@0: "doc/static-files/js/jquery.js", # MIT/GPL dual michael@0: "examples/annotator/data/jquery-1.4.2.min.js", # MIT/GPL dual michael@0: "examples/reddit-panel/data/jquery-1.4.4.min.js", # MIT/GPL dual michael@0: "examples/library-detector/data/library-detector.js", # MIT michael@0: "python-lib/mozrunner/killableprocess.py", # MIT? BSDish? michael@0: "python-lib/mozrunner/winprocess.py", # MIT michael@0: "packages/api-utils/tests/test-querystring.js", # MIT michael@0: "packages/api-utils/lib/promise.js", # MIT michael@0: "packages/api-utils/tests/test-promise.js", # MIT michael@0: ] michael@0: absskip = [from_sdk_top(os.path.join(*fn.split("/"))) for fn in skip] michael@0: michael@0: class Licenses(unittest.TestCase): michael@0: def test(self): michael@0: # Examine most SDK files to check if they've got an MPL2 license michael@0: # header. We exclude some files that are known to include different michael@0: # licenses. michael@0: self.missing = [] michael@0: self.scan_file(from_sdk_top(os.path.join("python-lib", "jetpack_sdk_env.py"))) michael@0: self.scan(os.path.join("python-lib", "cuddlefish"), [".js", ".py"], michael@0: skipdirs=["sdk-docs"], # test_generate.py makes this michael@0: ) michael@0: self.scan(os.path.join("python-lib", "mozrunner"), [".py"]) michael@0: michael@0: for sdk_package in ["addon-kit", "api-utils", "test-harness"]: michael@0: self.scan(os.path.join("packages", sdk_package), michael@0: [".js", ".py", ".md"]) michael@0: self.scan("examples", [".js", ".css", ".html", ".md"]) michael@0: self.scan("bin", [".bat", ".ps1"]) michael@0: for fn in [os.path.join("bin", "activate"), michael@0: os.path.join("bin", "cfx"), michael@0: os.path.join("bin", "integration-scripts", "buildbot-run-cfx-helper"), michael@0: os.path.join("bin", "integration-scripts", "integration-check"), michael@0: ]: michael@0: self.scan_file(from_sdk_top(fn)) michael@0: self.scan("doc", [".js", ".css", ".md"], skipdirs=["syntaxhighlighter"]) michael@0: michael@0: if self.missing: michael@0: print michael@0: print "The following files are missing an MPL2 header:" michael@0: for fn in sorted(self.missing): michael@0: print " "+fn michael@0: self.fail("%d files are missing an MPL2 header" % len(self.missing)) michael@0: michael@0: def scan(self, start, extensions=[], skipdirs=[]): michael@0: # scan a whole subdirectory michael@0: start = from_sdk_top(start) michael@0: for root, dirs, files in os.walk(start): michael@0: for d in skipdirs: michael@0: if d in dirs: michael@0: dirs.remove(d) michael@0: for fn in files: michael@0: ext = os.path.splitext(fn)[1] michael@0: if extensions and ext not in extensions: michael@0: continue michael@0: absfn = os.path.join(root, fn) michael@0: if absfn in absskip: michael@0: continue michael@0: self.scan_file(absfn) michael@0: michael@0: def scan_file(self, fn): michael@0: # scan a single file michael@0: if not MPL2_URL in open(fn, "r").read(): michael@0: relfile = fn[len(sdk_root)+1:] michael@0: self.missing.append(relfile) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()