aboutsummaryrefslogtreecommitdiffstats
blob: 8d8bb235f7d25796f67f4f797c4461bd984d7ecd (plain)
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
 ******************************************************************************
 * Copyright (c) 2008, 2010 VMware Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 ******************************************************************************
-->
<project name="quality-common" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:osgi="antlib:org.springframework.build.osgi">

<!-- Main targets -->
	<target name="test" depends="jar, test.pre, test.do, test.post" description="Executes all tests resulting from a compilation of the test tree returning test success metrics."/>

	<target name="clover" depends="clover.pre, clover.do, clover.post" description="Executes all tests resulting from a compilation of the test tree returning test coverage metrics."/>

	<target name="findbugs" depends="findbugs.pre, findbugs.do" description="Checks all code from the source tree for bugs."/>

	<target name="report" depends="ivy.init, resolve" description="Produce a HTML formatted report about all the dependencies and sub-dependencies of this build">
		<mkdir dir="${ivy.report.todir}" />
		<ivy:report conf="test, runtime, optional, provided, server-provided, aspects, external, additional" graph="false" xml="true"/>
	</target>

<!-- Other targets -->
	<target name="test.pre" depends="test.init" if="test.exists">
		<delete dir="${test-results.output.dir}" quiet="true"/>
		<mkdir dir="${test-results.output.dir}/xml"/>
	</target>

	<target name="test.do" depends="ivy.init, resolve.test, compile.init, test.init" if="test.exists">
		<path id="test.compile.classpath">
			<pathelement location="${jar.output.file}"/>
			<path refid="compile.classpath"/>
			<path refid="test.classpath"/>
		</path>
		<test-compile classpath.id="test.compile.classpath" input.dir="${test.java.dir}" output.dir="${test.output.dir}"
				resources.dir="${test.resources.dir}"/>

		<path id="test.run.classpath">
			<pathelement location="${jar.output.file}"/>
			<pathelement location="${test.output.dir}"/>
			<path refid="compile.classpath"/>
			<path refid="test.classpath"/>
			<path refid="runtime.classpath"/>
		</path>
		<test-run classpath.id="test.run.classpath"/>
	</target>

	<target name="test.post" depends="test.init" if="test.exists">
		<mkdir dir="${test-results.output.dir}/html"/>
		<junitreport>
			<fileset dir="${test-results.output.dir}/xml" erroronmissingdir="false"/>
			<report format="frames" todir="${test-results.output.dir}/html"/>
		</junitreport>
		<delete file="TESTS-TestSuites.xml"/>
	</target>

	<target name="clover.init" depends="ivy.init">
		<ivy:cachepath resolveId="clover.classpath" pathid="clover.classpath" organisation="com.atlassian.clover"
				module="com.springsource.com.cenqua.clover" revision="${com.springsource.com.cenqua.clover.version}"
				conf="runtime" type="jar" inline="true" log="download-only"/>
		<taskdef resource="cloverlib.xml" classpathref="clover.classpath"/>
	</target>

	<target name="clover.pre">
		<delete dir="${clover.output.dir}" quiet="true"/>
		<mkdir dir="${clover.output.dir}"/>
	</target>

	<target name="clover.do" depends="ivy.init, resolve.test, compile.init, clover.instrument, test.init"
			if="test.exists">
		<path id="test.compile.classpath">
			<pathelement location="${main.output.dir}"/>
			<path refid="compile.classpath" />
			<path refid="test.classpath"/>
		</path>

		<path id="clover.run.classpath">
			<pathelement location="${main.output.dir}"/>
			<pathelement location="${test.output.dir}"/>
			<path refid="clover.classpath"/>
			<path refid="compile.classpath"/>
			<path refid="test.classpath"/>
			<path refid="runtime.classpath"/>
		</path>
		<test-run classpath.id="clover.run.classpath"/>
	</target>

	<target name="clover.instrument" depends="ivy.init, resolve.test, compile.init, clover.init">
		<instrument input.dir="${main.java.dir}" output.dir="${main.clover.dir}"/>
		<path id="clover.compile.classpath">
			<path refid="clover.classpath"/>
			<path refid="compile.classpath"/>
		</path>
		<compile classpath.id="clover.compile.classpath" input.dir="${main.clover.dir}" output.dir="${main.output.dir}"
				resources.dir="${main.resources.dir}"/>

		<instrument input.dir="${test.java.dir}" output.dir="${test.clover.dir}"/>
		<path id="test.compile.classpath">
			<pathelement location="${main.output.dir}"/>
			<path refid="clover.classpath"/>
			<path refid="compile.classpath"/>
			<path refid="test.classpath"/>
		</path>
		<test-compile classpath.id="test.compile.classpath" input.dir="${test.clover.dir}" output.dir="${test.output.dir}"
				resources.dir="${test.resources.dir}"/>
		<delete dir="${clover.staging.dir}" quiet="true"/>
	</target>

	<target name="clover.post" depends="clover.init">
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/clover.xml">
				<format type="xml"/>
				<testsources dir="${test.java.dir}">
					<include name="**/*.java"/>
					<include name="*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/html">
				<format type="html"/>
				<testsources dir="${test.java.dir}">
					<include name="**/*.java"/>
					<include name="*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/clover.pdf" summary="true">
				<format type="pdf"/>
				<testsources dir="${test.java.dir}">
					<include name="**/*.java"/>
					<include name="*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-check initstring="${clover.db.file}" target="${clover.coverage}" haltOnFailure="${clover.enforce}">
			<testsources dir="${test.java.dir}">
				<include name="**/*.java"/>
				<include name="*.java"/>
			</testsources>
		</clover-check>
	</target>

	<target name="findbugs.init" depends="ivy.init, findbugs.download">
		<ivy:cachepath resolveId="findbugs.classpath" pathid="findbugs.classpath" organisation="edu.umd.cs.findbugs"
				module="com.springsource.edu.umd.cs.findbugs.ant" revision="${edu.umd.cs.findbugs.version}"
				conf="runtime" type="jar" inline="true" log="download-only"/>
		<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
				classpathref="findbugs.classpath"/>
	</target>

	<target name="findbugs.download" depends="findbugs.download.init" if="findbugs.download.needed">
		<ivy:cachepath resolveId="findbugs" pathid="findbugs" organisation="edu.umd.cs.findbugs"
				module="edu.umd.cs.findbugs.dist" revision="${edu.umd.cs.findbugs.version}" conf="runtime" type="zip"
				inline="true" log="download-only"/>
		<unzip dest="${findbugs.dir}">
			<path refid="findbugs"/>
			<globmapper from="findbugs-${edu.umd.cs.findbugs.version}/*" to="*"/>
		</unzip>
	</target>

	<target name="findbugs.download.init">
		<condition property="findbugs.download.needed">
			<not>
				<available file="${findbugs.dir}" type="dir"/>
			</not>
		</condition>
	</target>

	<target name="findbugs.pre" depends="src.init" if="src.exists">
		<delete dir="${findbugs.output.dir}" quiet="true"/>
		<mkdir dir="${findbugs.output.dir}"/>
	</target>

	<target name="findbugs.do" depends="ivy.init, resolve.compile, compile.init, findbugs.init, src.init" if="src.exists">
		<findbugs home="${findbugs.dir}" output="xml" outputFile="${findbugs.output.file}"
				excludeFilter="${findbugs.exclude.file}" jvmargs="-Xmx1024M" errorProperty="findbugs.errors" warningsProperty="findbugs.warnings">
			<class location="${main.output.dir}"/>
			<auxClasspath>
				<!-- Require something to always be in this classpath so findbugs on windows runs -->
				<path location="." />
				<path refid="compile.classpath"/>
			</auxClasspath>
			<sourcepath location="${main.java.dir}"/>
		</findbugs>
		<antcall target="findbugs.post"/>
	</target>

	<target name="findbugs.post" if="findbugs.enforce">
		<fail if="findbugs.errors" message="FindBugs errors found"/>
		<fail if="findbugs.warnings" message="FindBugs warnings found"/>
	</target>

