Skip to main content
summaryrefslogtreecommitdiffstats
blob: 787cd7816db446a5d6c0ab97e4702274e46d6f62 (plain) (blame)
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<project default="noDefault" name="getDependencies - gets all dependencies">

	<target name="noDefault">
		<echo>Must specify a target such as 'getCodeStyleDependencies'.</echo>
	</target>


	<macrodef name="get-code-quality-libraries">
		<sequential>
			<mkdir dir="${downloadsDir}" />
			<mkdir dir="${thirdPartyJarsDir}" />

			<!-- ANT CONTRIB CHECKS -->
			<condition property="antContribJarUnavailable">
				<not>
					<or>
						<available file="${relengCommonBuilderDir}/lib/ant-contrib.jar" type="file" />
						<available file="${relengBaseBuilderDir}/lib/ant-contrib.jar" type="file" />
						<available file="${thirdPartyJarsDir}/ant-contrib.jar" type="file" />
						<available file="/usr/share/java/ant-contrib.jar" type="file" />
					</or>
				</not>
			</condition>
			<antcall target="check.ant-contrib" />
			<!-- This will fail if ant-contrib.jar cannot be found. You can install Ant-Contrib via RPM, or download it here:
					  http://downloads.sourceforge.net/ant-contrib/ant-contrib-1.0b2-bin.zip
					  -->


			<!-- CHECK STYLE CHECKS -->
			<condition property="checkStyleJarUnavailable">
				<not>
					<or>
						<available file="${thirdPartyJarsDir}/checkstyle/checkstyle-all-5.0.jar" type="file" />
					</or>
				</not>
			</condition>
			<antcall target="check.check-style" />


			<!-- PMD CHECKS -->
			<condition property="pmdJarUnavailable">
				<not>
					<or>
						<available file="${thirdPartyJarsDir}/pmd/pmd-4.2.5.jar" type="file" />
					</or>
				</not>
			</condition>
			<antcall target="check.pmd" />


			<!-- FIND BUGS -->
			<condition property="findBugsJarUnavailable">
				<not>
					<or>
						<available file="${thirdPartyJarsDir}/findbugs/findbugs-ant.jar" type="file" />
					</or>
				</not>
			</condition>
			<antcall target="check.find-bugs" />

		</sequential>
	</macrodef>


	<macrodef name="set-code-quality-classpath">
		<attribute name="classpath" />
		<sequential>
			<!-- ANT CONTRIB -->
			<taskdef resource="net/sf/antcontrib/antlib.xml">
				<classpath>
					<pathelement path="@{classpath}" />
					<pathelement location="${relengCommonBuilderDir}/lib/ant-contrib.jar" />
					<pathelement location="${relengBaseBuilderDir}/lib/ant-contrib.jar" />
					<pathelement location="${thirdPartyJarsDir}/ant-contrib.jar" />
					<pathelement location="/usr/share/java/ant-contrib.jar" />
				</classpath>
			</taskdef>

			<!-- CHECK STYLE  -->
			<taskdef resource="checkstyletask.properties">
				<classpath>
					<pathelement path="@{classpath}" />
					<fileset dir="${thirdPartyJarsDir}/checkstyle" includes="*.jar" />
				</classpath>
			</taskdef>
			<!-- PMD  -->
			<path id="pmd.classpath">
				<pathelement path="@{classpath}" />
				<fileset dir="${thirdPartyJarsDir}/pmd" includes="*.jar" />
			</path>
			<taskdef name="pmd" classpathref="pmd.classpath" classname="net.sourceforge.pmd.ant.PMDTask" />
			<taskdef name="cpd" classpathref="pmd.classpath" classname="net.sourceforge.pmd.cpd.CPDTask" />

			<!-- FIND BUGS -->
			<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
				<!-- resource="/edu/umd/cd/findbugs/anttask/tasks.properties">-->
				<classpath>
					<pathelement path="@{classpath}" />
					<fileset dir="${thirdPartyJarsDir}/findbugs" includes="*.jar" />
				</classpath>
			</taskdef>
		</sequential>
	</macrodef>

	<target name="get.ant-contrib" if="thirdPartyDownloadLicenseAcceptanceOK">
		<get src="http://sourceforge.net/projects/ant-contrib/files/ant-contrib/ant-contrib-1.0b2/ant-contrib-1.0b2-bin.zip/download" dest="${downloadsDir}/ant-contrib-1.0b2-bin.zip" usetimestamp="true" />
		<touch file="${downloadsDir}/ant-contrib-1.0b2-bin.zip" />
		<mkdir dir="/tmp/ant-contrib-1.0b2-bin.zip_" />
		<unzip src="${downloadsDir}/ant-contrib-1.0b2-bin.zip" dest="/tmp/ant-contrib-1.0b2-bin.zip_" overwrite="true" />
		<copy file="/tmp/ant-contrib-1.0b2-bin.zip_/ant-contrib/lib/ant-contrib.jar" tofile="${thirdPartyJarsDir}/ant-contrib.jar" failonerror="true" />
		<delete dir="/tmp/ant-contrib-1.0b2-bin.zip_" includeemptydirs="true" quiet="true" />
	</target>

	<target name="get.check-style" if="thirdPartyDownloadLicenseAcceptanceOK">
		<get src="http://sourceforge.net/projects/checkstyle/files/checkstyle/5.0/checkstyle-5.0.zip/download" dest="${downloadsDir}/checkstyle-5.0.zip" usetimestamp="true" />
		<touch file="${downloadsDir}/checkstyle-5.0.zip" />
		<mkdir dir="/tmp/checkstyle-5.0.zip_" />
		<unzip src="${downloadsDir}/checkstyle-5.0.zip" dest="/tmp/checkstyle-5.0.zip_" overwrite="true" />
		<!-- transfer unzipped jars to 3rd party folder -->
		<mkdir dir="${thirdPartyJarsDir}/checkstyle" />
		<copy todir="${thirdPartyJarsDir}/checkstyle" failonerror="true">
			<fileset dir="/tmp/checkstyle-5.0.zip_/checkstyle-5.0" includes="*.jar" />
		</copy>
		<delete dir="/tmp/checkstyle-5.0.zip_" includeemptydirs="true" quiet="true" />
	</target>

	<target name="get.pmd" if="thirdPartyDownloadLicenseAcceptanceOK">
		<get src="http://sourceforge.net/projects/pmd/files/pmd/4.2.5/pmd-bin-4.2.5.zip/download" dest="${downloadsDir}/pmd-bin-4.2.5.zip" usetimestamp="true" />
		<touch file="${downloadsDir}/pmd-bin-4.2.5.zip" />
		<mkdir dir="/tmp/pmd-bin-4.2.5.zip_" />
		<unzip src="${downloadsDir}/pmd-bin-4.2.5.zip" dest="/tmp/pmd-bin-4.2.5.zip_" overwrite="true" />
		<!-- transfer unzipped jars to 3rd party folder -->
		<mkdir dir="${thirdPartyJarsDir}/pmd" />
		<copy todir="${thirdPartyJarsDir}/pmd" failonerror="true">
			<fileset dir="/tmp/pmd-bin-4.2.5.zip_/pmd-4.2.5/lib" includes="*.jar" />
			<fileset dir="/tmp/pmd-bin-4.2.5.zip_/pmd-4.2.5/etc/xslt" exclude="*.txt" />
		</copy>
		<delete dir="/tmp/pmd-bin-4.2.5.zip_" includeemptydirs="true" quiet="true" />
	</target>

	<target name="get.find-bugs" if="thirdPartyDownloadLicenseAcceptanceOK">
		<get src="http://sourceforge.net/projects/findbugs/files/findbugs/1.3.8/findbugs-1.3.8.zip/download" dest="${downloadsDir}/findbugs-1.3.8.zip" usetimestamp="true" />
		<touch file="${downloadsDir}/findbugs-1.3.8.zip" />
		<mkdir dir="/tmp/findbugs-1.3.8.zip_" />
		<unzip src="${downloadsDir}/findbugs-1.3.8.zip" dest="/tmp/findbugs-1.3.8.zip_" overwrite="true" />
		<!-- transfer unzipped jars to 3rd party folder -->
		<mkdir dir="${thirdPartyJarsDir}/findbugs" />
		<copy todir="${thirdPartyJarsDir}/findbugs" failonerror="true">
			<fileset dir="/tmp/findbugs-1.3.8.zip_/findbugs-1.3.8/lib" includes="*.jar" />
		</copy>
		<delete dir="/tmp/findbugs-1.3.8.zip_" includeemptydirs="true" quiet="true" />
	</target>

	<target name="check.ant-contrib" if="antContribJarUnavailable">
		<condition property="thirdPartyDownloadLicenseAcceptanceOK">
			<and>
				<isset property="thirdPartyDownloadLicenseAcceptance" />
				<equals arg1="${thirdPartyDownloadLicenseAcceptance}" arg2="&quot;I accept&quot;" />
			</and>
		</condition>
		<antcall target="get.ant-contrib" />
		<available file="${thirdPartyJarsDir}/ant-contrib.jar" property="antContribJarAvailable" />
		<fail unless="antContribJarAvailable">Error! 

	Ant-Contrib 1.0b2 is required. Download it from http://downloads.sourceforge.net/ant-contrib/ant-contrib-1.0b2-bin.zip/download,
	then place it in one of the following locations. You can also redefine these paths in your build.properties file:

	$${thirdPartyJarsDir}/ant-contrib.jar          = ${thirdPartyJarsDir}/ant-contrib.jar
				
	Or, to download this automatically, set build.properties#thirdPartyDownloadLicenseAcceptance to "I Accept".
	</fail>
	</target>

	<target name="check.check-style" if="checkStyleJarUnavailable">
		<condition property="thirdPartyDownloadLicenseAcceptanceOK">
			<and>
				<isset property="thirdPartyDownloadLicenseAcceptance" />
				<equals arg1="${thirdPartyDownloadLicenseAcceptance}" arg2="&quot;I accept&quot;" />
			</and>
		</condition>
		<antcall target="get.check-style" />
		<available file="${thirdPartyJarsDir}/checkstyle/checkstyle-all-5.0.jar" property="checkStyleJarUnavailable" />
		<fail unless="checkStyleJarUnavailable">Error! 

	Check Style 5.0 is required. Download it from http://sourceforge.net/projects/checkstyle/files/checkstyle/5.0/checkstyle-5.0.zip/download,
	then place it in one of the following locations. You can also redefine these paths in your build.properties file:

	$${thirdPartyJarsDir}/checkstyle/checkstyle-all-5.0.jar          = ${thirdPartyJarsDir}/checkstyle/checkstyle-all-5.0.jar
				
	Or, to download this automatically, set build.properties#thirdPartyDownloadLicenseAcceptance to "I Accept".
	</fail>
	</target>

	<target name="check.pmd" if="pmdJarUnavailable">
		<condition property="thirdPartyDownloadLicenseAcceptanceOK">
			<and>
				<isset property="thirdPartyDownloadLicenseAcceptance" />
				<equals arg1="${thirdPartyDownloadLicenseAcceptance}" arg2="&quot;I accept&quot;" />
			</and>
		</condition>
		<antcall target="get.pmd" />
		<available file="${thirdPartyJarsDir}/pmd/pmd-4.2.5.jar" property="pmdJarUnavailable" />
		<fail unless="pmdJarUnavailable">Error! 

	PMD 4.2.5 is required. Download it from http://sourceforge.net/projects/pmd/files/pmd/4.2.5/pmd-bin-4.2.5.zip/download,
	then place it in one of the following locations. You can also redefine these paths in your build.properties file:

	$${thirdPartyJarsDir}/pmd/pmd-4.2.5.jar          = ${thirdPartyJarsDir}/pmd/pmd-4.2.5.jar
				
	Or, to download this automatically, set build.properties#thirdPartyDownloadLicenseAcceptance to "I Accept".
	</fail>
	</target>

	<target name="check.find-bugs" if="findBugsJarUnavailable">
		<condition property="thirdPartyDownloadLicenseAcceptanceOK">
			<and>
				<isset property="thirdPartyDownloadLicenseAcceptance" />
				<equals arg1="${thirdPartyDownloadLicenseAcceptance}" arg2="&quot;I accept&quot;" />
			</and>
		</condition>
		<antcall target="get.find-bugs" />
		<available file="${thirdPartyJarsDir}/findbugs/findbugs-ant.jar" property="findBugsJarUnavailable" />
		<fail unless="findBugsJarUnavailable">Error! 

	FindBugs 1.3.8 is required. Download it from http://sourceforge.net/projects/findbugs/files/findbugs/1.3.8/findbugs-1.3.8.zip/download,
	then place it in one of the following locations. You can also redefine these paths in your build.properties file:

	$${thirdPartyJarsDir}/findbugs/findbugs-ant.jar          = ${thirdPartyJarsDir}/findbugs/findbugs-ant.jar
				
	Or, to download this automatically, set build.properties#thirdPartyDownloadLicenseAcceptance to "I Accept".
	</fail>
	</target>

	<macrodef name="check-style-check">
		<attribute name="rules" />
		<attribute name="source.dir" />
		<attribute name="output.dir" />
		<sequential>
			<echo message="Check Style - @{source.dir}" />
			<checkstyle config="@{rules}" failureProperty="checkstyle.failure" failOnViolation="false">
				<formatter type="xml" tofile="@{output.dir}/checkstyle_report.xml" />
				<fileset dir="@{source.dir}" includes="**/*.java" />
			</checkstyle>
		</sequential>
	</macrodef>

	<macrodef name="pmd-check">
		<attribute name="rules" />
		<attribute name="source.dir" />
		<attribute name="output.dir" />
		<sequential>
			<echo message="PMD Check - @{source.dir}" />
			<pmd shortfilenames="true" failonerror="true" failOnRuleViolation="false" targetjdk="1.6" rulesetfiles="@{rules}">
				<formatter type="xml" toFile="@{output.dir}/pmd_report.xml" />
				<!--<formatter type="html" toFile="${results-location}/pmd_report.html" linePrefix=".line" /> -->
				<!-- <formatter type="summaryhtml" toFile="${results-location}/pmd_summary_report.html" /> -->
				<fileset dir="@{source.dir}" includes="**/*.java" />
			</pmd>
		</sequential>
	</macrodef>

	<macrodef name="pmd-copy-paste-check">
		<attribute name="min.token.count" />
		<attribute name="source.dir" />
		<attribute name="output.dir" />
		<sequential>
			<echo message="PMD-COPY-PASTE Check - @{source.dir}" />
			<cpd minimumTokenCount="@{min.token.count}" ignoreLiterals="false" language="java" format="xml" outputfile="@{output.dir}/pmd_cpd_report.xml">
				<fileset dir="@{source.dir}" includes="**/*.java" />
			</cpd>
			<!--<xslt in="${results-location}/pmd_cpd_report.xml" style="etc/xslt/cpdhtml.xslt" out="${results-location}/pmd_cpd_report.html" />-->
		</sequential>
	</macrodef>


	<macrodef name="findbugs-check">
		<attribute name="source.dir" />
		<attribute name="output.dir" />
		<attribute name="jar.to.analyze" />
		<attribute name="dependecy.jars" />
		<sequential>
			<echo message="FIND-BUGS Check - @{source.dir}" />
			<!-- pass the Jar file with the code and all the dependency jars -->
			<!-- <jar basedir="@{source.dir}/bin/" destfile="@{output.dir}/temp.jar" includes="**/*.class" /> -->

			<findbugs home="${thirdPartyJarsDir}/findbugs" output="xml" outputFile="@{output.dir}/findbugs_report.xml" effort="default" failOnError="false">
				<auxClasspath path="@{dependecy.jars}" />
				<sourcePath path="@{source.dir}/src/**/*.java" />
				<class location="@{jar.to.analyze}" />
			</findbugs>
			<delete file="@{output.dir}/temp.jar" quiet="true" />
			<!--<xslt in="@{output.dir}/findbugs_report.xml" style="fancy-hist.xsl" out="@{output.dir}/findbugs_report.html" />-->
		</sequential>
	</macrodef>

	<macrodef name="all-code-quality-checks">
		<attribute name="bundle.list" />
		<sequential>
			<mkdir dir="${buildDir}" />
			<for param="bundle" delimiter=";" list="@{bundle.list}">
				<sequential>
					<if>
						<isset property="@{bundle}" />
						<then>
							<echo message="Processing... ${bundle}" />
						</then>
					</if>


					<propertyregex property="output" override="true" input="@{bundle}" regexp="[^\\]+$" select="\0" casesensitive="false" />

					<echo message="Processing... @{bundle} to ${output}" />
					<mkdir dir="${buildDir}/${output}" />
					<check-style-check source.dir="@{bundle}" output.dir="${buildDir}/${output}" rules="${osee-checkstyle-rules}" />
					<pmd-check source.dir="@{bundle}" output.dir="${buildDir}/${output}" rules="${osee-pmd-rules}" />
					<pmd-copy-paste-check source.dir="@{bundle}" output.dir="${buildDir}/${output}" min.token.count="100" />

					<!-- <findbugs-check source.dir="@{bundle}" output.dir="${output}"/> -->
				</sequential>
			</for>
		</sequential>
	</macrodef>

	<macrodef name="create-html-index">
		<attribute name="bundle.list" />
		<attribute name="output" />
		<sequential>
			<echo message="&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
				&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot; &gt;
				&lt;html&gt;&lt;head&gt;" file="@{output}" />
			<echo message="&lt;style type=&quot;text/css&quot;&gt;" file="@{output}" append="true" />
			<echo message="table.oseeTable { border-width: 1px 1px 1px 1px; border-spacing: 2px; border-style: solid solid solid solid; border-color: blue blue blue blue; border-collapse: separate; background-color: rgb(255, 250, 250); } table.oseeTable th { border-width: 1px 1px 1px 1px; padding: 4px 4px 4px 4px; border-style: solid solid solid solid; border-color: black black black black; background-color: white; -moz-border-radius: 0px 0px 0px 0px; } table.oseeTable td { border-width: 1px 1px 1px 1px; padding: 4px 4px 4px 4px; border-style: solid solid solid solid; border-color: black black black black; background-color: white; -moz-border-radius: 0px 0px 0px 0px; }" file="@{output}" append="true" />
			<echo message="&lt;/style&gt;" file="@{output}" append="true" />
			<echo message="&lt;/head&gt;&lt;body&gt;" file="@{output}" append="true" />
			<echo message="&lt;div id=&quot;content&quot;&gt;" file="@{output}" append="true" />

			<echo message="&lt;table class=&quot;oseeTable&quot; width=&quot;95%&quot; &gt;
				&lt;th&gt;Name&lt;/th&gt;
				&lt;th&gt;Format&lt;/th&gt;
				&lt;th&gt;PMD&lt;/th&gt;
				&lt;th&gt;Copy/Paste&lt;/th&gt;
				&lt;th&gt;BUGS&lt;/th&gt;" file="@{output}" append="true" />
			<for param="bundle" delimiter=";" list="@{bundle.list}">
				<sequential>
					<propertyregex property="folder" override="true" input="@{bundle}" regexp="[^\\]+$" select="\0" casesensitive="false" />

					<echo message="&lt;tr&gt;" file="@{output}" append="true" />
					<echo message="&lt;td&gt;${folder}&lt;/td&gt;" file="@{output}" append="true" />
					<echo message="&lt;td&gt;&lt;a href=&quot;${folder}/checkstyle_report.xml&quot; &gt;Style&lt;/a&gt;&lt;/td&gt;" file="@{output}" append="true" />
					<echo message="&lt;td&gt;&lt;a href=&quot;${folder}/pmd_report.xml&quot; &gt;PMD&lt;/a&gt;&lt;/td&gt;" file="@{output}" append="true" />
					<echo message="&lt;td&gt;&lt;a href=&quot;${folder}/pmd_cpd_report.xml&quot; &gt;CP&lt;/a&gt;&lt;/td&gt;" file="@{output}" append="true" />
					<echo message="&lt;td&gt;&lt;a href=&quot;${folder}/findbugs_report.xml&quot; &gt;BUGS&lt;/a&gt;&lt;/td&gt;" file="@{output}" append="true" />
					<echo message="&lt;/tr&gt;" file="@{output}" append="true" />
				</sequential>
			</for>
			<echo message="&lt;/table&gt;" file="@{output}" append="true" />
			<echo message="&lt;/div&gt;" file="@{output}" append="true" />
			<echo message="&lt;/body&gt;&lt;/html&gt;" file="@{output}" append="true" />
		</sequential>
	</macrodef>
</project>

Back to the top