Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Script that is used by PRESUBMIT.py to run style checks on Java files.""" | 5 """Script that is used by PRESUBMIT.py to run style checks on Java files.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import subprocess | 8 import subprocess |
| 9 | 9 |
| 10 | 10 |
| 11 def RunCheckstyle(input_api, output_api, style_file): | 11 def RunCheckstyle(input_api, output_api, style_file): |
| 12 if not os.path.exists(style_file): | 12 if not os.path.exists(style_file): |
| 13 file_error = (' Java checkstyle configuration file is missing: ' | 13 file_error = (' Java checkstyle configuration file is missing: ' |
| 14 + style_file) | 14 + style_file) |
| 15 return [output_api.PresubmitError(file_error)] | 15 return [output_api.PresubmitError(file_error)] |
| 16 | 16 |
| 17 # Filter out non-Java files and files that were deleted. | 17 # Filter out non-Java files and files that were deleted. |
| 18 java_files = [x.LocalPath() for x in input_api.AffectedFiles(False, False) | 18 java_files = [x.LocalPath() for x in input_api.AffectedFiles(False, False) |
| 19 if os.path.splitext(x.LocalPath())[1] == '.java'] | 19 if os.path.splitext(x.LocalPath())[1] == '.java'] |
| 20 if not java_files: | 20 if not java_files: |
| 21 return [] | 21 return [] |
| 22 | 22 |
| 23 # Run checkstyle | 23 # Run checkstyle |
| 24 checkstyle_env = os.environ.copy() | 24 checkstyle_env = os.environ.copy() |
| 25 checkstyle_env['JAVA_CMD'] = 'java' | 25 checkstyle_env['JAVA_CMD'] = 'java' |
| 26 try: | 26 try: |
| 27 check = subprocess.Popen(['checkstyle', '-c', style_file] + java_files, | 27 check = subprocess.Popen(['java', '-cp', |
|
Yaron
2014/08/11 17:46:15
Looks like the internal tree will need an update a
aurimas (slooooooooow)
2014/08/11 22:59:31
We use this python script directly so no need for
| |
| 28 'third_party/checkstyle/checkstyle-5.7-all.jar', | |
|
Yaron
2014/08/11 17:46:15
If this is now checked into the tree, devs don't n
aurimas (slooooooooow)
2014/08/11 22:59:31
Done.
| |
| 29 'com.puppycrawl.tools.checkstyle.Main', '-c', | |
| 30 style_file] + java_files, | |
| 28 stdout=subprocess.PIPE, env=checkstyle_env) | 31 stdout=subprocess.PIPE, env=checkstyle_env) |
| 29 stdout, _ = check.communicate() | 32 stdout, _ = check.communicate() |
| 30 if check.returncode == 0: | 33 if check.returncode == 0: |
| 31 return [] | 34 return [] |
| 32 except OSError as e: | 35 except OSError as e: |
| 33 import errno | 36 import errno |
| 34 if e.errno == errno.ENOENT: | 37 if e.errno == errno.ENOENT: |
| 35 install_error = (' checkstyle is not installed. Please run ' | 38 install_error = (' checkstyle is not installed. Please run ' |
| 36 'build/install-build-deps-android.sh') | 39 'build/install-build-deps-android.sh') |
| 37 return [output_api.PresubmitPromptWarning(install_error)] | 40 return [output_api.PresubmitPromptWarning(install_error)] |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 49 if not errors: | 52 if not errors: |
| 50 return [] | 53 return [] |
| 51 | 54 |
| 52 local_path = input_api.PresubmitLocalPath() | 55 local_path = input_api.PresubmitLocalPath() |
| 53 output = [] | 56 output = [] |
| 54 for error in errors: | 57 for error in errors: |
| 55 # Change the full file path to relative path in the output lines | 58 # Change the full file path to relative path in the output lines |
| 56 full_path, end = error.split(':', 1) | 59 full_path, end = error.split(':', 1) |
| 57 rel_path = os.path.relpath(full_path, local_path) | 60 rel_path = os.path.relpath(full_path, local_path) |
| 58 output.append(' %s:%s' % (rel_path, end)) | 61 output.append(' %s:%s' % (rel_path, end)) |
| 59 return [output_api.PresubmitPromptWarning('\n'.join(output))] | 62 return [output_api.PresubmitPromptWarning('\n'.join(output))] |
| OLD | NEW |