-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
279 lines (251 loc) · 13.8 KB
/
build.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
<project name="gearman-java" default="usage" basedir=".">
<property file="${user.home}/.ant/${ant.project.name}.properties"/>
<property name="project.version" value="0.04"/>
<property name="src.dir" location="./src" />
<property name="test.src.dir" location="./test" />
<property name="build.dir" location="./build" />
<property name="build.classes.dir" location="${build.dir}/classes" />
<property name="build.tests.dir" location="${build.dir}/tests" />
<property name="dist.dir" location="${build.dir}/../dist" />
<property name="dist.lib.dir" location="${dist.dir}/lib" />
<property name="build.docs.dir" location="${build.dir}/javadocs" />
<property name="dist.docs.dir" location="${dist.dir}/docs" />
<property name="dist.jar" location="${dist.lib.dir}/${ant.project.name}-${project.version}.jar"/>
<property name="api.pkg" value="org.gearman"/>
<property name="pmd.home" value="${user.home}/.ant/lib/pmd"/>
<property name="junit.jar" value="${user.home}/.ant/lib/junit.jar"/>
<property name="findbugs.home" value="${user.home}/.ant/lib/findbugs"/>
<property name="checkstyle.home" value="${user.home}/.ant/lib/checkstyle"/>
<property name="emma.home" value="${user.home}/.ant/lib/emma"/>
<property name="coverage.dir" value="${build.dir}/emma"/>
<path id="build.classpath">
<pathelement location="${build.classes.dir}" />
</path>
<path id="test.classpath">
<pathelement location="${dist.jar}" />
<pathelement location="${build.tests.dir}"/>
<pathelement location="${junit.jar}" />
</path>
<path id="pmd.lib.search.path">
<pathelement path="${pmd.home}/lib/"/>
<pathelement path="${java.class.path}"/>
<pathelement path="lib/pmd/lib/"/>
</path>
<path id="findbugs.lib.search.path">
<pathelement path="${findbugs.home}/lib/"/>
<pathelement path="${java.class.path}"/>
<pathelement path="lib/findbugs/lib/"/>
</path>
<path id="checkstyle.lib.search.path">
<pathelement path="${checkstyle.home}/"/>
<pathelement path="${java.class.path}"/>
<pathelement path="lib/checkstyle/lib/"/>
</path>
<path id="emma.lib" >
<pathelement location="${emma.home}/lib/emma.jar"/>
<pathelement location="${emma.home}/lib/emma_ant.jar"/>
</path>
<target name="-check_pmd" description="Check that pmd jar files are present">
<available file="pmd.jar" type="file" property="pmd.jar.present">
<filepath refid="pmd.lib.search.path"/>
</available>
<fail unless="pmd.jar.present" message="Please install pmd.jar in lib-directory (or in ant classpath) to run PMD."/>
</target>
<target name="pmd" depends="compile, -check_pmd" description="Check the code with PMD">
<condition property="pmd.report.type" value="html" else="xml">
<isset property="gearman-java.reports.text"/>
</condition>
<path id="pmd.lib" >
<pathelement location="${pmd.home}/lib/pmd.jar"/>
<pathelement location="${pmd.home}/lib/jaxen.jar"/>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.lib"/>
<mkdir dir="build/pmd"/>
<pmd targetjdk="1.5" failOnRuleViolation="true" failuresPropertyName="pmd.num.warnings" rulesetfiles="tools/pmd/ruleset.xml">
<formatter type="${pmd.report.type}" toFile="build/pmd/report.${pmd.report.type}"/>
<fileset dir="src" includes="**/*.java"/>
</pmd>
<condition property="pmd.num.warnings.value" value="${pmd.num.warnings}" else="0">
<isset property="pmd.num.warnings"/>
</condition>
<echo message="PMD finished, found ${pmd.num.warnings.value} warnings, see build/pmd/pmd_report.html"/>
</target>
<target name="-check_findbugs" description="Check that findbugs jar files are present">
<available file="findbugs.jar" type="file" property="findbugs.jar.present">
<filepath refid="findbugs.lib.search.path"/>
</available>
<fail unless="findbugs.jar.present" message="Could not find findbugs.jar"/>
<available file="findbugs-ant.jar" type="file" property="findbugs-ant.jar.present">
<filepath refid="findbugs.lib.search.path"/>
</available>
<fail unless="findbugs-ant.jar.present" message="Could not find findbugs-ant.jar"/>
</target>
<target name="findbugs" depends="dist, -check_findbugs" description="Check the code with Findbugs">
<condition property="findbugs.report.type" value="html" else="xml">
<isset property="gearman-java.reports.text"/>
</condition>
<path id="findbugs.lib" >
<pathelement location="${findbugs.home}/lib/findbugs.jar"/>
<pathelement location="${findbugs.home}/lib/findbugs-ant.jar"/>
</path>
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.lib"/>
<mkdir dir="build/findbugs"/>
<findbugs projectname="${ant.project.name}-${project.version}" home="${findbugs.home}" output="${findbugs.report.type}" outputFile="build/findbugs/findbugs.${findbugs.report.type}" warningsProperty="findbugs-warnings">
<sourcePath path="src" />
<class location="${dist.jar}" />
</findbugs>
<fail if="findbugs-warnings" message="findbugs found one or more warnings"/>
</target>
<target name="-check_checkstyle" description="Check that checkstyle jar files are present">
<available file="checkstyle-all.jar" type="file" property="checkstyle.jar.present">
<filepath refid="checkstyle.lib.search.path"/>
</available>
<fail unless="checkstyle.jar.present" message="Please install checkstyle-all.jar in lib-directory (or in ant classpath) to run Checkstyle, see README."/>
</target>
<target name="checkstyle" depends="compile, -check_checkstyle" description="Check the style with Checkstyle">
<condition property="checkstyle.report.type" value="plain" else="xml">
<isset property="gearman-java.reports.text"/>
</condition>
<taskdef resource="checkstyletask.properties" classpath="${checkstyle.home}/checkstyle-all.jar"/>
<mkdir dir="build/checkstyle"/>
<checkstyle config="tools/checkstyle/ruleset.xml" failOnViolation="true">
<fileset dir="src" includes="**/*.java"/>
<formatter type="${checkstyle.report.type}" toFile="build/checkstyle/errors.${checkstyle.report.type}"/>
</checkstyle>
</target>
<target name="-check_emma" description="Check that emma jar files are present">
<available file="${emma.home}/lib/emma.jar" type="file" property="emma.jar.present"/>
<fail unless="emma.jar.present" message="Could not find emma.jar"/>
<available file="${emma.home}/lib/emma_ant.jar" type="file" property="emma_ant.jar.present"/>
<fail unless="emma_ant.jar.present" message="Could not find emma_ant.jar"/>
</target>
<target name="emma-instrument" depends="compile, -check_emma" description="Instruments the source code for Emma code coverage analysis">
<taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
<mkdir dir="${coverage.dir}" />
<emma enabled="true">
<instr instrpath="build/classes" metadatafile="${coverage.dir}/coverage.em"
mode="overwrite" filter="+org.gearman.*,-org.gearman.example.*" destdir="${coverage.dir}" />
</emma>
</target>
<target name="emma-report" description="Analyze" depends="-check_emma">
<taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
<emma enabled="true" >
<report sourcepath="${src.dir}">
<infileset dir="${coverage.dir}" includes="*.em, *.ec"/>
<xml outfile="${coverage.dir}/coverage.xml"/>
<html outfile="${coverage.dir}/index.html"/>
</report>
</emma>
</target>
<target name="code-coverage" depends="clean, emma-instrument, test, emma-report" description="Create test code coverage reports based on the unit tests"/>
<target name="validate" depends="clean, dist, pmd, findbugs, checkstyle, test" description="Create test code coverage reports based on the unit tests"/>
<target name="usage">
<echo message="Build the ${ant.project.name} project."/>
<echo message=""/>
<echo message="This build system support the follow targets:"/>
<echo message=""/>
<echo message="help: display this help message."/>
<echo message=""/>
<echo message="compile: builds the project source files."/>
<echo message=""/>
<echo message="dist: generates the project jar file and javadocs."/>
<echo message=""/>
<echo message="findbugs: generates the project jar file and runs findbugs."/>
<echo message=""/>
<echo message="test: builds the jar file and testsuite. Runs the regression tests"/>
<echo message=" against the built jar. Requires Junit 4.6 to be on classpath"/>
<echo message=" or specified via the junit.jar property (-Djunit.jar)"/>
<echo message=" By default, junit will generate xml test results, to generate"/>
<echo message=" plain text results set the gearman-java.reports.text property."/>
<echo message=""/>
<echo message="pmd: builds the jar file and run pmd scan"/>
<echo message=""/>
<echo message="code-coverage: Generate code coverage by running emma."/>
<echo message=""/>
<echo message="validate: builds the jar and then runs a series of validation targets,"/>
<echo message=" including, pmd,findbugs,checkstyle, and test. By default, the"/>
<echo message=" reports generated by the sub taks of this target will be in an"/>
<echo message=" xml format --so that they can be parsed by build tools such as"/>
<echo message=" hudson. To generate reports in a more human friendly format"/>
<echo message=" (html or text) set the gearman-java.reports.text property."/>
<echo message=""/>
<echo message="clean: removes the built classes, jar files and test results"/>
<echo message=""/>
</target>
<!-- removes ./build dir -->
<target name="clean">
<delete dir="${dist.dir}" quiet="true" />
<delete dir="${build.dir}" quiet="true" />
</target>
<!-- Prep the build dir -->
<target name="init">
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${build.tests.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.lib.dir}" />
<mkdir dir="${build.docs.dir}" />
<mkdir dir="${dist.docs.dir}" />
</target>
<!-- build it -->
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="true">
<!--Turned off checked warnings for now, because GearmanClientImpl will fail -->
<!--to compile with warnings even though we are using @supprress annotation -->
<compilerarg value="-Xlint:-unchecked"/>
</javac>
</target>
<!-- generate javadocs -->
<target name="javadoc" depends="compile">
<delete failonerror="false">
<fileset dir="${build.docs.dir}" />
</delete>
<javadoc sourcepath="${src.dir}"
destdir="${build.docs.dir}"
packagenames= "org.gearman.*"
author= "true"
private="true"
version="true"
classpathref="build.classpath"
defaultexcludes="yes"
use="true"
windowtitle="Gearman Java Library API documentation"
doctitle="<h1>Gearman Java Library documentation </h1>">
</javadoc>
</target>
<!-- build jar file -->
<target name="dist" depends="compile,javadoc">
<jar jarfile="${dist.jar}" basedir="${build.classes.dir}"/>
<jar jarfile="${dist.docs.dir}/${ant.project.name}-${project.version}-javadocs.jar" basedir="${build.docs.dir}"/>
</target>
<!-- build junit tests -->
<target name="compileTests" depends="dist">
<javac srcdir="${test.src.dir}" destdir="${build.tests.dir}" classpathref="test.classpath" debug="true" />
</target>
<!-- Run junit tests. Requires that junit.jar be on the CLASSPATH or -->
<!-- the property ${junit.jar} be set to point to the path for the -->
<!-- junit.jar file. Some of the tests may require that a gearmaand -->
<!-- instance be running and listening on the default port. -->
<target name="test" depends="compileTests">
<condition property="junit.report.type" value="plain" else="xml">
<isset property="gearman-java.reports.text"/>
</condition>
<mkdir dir="${build.tests.dir}/results" />
<junit printsummary="true" failureproperty="junit.failure" fork="yes">
<formatter type="${junit.report.type}"/>
<classpath>
<path refid="test.classpath"/>
<path refid="emma.lib"/>
<pathelement path="${java.class.path}"/>
</classpath>
<jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.ec" />
<jvmarg value="-Demma.coverage.out.merge=true" />
<batchtest todir="${build.tests.dir}/results">
<fileset dir="${test.src.dir}">
<include name="**/*Test*.java" />
<exclude name="**/TestUtil.java" />
</fileset>
</batchtest>
</junit>
<fail if="junit.failure" message="One or more unit tests failed. See ${build.tests.dir}/results for details."/>
</target>
</project>