1#  Copyright (C) 2015 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15# The config file to use when checking style issues
16STYLE_CONFIG := $(LOCAL_PATH)/build/gcheckstyle/tools/java/checkstyle/googlestyle-5.0.xml
17
18# The jar file to use to perform the checking
19STYLE_JAR := $(LOCAL_PATH)/build/gcheckstyle/google-style-checker_deploy.jar
20
21# The output file to cache the results of style error checking
22$(LOCAL_PACKAGE_NAME)STYLE_ERRORS_TXT := $(intermediates.COMMON)/$(LOCAL_PACKAGE_NAME)_style_errors.txt
23
24# The set of input files to check
25$(LOCAL_PACKAGE_NAME)JAVA_FILES = $(shell find $(LOCAL_PATH)/src/ -name '*.java')
26
27# Updates the JAR file with the new config if the config has changed
28# The config file has to be packaged into the jar, and jar uf command expects the current working directory
29# to match the jar structure
30$(STYLE_JAR): PRIVATE_PATH := $(LOCAL_PATH)
31$(STYLE_JAR) : $(STYLE_CONFIG)
32	$(hide) pushd $(PRIVATE_PATH)/build/gcheckstyle && \
33	jar uf google-style-checker_deploy.jar tools/java/checkstyle/googlestyle-5.0.xml && \
34	popd
35
36# Rebuilds the style errors text if the style checker or any of the java files have changed
37# FLAG: It may be more efficient to cache individual file results rather than grouping them all together
38$($(LOCAL_PACKAGE_NAME)STYLE_ERRORS_TXT): SOURCES := $($(LOCAL_PACKAGE_NAME)JAVA_FILES)
39$($(LOCAL_PACKAGE_NAME)STYLE_ERRORS_TXT) : $($(LOCAL_PACKAGE_NAME)JAVA_FILES) $(STYLE_JAR)
40	$(hide) -/usr/local/buildtools/java/jdk/bin/java -jar $(STYLE_JAR) $(SOURCES) > $@
41
42# The root of the lint rule which just prints the style errors txt file to the console
43$(LOCAL_PACKAGE_NAME)lint :: $($(LOCAL_PACKAGE_NAME)STYLE_ERRORS_TXT)
44	$(hide) $(PRIVATE_PATH)/build/process_style_output.py -omit $(abspath $(PRIVATE_PATH))/ < $< | $(PRIVATE_PATH)/build/colorize_errors.py
45
46