-
Notifications
You must be signed in to change notification settings - Fork 439
/
check.xml
321 lines (285 loc) · 15 KB
/
check.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="checkstyle" name="CheckAnt" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:if="ant:if" xmlns:unless="ant:unless">
<description>
Check Ant codebase against certain code style guidelines using
Checkstyle, Apache Rat, SpotBugs, OWASP Dependency Check
and Nu Html Checker (v.Nu).
Checkstyle uses an abstract syntax tree (AST) for doing checks
against Java sources. It is available at https://checkstyle.org/
under GPL 2.1 license.
"Apache Rat is a release audit tool, focused on licenses." It is available
at https://creadur.apache.org/rat/ under Apache License, Version 2.0.
"SpotBugs is a program which uses static analysis to look for bugs in Java
code." It is available at https://spotbugs.github.io/ under LGPL 3 license.
"Dependency-Check is a utility that identifies project dependencies and
checks if there are any known, publicly disclosed, vulnerabilities." It is
available at https://www.owasp.org/index.php/OWASP_Dependency_Check under
Apache License, Version 2.0.
"The Nu Html Checker (v.Nu) is the backend of checker.html5.org,
html5.validator.nu, and validator.w3.org/nu." It is available at
https://validator.github.io/validator/ under MIT license.
See external task page and homepages for more information.
</description>
<import file="build.xml"/>
<property name="reports.dir"
value="${build.dir}/reports"
description="Base directory for generated reports"/>
<!-- Ant Checkstyle -->
<property name="checkstyle.src.dir" location="${etc.dir}/checkstyle"/>
<property name="checkstyle.version"
value="6.19"
description="Which version of Checkstyle to use"/>
<property name="checkstyle.reportdir"
location="${reports.dir}/checkstyle"
description="Where to store Checkstyle reports"/>
<property name="checkstyle.raw"
location="${checkstyle.reportdir}/raw.xml"
description="Name of Checkstyle XML report"/>
<property name="stylesheet.html"
location="${checkstyle.src.dir}/checkstyle-frames.xsl"
description="Name of Checkstyle XSLT for generating HTML"/>
<property name="stylesheet.html.sorted"
location="${checkstyle.src.dir}/checkstyle-frames-sortby-check.xsl"
description="Name of Checkstyle XSLT for generating 2nd HTML"/>
<property name="stylesheet.text"
location="${checkstyle.src.dir}/checkstyle-text.xsl"
description="Name of Checkstyle XSLT for generating plain text"/>
<property name="stylesheet.xdoc"
location="${checkstyle.src.dir}/checkstyle-xdoc.xsl"
description="Name of Checkstyle XSLT for generating XDOC"/>
<property name="checkstyle.basedir"
location="${java.dir}"
description="Where are the Java sources to check"/>
<property name="tocheck"
value="**/*.java"
description="Include pattern of the files to check"/>
<!-- Findbugs: Running SpotBugs -->
<property name="spotbugs.version"
value="3.1.4"
description="Which version of SpotBugs to use"/>
<property name="findbugs.reportdir"
location="${reports.dir}/findbugs"
description="Where to store SpotBugs results"/>
<property name="findbugs.raw"
value="raw.xml"
description="Name of SpotBugs XML report"/>
<property name="findbugs.xsl"
value="fancy.xsl"
description="Which XSL to use for generating output: default, fancy, plain, summary"/>
<property name="findbugs.jvmargs"
value="-Xms128m -Xmx512m"
description="JVM arguments when invoking SpotBugs"/>
<!-- Apache Rat: Release Auditing Tool -->
<property name="rat.version"
value="0.13"
description="Which version of Apache Rat to use"/>
<property name="rat.report.dir"
value="${reports.dir}/rat"
description="Where to store Apache Rat reports"/>
<property name="rat.report.file"
value="${rat.report.dir}/report.html"
description="Name of Apache Rat report"/>
<!-- OWASP Dependency Check -->
<property name="owasp.dc.version"
value="3.2.1"
description="Which version of OWASP Dependency Check to use"/>
<property name="owasp.dc.report.dir"
value="${reports.dir}/owasp-dc"
description="Where to store the OWASP Dependency Check reports"/>
<!-- Nu Html Checker -->
<property name="htmlcheck.nu.version"
value="18.11.5"
description="Which version of Nu Html Checker to use"/>
<property name="htmlcheck.report.dir"
value="${reports.dir}/html-check"
description="Directory where to store the HTML-Check report"/>
<property name="htmlcheck.report.file"
value="${htmlcheck.report.dir}/report.txt"
description="Report file of the HTML-Check"/>
<target name="init-ivy">
<property name="ivy.version" value="2.5.0"/>
<property name="ivy.jar.url" value="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"/>
<property name="ivy.jar.dir" value="${build.dir}/ivy"/>
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
<mkdir dir="${ivy.jar.dir}"/>
<get src="${ivy.jar.url}" dest="${ivy.jar.file}" usetimestamp="true"/>
<path id="ivy.lib.path">
<fileset dir="${ivy.jar.dir}" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</target>
<target name="checkstyle" description="--> checks Ant codebase according to ${checkstyle.src.dir}/checkstyle-config" depends="init-ivy">
<available property="antlr.present" classname="antlr.CommonAST"/>
<echo if:set="antlr.present">
Found antlr on the classpath.
Having a wrong antlr version on the same classpath as Checkstyle may produce errors like
'Can't find/access AST Node typecom.puppycrawl.tools.checkstyle.api.DetailAST'
Skip running Checkstyle.
</echo>
<sequential unless:set="antlr.present">
<ivy:cachepath organisation="com.puppycrawl.tools" module="checkstyle" revision="${checkstyle.version}"
inline="true" conf="default" pathid="checkstyle.classpath"/>
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" classpathref="checkstyle.classpath"/>
<mkdir dir="${checkstyle.reportdir}"/>
<checkstyle config="${checkstyle.src.dir}/checkstyle-config" failOnViolation="false">
<formatter type="xml" toFile="${checkstyle.raw}"/>
<fileset dir="${java.dir}">
<include name="${tocheck}"/>
<exclude name="**/bzip2/*.java"/>
<exclude name="**/CVSPass.java"/>
</fileset>
</checkstyle>
</sequential>
</target>
<target name="htmlreport" description="--> generates a html checkstyle report" unless="antlr.present">
<xslt in="${checkstyle.raw}" style="${stylesheet.html}"
out="${checkstyle.reportdir}/html/output.txt">
<param name="basedir" expression="${checkstyle.basedir}"/>
<param name="output.dir" expression="${checkstyle.reportdir}"/>
</xslt>
<xslt in="${checkstyle.raw}" style="${stylesheet.html.sorted}"
out="${checkstyle.reportdir}/html/output-sorted.txt">
<param name="basedir" expression="${checkstyle.basedir}"/>
<param name="output.dir" expression="${checkstyle.reportdir}"/>
</xslt>
</target>
<target name="textreport" description="--> generates a text checkstyle report" unless="antlr.present">
<xslt in="${checkstyle.raw}" style="${stylesheet.text}"
out="${checkstyle.reportdir}/report.txt">
</xslt>
</target>
<target name="textreport-display" depends="textreport" description="--> generates a text checkstyle report and displays it immediately">
<loadfile property="report" srcfile="${checkstyle.reportdir}/report.txt"/>
<echo>${report}</echo>
</target>
<target name="xdocreport" description="--> generates a xdoc checkstyle report" unless="antlr.present">
<xslt in="${checkstyle.raw}" style="${stylesheet.xdoc}"
out="${checkstyle.reportdir}/xdocs/index.xml">
<param name="basedir" expression="${checkstyle.basedir}"/>
</xslt>
</target>
<target name="dumphtml" depends="checkstyle, htmlreport" description="--> runs the checkstyle and generates a html report"/>
<target name="dumptext" depends="checkstyle, textreport" description="--> runs the checkstyle and displays result as text">
<concat>
<filelist dir="${checkstyle.reportdir}" files="report.txt"/>
</concat>
</target>
<target name="fixTS" description="--> fix checkstyle errors 'Line has trailing spaces'">
<fail message="Define path to java file 'path'">
<condition><not><isset property="path"/></not></condition>
</fail>
<replaceregexp match="\s+$" replace="" flags="g" byline="true">
<fileset dir="src/main" includes="${path}"/>
</replaceregexp>
</target>
<target name="fixTab" description="--> fix checkstyle errors 'Line contains TAB sign'">
<fail message="Define path to java file 'path'">
<condition><not><isset property="path"/></not></condition>
</fail>
<fixcrlf srcdir="src/main" includes="${path}" javafiles="yes" tab="remove" tablength="4"/>
</target>
<target name="findbugs" description="--> checks Ant codebase with SpotBugs" depends="init-ivy,build"
xmlns:fb="http://findbugs.sourceforge.net/">
<!-- Path of optional libs is provided through CLI to forked JVM -->
<path id="optional.libs">
<fileset dir="lib/optional" includes="*.jar"/>
</path>
<ivy:cachepath organisation="com.github.spotbugs" module="spotbugs-ant" revision="${spotbugs.version}"
inline="true" conf="default" pathid="spotbugs.classpath"/>
<!-- Load the SpotBugs AntTasks -->
<taskdef uri="http://findbugs.sourceforge.net/" resource="edu/umd/cs/findbugs/anttask/tasks.properties"
classpathref="spotbugs.classpath"/>
<!-- Start SpotBugs -->
<mkdir dir="${findbugs.reportdir}"/>
<fb:spotbugs classpathref="spotbugs.classpath"
output="xml:withMessages"
outputFile="${findbugs.reportdir}/${findbugs.raw}"
jvmargs="${findbugs.jvmargs}"
projectName="${Name} ${project.version}">
<class location="${build.classes}"/>
<sourcePath path="${java.dir}"/>
<auxClasspath refid="optional.libs"/>
</fb:spotbugs>
<!-- Generate (human) readable output -->
<xslt basedir="${findbugs.reportdir}" includes="${findbugs.raw}" destdir="${findbugs.reportdir}">
<style>
<javaresource name="${findbugs.xsl}" classpathref="spotbugs.classpath"/>
</style>
</xslt>
</target>
<target name="rat" description="--> Runs the ReleaseAuditingTool" depends="init-ivy">
<ivy:cachepath organisation="org.apache.rat" module="apache-rat-tasks" revision="${rat.version}"
inline="true" conf="default" pathid="rat.classpath"/>
<typedef resource="org/apache/rat/anttasks/antlib.xml"
uri="antlib:org.apache.rat.anttasks"
classpathref="rat.classpath"/>
<mkdir dir="${rat.report.dir}"/>
<rat:report xmlns:rat="antlib:org.apache.rat.anttasks" reportfile="${rat.report.dir}/report.txt">
<rat:fullTextMatcher licenseFamilyCategory="AL "
licenseFamilyName="Apache License Version 2.0 with HTTPS reference">
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
</rat:fullTextMatcher>
<rat:approvedLicense
familyName="Apache License Version 2.0 with HTTPS reference"/>
<fileset dir="${java.dir}">
<exclude name="org/apache/tools/ant/defaultManifest.mf"/>
<exclude name="org/apache/tools/ant/version.txt"/>
</fileset>
</rat:report>
</target>
<target name="dependency-check" description="--> Runs the OWASP Dependency Check" depends="init-ivy">
<ivy:cachepath organisation="org.owasp" module="dependency-check-ant" revision="${owasp.dc.version}"
inline="true" conf="default" pathid="owasp.dc.classpath"/>
<taskdef resource="dependency-check-taskdefs.properties" uri="https://jeremylong.github.io/"
classpathref="owasp.dc.classpath"/>
<mkdir dir="${owasp.dc.report.dir}"/>
<owasp:dependency-check xmlns:owasp="https://jeremylong.github.io/"
projectName="${ant.project.name}"
reportOutputDirectory="${owasp.dc.report.dir}">
<fileset dir="lib" includes="**/*.jar"/>
<fileset dir="." includes="dist/**/*.jar"/>
</owasp:dependency-check>
</target>
<target name="html-check" description="--> Runs the Nu Html Checker" depends="init-ivy">
<ivy:cachepath organisation="nu.validator" module="validator" revision="${htmlcheck.nu.version}"
inline="true" conf="default" pathid="nu.classpath"/>
<fileset dir="." id="html.files">
<include name="${src.dir}/**/*.html"/>
<include name="${manual.dir}/**/*.html"/>
<exclude name="${manual.dir}/index.html"/>
</fileset>
<pathconvert pathsep=" " property="html.list" refid="html.files"/>
<mkdir dir="${htmlcheck.report.dir}"/>
<java classname="nu.validator.client.SimpleCommandLineValidator" classpathref="nu.classpath"
taskname="html-check" output="${htmlcheck.report.file}">
<arg line="--html --format text"/>
<arg line="${html.list}"/>
</java>
<concat><file name="${htmlcheck.report.file}"/></concat>
</target>
</project>