diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator')
8 files changed, 299 insertions, 43 deletions
diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/Manifest.txt b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/Manifest.txt deleted file mode 100644 index cef7593ce1b..00000000000 --- a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/Manifest.txt +++ /dev/null @@ -1 +0,0 @@ -Class-Path: ../closure/compiler.jar diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/PRESUBMIT.py b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/PRESUBMIT.py new file mode 100644 index 00000000000..48f18413dd9 --- /dev/null +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/PRESUBMIT.py @@ -0,0 +1,55 @@ +# Copyright (C) 2013 Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""DevTools JSDoc validator presubmit script + +See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts +for more details about the presubmit API built into gcl. +""" + +import sys + + +def _ValidateHashes(input_api, output_api): + sys.path.append(input_api.PresubmitLocalPath()) + import build_jsdoc_validator_jar + hashes_modified = build_jsdoc_validator_jar.hashes_modified() + if not hashes_modified: + return [] + + results = '\n'.join(['%s (%s != %s)' % (name, expected, actual) for (name, expected, actual) in hashes_modified]) + return [output_api.PresubmitError('DevTools frontend JSDoc validator Java code, "%s" and "%s" must always be updated together. Please rebuild.\nModifications found:\n%s' % + (build_jsdoc_validator_jar.jar_name, build_jsdoc_validator_jar.hashes_name, results))] + + +def CheckChangeOnUpload(input_api, output_api): + return _ValidateHashes(input_api, output_api) + + +def CheckChangeOnCommit(input_api, output_api): + return _ValidateHashes(input_api, output_api) diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build-jsdoc-validator-jar.sh b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build-jsdoc-validator-jar.sh deleted file mode 100755 index f470ffe9eeb..00000000000 --- a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build-jsdoc-validator-jar.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -java_bin_path= -if [ "$JAVA_HOME" != "" ]; then - java_bin_path=$JAVA_HOME/bin/ -fi - -main_class=org.chromium.devtools.jsdoc.JsDocValidator -manifest_name=Manifest.txt -jar_name=jsdoc-validator.jar -script_path=$( cd $(dirname $0) ; pwd -P ) -bin_path=$(mktemp -d) - -function main() { - shopt -s globstar - echo "Compiling..." - ${java_bin_path}javac -d $bin_path $script_path/src/**/*.java -cp $script_path/../closure/compiler.jar > /dev/null - if [ $? != 0 ]; then - bail 1 - fi - - echo "Building jar..." - ${java_bin_path}jar cvfem $script_path/$jar_name $main_class $script_path/$manifest_name -C $bin_path . > /dev/null - if [ $? != 0 ]; then - bail 1 - fi - bail 0 -} - -function bail() { - rm -rf $bin_path - if [ "$1" == "0" ]; then - echo "Done." - else - echo "Failed." - fi - - exit $1 -} - -main - diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build_jsdoc_validator_jar.py b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build_jsdoc_validator_jar.py new file mode 100755 index 00000000000..75e80db2b3d --- /dev/null +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/build_jsdoc_validator_jar.py @@ -0,0 +1,165 @@ +#!/usr/bin/python + +import hashlib +import operator +import os +import shutil +import stat +import subprocess +import sys +import tempfile + + +def rel_to_abs(rel_path): + return os.path.join(script_path, rel_path) + + +java_bin_path = os.getenv('JAVA_HOME', '') +if java_bin_path: + java_bin_path = os.path.join(java_bin_path, 'bin') + +main_class = 'org.chromium.devtools.jsdoc.JsDocValidator' +jar_name = 'jsdoc-validator.jar' +hashes_name = 'hashes' +src_dir = 'src' +script_path = os.path.dirname(os.path.abspath(__file__)) +closure_jar_relpath = os.path.join('..', 'closure', 'compiler.jar') +src_path = rel_to_abs(src_dir) +hashes_path = rel_to_abs(hashes_name) + + +def get_file_hash(file, blocksize=65536): + sha = hashlib.sha256() + buf = file.read(blocksize) + while len(buf) > 0: + sha.update(buf) + buf = file.read(blocksize) + return sha.hexdigest() + + +def traverse(hasher, path): + abs_path = rel_to_abs(path) + info = os.lstat(abs_path) + quoted_name = repr(path.replace('\\', '/')) + if stat.S_ISDIR(info.st_mode) and not os.path.basename(path).startswith('.'): + hasher.update('d ' + quoted_name + '\n') + for entry in sorted(os.listdir(abs_path)): + traverse(hasher, os.path.join(path, entry)) + elif stat.S_ISREG(info.st_mode) and path.endswith('.java'): + hasher.update('r ' + quoted_name + ' ') + hasher.update(str(info.st_size) + ' ') + with open(abs_path, 'Ur') as file: + f_hash = get_file_hash(file) + hasher.update(f_hash + '\n') + + +def get_src_dir_hash(dir): + sha = hashlib.sha256() + traverse(sha, dir) + return sha.hexdigest() + + +def get_actual_hashes(): + hashed_files = [(jar_name, True)] + hashes = {} + for (file_name, binary) in hashed_files: + try: + hash = get_file_hash(open(file_name, 'rb' if binary else 'r')) + hashes[file_name] = hash + except IOError: + hashes[file_name] = '0' + hashes[src_dir] = get_src_dir_hash(src_dir) + return hashes + + +def get_expected_hashes(): + try: + with open(hashes_path, 'r') as file: + return {file_name: hash for (file_name, hash) in [(name.strip(), hash.strip()) for (hash, name) in [line.split(' ', 1) for line in file]]} + except: + return None + + +def run_and_communicate(command, error_template): + proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) + proc.communicate() + if proc.returncode: + print >> sys.stderr, error_template % proc.returncode + sys.exit(proc.returncode) + + +def build_artifacts(): + print 'Compiling...' + java_files = [] + for root, dirs, files in sorted(os.walk(src_path)): + for file_name in files: + if file_name.endswith('.java'): + java_files.append(os.path.join(root, file_name)) + + bin_path = tempfile.mkdtemp() + manifest_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) + try: + manifest_file.write('Class-Path: %s\n' % closure_jar_relpath) + manifest_file.close() + javac_path = os.path.join(java_bin_path, 'javac') + javac_command = '%s -d %s -cp %s %s' % (javac_path, bin_path, rel_to_abs(closure_jar_relpath), ' '.join(java_files)) + run_and_communicate(javac_command, 'Error: javac returned %d') + + print 'Building jar...' + artifact_path = rel_to_abs(jar_name) + jar_path = os.path.join(java_bin_path, 'jar') + jar_command = '%s cvfme %s %s %s -C %s .' % (jar_path, artifact_path, manifest_file.name, main_class, bin_path) + run_and_communicate(jar_command, 'Error: jar returned %d') + finally: + os.remove(manifest_file.name) + shutil.rmtree(bin_path, True) + + +def update_hashes(): + print 'Updating hashes...' + with open(hashes_path, 'w') as file: + file.writelines(['%s %s\n' % (hash, name) for (name, hash) in get_actual_hashes().iteritems()]) + + +def hashes_modified(): + expected_hashes = get_expected_hashes() + if not expected_hashes: + return [('<no expected hashes>', 1, 0)] + actual_hashes = get_actual_hashes() + results = [] + for name, expected_hash in expected_hashes.iteritems(): + actual_hash = actual_hashes.get(name) + if expected_hash != actual_hash: + results.append((name, expected_hash, actual_hash)) + return results + + +def help(): + print 'usage: %s [option]' % os.path.basename(__file__) + print 'Options:' + print '--force-rebuild: Rebuild classes and jar even if there are no source file changes' + print '--no-rebuild: Do not rebuild jar, just update hashes' + + +def main(): + no_rebuild = False + force_rebuild = False + + if len(sys.argv) > 1: + if sys.argv[1] == '--help': + help() + return + no_rebuild = sys.argv[1] == '--no-rebuild' + force_rebuild = sys.argv[1] == '--force-rebuild' + + if not hashes_modified() and not force_rebuild: + print 'No modifications found, rebuild not required.' + return + if not no_rebuild: + build_artifacts() + + update_hashes() + print 'Done.' + +if __name__ == '__main__': + main() diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/hashes b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/hashes new file mode 100644 index 00000000000..b53ea1d71d1 --- /dev/null +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/hashes @@ -0,0 +1,2 @@ +b5c1c0e9e16e027abae9f603ad6ff9228fe3b634be5b170ff9c267e8a3c54573 src +ac033f55138d8536bd031ca2a1f0cfc703ffa80dbfd24b2bd34dbfda1b90ff5c jsdoc-validator.jar diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/jsdoc-validator.jar b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/jsdoc-validator.jar Binary files differindex bccab7cb922..00de355e5e5 100644 --- a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/jsdoc-validator.jar +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/jsdoc-validator.jar diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/run_tests.py b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/run_tests.py new file mode 100755 index 00000000000..c8a0112ce82 --- /dev/null +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/run_tests.py @@ -0,0 +1,74 @@ +#!/usr/bin/python + +import hashlib +import operator +import os +import shutil +import stat +import subprocess +import sys +import tempfile + + +def rel_to_abs(rel_path): + return os.path.join(script_path, rel_path) + +java_exec = 'java -Xms1024m -server -XX:+TieredCompilation' +tests_dir = 'tests' +jar_name = 'jsdoc-validator.jar' +script_path = os.path.dirname(os.path.abspath(__file__)) +tests_path = rel_to_abs(tests_dir) +validator_jar_file = rel_to_abs(jar_name) +golden_file = os.path.join(tests_path, 'golden.dat') + +test_files = [os.path.join(tests_path, f) for f in os.listdir(tests_path) if f.endswith('.js') and os.path.isfile(os.path.join(tests_path, f))] + +validator_command = "%s -jar %s %s" % (java_exec, validator_jar_file, " ".join(sorted(test_files))) + + +def run_and_communicate(command, error_template): + proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) + (out, _) = proc.communicate() + if proc.returncode: + print >> sys.stderr, error_template % proc.returncode + sys.exit(proc.returncode) + return out + + +def help(): + print 'usage: %s [option]' % os.path.basename(__file__) + print 'Options:' + print '--generate-golden: Re-generate golden file' + print '--dump: Dump the test results to stdout' + + +def main(): + need_golden = False + need_dump = False + if len(sys.argv) > 1: + if sys.argv[1] == '--generate-golden': + need_golden = True + elif sys.argv[1] == '--dump': + need_dump = True + else: + help() + return + + result = run_and_communicate(validator_command, "Error running validator: %d") + if need_dump: + print result + return + + if need_golden: + with open(golden_file, 'wt') as golden: + golden.write(result) + else: + with open(golden_file, 'rt') as golden: + golden_text = golden.read() + if golden_text == result: + print 'OK' + else: + print 'ERROR: Golden output mismatch' + +if __name__ == '__main__': + main() diff --git a/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/DEPS b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/DEPS new file mode 100644 index 00000000000..fa04739e7d0 --- /dev/null +++ b/chromium/third_party/WebKit/Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+Source/devtools/scripts/jsdoc-validator/src/org/chromium/devtools/jsdoc", +] |