summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitchell Wills <mwills@google.com>2016-02-11 16:56:17 -0800
committerMitchell Wills <mwills@google.com>2016-02-11 16:59:56 -0800
commite524e6070bb3bd1d1a4292170de075b2f467773a (patch)
tree51e887728bee08bcc0625bb021b2d6b8c4519e41
parent51cc7ee42e5f6679dbc62ef4203fca2c597d009c (diff)
downloadandroid_development-e524e6070bb3bd1d1a4292170de075b2f467773a.tar.gz
android_development-e524e6070bb3bd1d1a4292170de075b2f467773a.tar.bz2
android_development-e524e6070bb3bd1d1a4292170de075b2f467773a.zip
Add OuterTypeFilename rule to Checkstyle
This also requires modifying the logic to create temporary files so that the filename is the same as that in source tree. Bug: 27109166 Change-Id: I73f2406d5c85d45b0b259f0fd7dd081e44df029c
-rw-r--r--tools/checkstyle/android-style.xml3
-rwxr-xr-xtools/checkstyle/checkstyle.py14
2 files changed, 12 insertions, 5 deletions
diff --git a/tools/checkstyle/android-style.xml b/tools/checkstyle/android-style.xml
index 2d11bf5ed..7fff49b72 100644
--- a/tools/checkstyle/android-style.xml
+++ b/tools/checkstyle/android-style.xml
@@ -216,6 +216,9 @@
<module name="RedundantModifier">
<property name="severity" value="error"/>
</module>
+ <module name="OuterTypeFilename">
+ <property name="severity" value="error"/>
+ </module>
<module name="FileContentsHolder"/>
</module>
<module name="FileTabCharacter">
diff --git a/tools/checkstyle/checkstyle.py b/tools/checkstyle/checkstyle.py
index 421178f8d..80049b650 100755
--- a/tools/checkstyle/checkstyle.py
+++ b/tools/checkstyle/checkstyle.py
@@ -244,12 +244,16 @@ def _GetTempFilesForCommit(file_names, commit):
tmp_dir_name = tempfile.mkdtemp()
tmp_file_names = {}
for file_name in file_names:
+ rel_path = os.path.relpath(file_name)
content = subprocess.check_output(
- ['git', 'show', commit + ':' + os.path.relpath(file_name)])
- (fd, tmp_file_name) = tempfile.mkstemp(suffix='.java',
- dir=tmp_dir_name,
- text=True)
- tmp_file = os.fdopen(fd, 'w')
+ ['git', 'show', commit + ':' + rel_path])
+
+ tmp_file_name = os.path.join(tmp_dir_name, rel_path)
+ # create directory for the file if it doesn't exist
+ if not os.path.exists(os.path.dirname(tmp_file_name)):
+ os.makedirs(os.path.dirname(tmp_file_name))
+
+ tmp_file = open(tmp_file_name, 'w')
tmp_file.write(content)
tmp_file.close()
tmp_file_names[tmp_file_name] = file_name