summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authoraurimas@chromium.org <aurimas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-10 19:33:49 +0000
committeraurimas@chromium.org <aurimas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-10 19:33:49 +0000
commit760deeab8a9baa01f0b2f33bf26ba46f986bdba5 (patch)
treeaeda738006eb04fe1454c0b25e32f81966579285 /tools
parent6f221ce75d467f34aaf57ceab5216f2884bb082a (diff)
downloadchromium_src-760deeab8a9baa01f0b2f33bf26ba46f986bdba5.zip
chromium_src-760deeab8a9baa01f0b2f33bf26ba46f986bdba5.tar.gz
chromium_src-760deeab8a9baa01f0b2f33bf26ba46f986bdba5.tar.bz2
Adding Java style presubmit check.
BUG=320711 Review URL: https://codereview.chromium.org/110773002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools')
-rw-r--r--tools/android/checkstyle/checkstyle.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/android/checkstyle/checkstyle.py b/tools/android/checkstyle/checkstyle.py
new file mode 100644
index 0000000..c47fbee
--- /dev/null
+++ b/tools/android/checkstyle/checkstyle.py
@@ -0,0 +1,59 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Script that is used by PRESUBMIT.py to run style checks on Java files."""
+
+import os
+import subprocess
+
+
+def RunCheckstyle(input_api, output_api, style_file):
+ if not os.path.exists(style_file):
+ file_error = (' Java checkstyle configuration file is missing: '
+ + style_file)
+ return [output_api.PresubmitError(file_error)]
+
+ # Filter out non-Java files and files that were deleted.
+ java_files = [x.LocalPath() for x in input_api.AffectedFiles(False, False)
+ if os.path.splitext(x.LocalPath())[1] == '.java']
+ if not java_files:
+ return []
+
+ # Run checkstyle
+ checkstyle_env = os.environ.copy()
+ checkstyle_env['JAVA_CMD'] = 'java'
+ try:
+ check = subprocess.Popen(['checkstyle', '-c', style_file] + java_files,
+ stdout=subprocess.PIPE, env=checkstyle_env)
+ stdout, _ = check.communicate()
+ if check.returncode == 0:
+ return []
+ except OSError as e:
+ import errno
+ if e.errno == errno.ENOENT:
+ install_error = (' checkstyle is not installed. Please run '
+ 'build/install-build-deps-android.sh')
+ return [output_api.PresubmitPromptWarning(install_error)]
+
+ # Remove non-error values from stdout
+ errors = stdout.splitlines()
+
+ if errors and errors[0] == 'Starting audit...':
+ del errors[0]
+ if errors and errors[-1] == 'Audit done.':
+ del errors[-1]
+
+ # Filter out warnings
+ errors = [x for x in errors if 'warning: ' not in x]
+ if not errors:
+ return []
+
+ local_path = input_api.PresubmitLocalPath()
+ output = []
+ for error in errors:
+ # Change the full file path to relative path in the output lines
+ full_path, end = error.split(':', 1)
+ rel_path = os.path.relpath(full_path, local_path)
+ output.append(' %s:%s' % (rel_path, end))
+ return [output_api.PresubmitPromptWarning('\n'.join(output))] \ No newline at end of file