<!-- Macros -->
	<macrodef name="test-run">
		<attribute name="classpath.id"/>
		<sequential>
			<condition property="test.halt" value="false" else="true">
				<istrue value="${ci.build}"/>
			</condition>
			<mkdir dir="${test-results.output.dir}/xml"/>
			<junit forkmode="${test.forkmode}" dir="${basedir}" haltonerror="${test.halt}" haltonfailure="${test.halt}">
				<jvmarg line="${test.vm.args}"/>
				<syspropertyset>
					<propertyref builtin="commandline"/>
				</syspropertyset>
				<classpath refid="@{classpath.id}"/>
				<test fork="yes" todir="${test-results.output.dir}/xml" name="${testcase}" if="testcase"/>
				<batchtest fork="yes" todir="${test-results.output.dir}/xml" unless="testcase">
					<fileset dir="${test.output.dir}" erroronmissingdir="false">
						<include name="**/*Test.class"/>
						<include name="**/*Tests.class"/>
						<exclude name="**/Abstract*.class"/>
					</fileset>
				</batchtest>
				<formatter type="brief" usefile="false"/>
				<formatter type="xml"/>
			</junit>
		</sequential>
	</macrodef>

	<macrodef name="instrument">
		<attribute name="input.dir"/>
		<attribute name="output.dir"/>
		<sequential>
			<clover-instr initstring="${clover.db.file}" destdir="@{output.dir}">
				<fileset dir="@{input.dir}" erroronmissingdir="false">
					<include name="**/*.java"/>
					<include name="*.java"/>
				</fileset>
			</clover-instr>
			<copy todir="@{output.dir}">
				<fileset dir="@{input.dir}" erroronmissingdir="false">
					<exclude name="**/*.java"/>
					<exclude name="*.java"/>
				</fileset>
			</copy>
		</sequential>
	</macrodef>
</project>