forked from typetools/checker-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-styleguide.xml
178 lines (160 loc) · 7.85 KB
/
build-styleguide.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!--
This is a configuration file for use by Ant when building the
Checker Framework.
This file is shared between all subprojects and external projects.
It contains targets to automatically enforce a common style.
The fileset "formatted.java.files" must contain the files to reformat.
-->
<project name="styleguide"
xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="style.grep.args" value="-r -n -e"/>
<!-- These variables contain commands, not lists of files. -->
<!-- keep these two lists in sync -->
<property name="style.grep.files" value="--exclude-dir=.git --exclude-dir=annotated --exclude-dir=api --exclude-dir=bib --exclude-dir=bootstrap --exclude-dir=build --exclude-dir=jdk --exclude-dir=maven-artifacts --exclude='*.aux' --exclude='*.bib' --exclude='*.class' --exclude='*.dvi' --exclude='*.expected' --exclude='*.gif' --exclude='*.jar' --exclude='*.jtr' --exclude='*.log' --exclude='*.out' --exclude='*.patch' --exclude='*.pdf' --exclude='*.png' --exclude='*.sty' --exclude='*.xcf' --exclude='*~' --exclude='#*#' --exclude='CFLogo.ai' --exclude='logfile.log.rec.index' --exclude='manual.html' --exclude='manual.html-e' --exclude='junit*.properties' ."/>
<property name="style.find.files" value=". -not ( -name .git -prune ) -not ( -name annotated -prune ) -not ( -name api -prune ) -not ( -name bib -prune ) -not ( -name bootstrap -prune ) -not ( -name build -prune ) -not ( -name jdk -prune ) -not ( -path maven-artifacts -prune ) -not ( -name '*.aux' ) -not ( -name '*.bib' ) -not ( -name '*.class' ) -not ( -name '*.dvi' ) -not ( -name '*.expected' ) -not ( -name '*.gif' ) -not ( -name '*.jar' ) -not ( -name '*.log' ) -not ( -name '*.out' ) -not ( -name '*.patch' ) -not ( -name '*.pdf' ) -not ( -name '*.png' ) -not ( -name 'junit*.properties' ) -not ( -name '*~' ) -not ( -name '#*#' ) -not ( -name 'manual.html' ) -not ( -name 'manual.html-e' ) -not ( -empty ) -type f"/>
<loadresource property="style.find.files.quoted">
<propertyresource name="style.find.files"/>
<filterchain>
<tokenfilter>
<replacestring from="(" to="\("/>
<replacestring from=")" to="\)"/>
</tokenfilter>
</filterchain>
</loadresource>
<target name="check-style" depends="check-format"
description="Check basic style guidelines">
<!-- There should be a way to templatize the following. -->
<exec executable="grep" outputproperty="trailingwhitespace" failonerror="false">
<arg line="${style.grep.args}"/>
<arg value=" $"/>
<arg line="${style.grep.files}"/>
</exec>
<fail message="Trailing whitespace:${line.separator}${trailingwhitespace}">
<condition>
<not>
<equals arg1="${trailingwhitespace}" arg2=""/>
</not>
</condition>
</fail>
<exec executable="grep" outputproperty="missingspace" failonerror="false">
<arg line="${style.grep.args}"/>
<arg value="[^\\]\b\(else\|finally\|try\){\|}\(catch\|else\|finally\)\b\|){\($\|[^0-9]\)\|\b\(catch\|for\|if\|while\)("/>
<arg line="${style.grep.files}"/>
<arg value="--exclude=build-styleguide.xml"/>
<arg value="--exclude=Makefile"/>
</exec>
<fail message="Missing space:${line.separator}${missingspace}">
<condition>
<not>
<equals arg1="${missingspace}" arg2=""/>
</not>
</condition>
</fail>
<!-- To remove trailing whitespace:
find . -name '*.java' | xargs sed -i ':a;/^[ \n]*$/{$d;N;ba}'
-->
<exec executable="find" outputproperty="blankline" failonerror="false">
<arg line="${style.find.files}"/>
<arg value="-exec"/>
<arg value="sh"/>
<arg value="+v"/>
<arg value="+x"/>
<arg value="-c"/>
<arg value="[ -z "$(sed -n "\$p" "$1")" ]"/>
<arg value="_"/>
<arg value="{}"/>
<arg value=";"/>
<arg value="-print"/>
</exec>
<fail message="Blank line at end of file:${line.separator}${blankline}">
<condition>
<not>
<equals arg1="${blankline}" arg2=""/>
</not>
</condition>
</fail>
<!-- To add final newline:
find -type f -name '*.java' | xargs sed -i -e '$a\'
-->
<exec executable="sh" outputproperty="notrailingnewline" failonerror="false">
<arg value="+v"/>
<arg value="+x"/>
<arg value="-c"/>
<arg value="find ${style.find.files.quoted} -print0 | xargs -0 -L1 sh +v +x -c 'test "$(tail -c 1 "$0")" && echo "No newline at end of $0"'"/>
<!-- <arg value="find ${style.find.files.quoted} -print0 | xargs -0 -L1 bash -c 'echo "$0"'"/> -->
</exec>
<fail message="Missing newline at end of files:${line.separator}${notrailingnewline}">
<condition>
<not>
<equals arg1="${notrailingnewline}" arg2=""/>
</not>
</condition>
</fail>
</target>
<!-- Allow 30 seconds for either formatting task to complete. -->
<!-- I can add back quiet="true" to the get invocations, when all
installations have a modern enough Ant that recognizes that attribute. -->
<condition property="isMac">
<os family="mac" />
</condition>
<!-- Avoids "Argument list too long" message. You can also set
this property in file local.properties. -->
<condition property="maxparallel" value="1000" else="-1">
<isset property="isMac"/>
</condition>
<target name="-run-google-java-format.check">
<condition property="run-google-java-format.exists">
<available file="${checker.loc}/bin-devel/.run-google-java-format" type="dir"/>
</condition>
</target>
<target name="-get-run-google-java-format"
description="Obtain the run-google-java-format project"
depends="-run-google-java-format.check"
unless="run-google-java-format.exists">
<exec executable="git"
dir="${checker.loc}/bin-devel">
<arg value="clone"/>
<arg value="-q"/>
<arg value="https://github.com/plume-lib/run-google-java-format.git"/>
<arg value=".run-google-java-format"/>
</exec>
</target>
<target name="update-run-google-java-format"
description="Update the run-google-java-format project"
depends="-get-run-google-java-format">
<exec executable="git"
dir="${checker.loc}/bin-devel/.run-google-java-format">
<arg value="pull"/>
<arg value="-q"/>
</exec>
</target>
<target name="reformat" depends="update-run-google-java-format"
description="Reformat Java code">
<apply executable="python" parallel="true" maxparallel="${maxparallel}" failonerror="true">
<arg value="${checker.loc}/bin-devel/.run-google-java-format/run-google-java-format.py"/>
<arg value="--aosp"/> <!-- 4-space indentation -->
<fileset refid="formatted.java.files"/>
</apply>
</target>
<target name="check-format" depends="update-run-google-java-format"
description="Check Java code formatting">
<apply executable="python" parallel="true" maxparallel="${maxparallel}"
failonerror="false" resultproperty="check.format.result"
outputproperty="check.format.stdout" errorproperty="check.format.stderr">
<arg value="${checker.loc}/bin-devel/.run-google-java-format/check-google-java-format.py"/>
<arg value="--aosp"/> <!-- 4-space indentation -->
<fileset refid="formatted.java.files"/>
</apply>
<echo unless:blank="${check.format.stdout}">${check.format.stdout}</echo>
<echo unless:blank="${check.format.stderr}">${check.format.stderr}</echo>
<echo unless:blank="${check.format.stderr}">Fix syntax errors, then re-run: ant check-format</echo>
<echo unless:blank="${check.format.stdout}" if:blank="${check.format.stderr}">Try running: ant reformat</echo>
<fail>
<condition>
<not>
<equals arg1="0" arg2="${check.format.result}"/>
</not>
</condition>
</fail>
</target>
</project>