forked from Zutubi/pulse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common-build.xml
425 lines (344 loc) · 16 KB
/
common-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
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:ivy="antlib:org.apache.ivy.ant">
<import file="macros.xml"/>
<presetdef name="javac">
<javac source="5" target="5" includeantruntime="false" />
</presetdef>
<!-- initialise configuration -->
<target name="init" depends="module-pre-init, common-init, module-post-init"/>
<target name="module-pre-init"/>
<target name="module-post-init"/>
<target name="common-init">
<!-- Define custom ant tasks -->
<path id="custom.task.path">
<fileset dir="${project.root.dir}/etc">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef name="copyright" classname="com.zutubi.pulse.CopyrightTask" classpathref="custom.task.path"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="custom.task.path"/>
<property file="${project.root.dir}/ivy.properties"/>
<load-ivy-taskdef/>
<ivy:settings/>
<!-- Load the user's properties, then the module's properties to allow them to
override the default root level properties. -->
<property file="${user.home}/ant.properties"/>
<property file="build.properties"/>
<property file="${project.root.dir}/build.properties"/>
<!-- Grab module info from Ivy -->
<ivy:info file="ivy.xml"/>
<echo message="----------------------------------------------"/>
<echo message=" Component: ${ivy.module}"/>
<echo message="----------------------------------------------"/>
<!-- behavioural defaults -->
<property name="javac.debug" value="true"/>
<property name="javac.deprecation" value="off"/>
<dirname property="current.dir" file="ivy.xml"/>
<!-- INTERNAL: project structural properties -->
<property name="build.dir" value="${current.dir}/build"/>
<property name="build.lib.dir" value="${build.dir}/lib"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="test.classes.dir" value="${build.dir}/test.classes"/>
<property name="report.dir" value="${build.dir}/reports"/>
<property name="build.tmp.dir" value="${build.dir}/tmp"/>
<property name="distconf" value="build,test"/>
<!-- resources / properties definition-->
<patternset id="resources">
<exclude name="**/*.java"/>
</patternset>
<condition property="no.src">
<not>
<available file="src/java"/>
</not>
</condition>
<condition property="no.tests">
<not>
<available file="src/test"/>
</not>
</condition>
<condition property="skip.tests">
<and>
<isset property="no.tests"/>
</and>
</condition>
<!-- Define lib path -->
<path id="lib.path">
<fileset id="module.libs" dir="${build.lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- Define source paths -->
<path id="src.paths">
<pathelement path="src/java"/>
</path>
<path id="src.resources">
<fileset dir="src/java">
<patternset refid="resources"/>
</fileset>
</path>
<path id="src.export.selection">
<fileset dir="src/java">
<include name="**/*"/>
</fileset>
</path>
<!-- Define test paths -->
<path id="test.paths">
<pathelement path="src/test"/>
</path>
<path id="test.resources">
<fileset dir="src/test">
<patternset refid="resources"/>
</fileset>
</path>
<path id="test.export.selection">
<fileset dir="src/test">
<include name="**/*"/>
</fileset>
</path>
<!-- TODO: This exclusion set should be located in the individual model files, not in the base.
TODO: Use: ${ivy.module}.test.selection
-->
<path id="test.run.selection">
<fileset dir="src/test">
<include name="**/*Test.java"/>
<exclude name="**/Cvs*"/>
<exclude name="**/RlsCommandTest*"/>
<exclude name="**/VersionCommandTest*"/>
<exclude name="**/LogInformationAnalyserTest*"/>
<exclude name="**/*Subversion*Test*"/>
<exclude name="**/*WorkingCopyTest*"/>
<exclude name="**/LocalBuildTest.java"/>
<exclude name="**/PostProcessCommandTest.java"/>
<exclude name="**/*Perforce*Test*"/>
</fileset>
</path>
<patternset id="release.excludes">
<exclude name="**/LicenseEncoder*"/>
<exclude name="**/LicenseCommandLineInterface*"/>
</patternset>
</target>
<target name="show" depends="init"/>
<target name="clean" depends="init, module-pre-clean, common-clean, module-post-clean"/>
<target name="module-pre-clean" description="Pre clean hook."/>
<target name="module-post-clean" description="Post clean hook."/>
<target name="common-clean">
<delete dir="${build.dir}"/>
<delete dir="${user.home}/.ivy2/cache/zutubi/${ivy.module}" failonerror="false"/>
<delete failonerror="false">
<fileset dir="${user.home}/.ivy2/cache/" includes="*zutubi*"/>
</delete>
</target>
<!-- prepare for new build -->
<target name="prepare" depends="init, module-pre-prepare, common-prepare, module-post-prepare"/>
<target name="module-pre-prepare" description="Pre prepare hook."/>
<target name="module-post-prepare" description="Post prepare hook."/>
<target name="common-prepare">
<antcall target="build-dependencies"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${build.lib.dir}"/>
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${report.dir}/junit/xml"/>
<mkdir dir="${report.dir}/junit/html"/>
</target>
<target name="build-dependencies" unless="skip.dependencies">
<!-- Determine the build list, storing the details in the build.path.${ivy.module} reference. -->
<ivy:buildlist reference="build.path.${ivy.module}" root="${ivy.module}" excluderoot="true" onMissingDescriptor="skip">
<fileset dir="${project.root.dir}" includes="*/build.xml"/>
<fileset dir="${project.root.dir}/bundles" includes="*/build.xml"/>
</ivy:buildlist>
<!-- run the builds -->
<subant inheritAll="false" target="build.module" buildpathref="build.path.${ivy.module}">
<property name="skip.tests" value="true"/>
<property name="skip.dependencies" value="true"/>
</subant>
</target>
<!-- perform the actual build -->
<target name="build" depends="init, module-pre-build, common-build, module-post-build"/>
<target name="module-pre-build" description="Pre build hook."/>
<target name="module-post-build" description="Post build hook."/>
<target name="common-build">
<echo message="----------------------------------------------"/>
<echo message=" Component: build ${ivy.module}"/>
<echo message="----------------------------------------------"/>
<retrieve-dependencies dest="${build.lib.dir}" conf="build"/>
<if> <!-- if we have srcs to build, then do so. -->
<not><isset property="no.src"/></not>
<then>
<javac target="5" destdir="${classes.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}">
<classpath refid="lib.path"/>
<src refid="src.paths"/>
</javac>
<copy todir="${classes.dir}" overwrite="true">
<path refid="src.resources"/>
</copy>
</then>
</if>
<if> <!-- if we have tests to build, then do so. -->
<not><isset property="no.tests"/></not>
<then>
<retrieve-dependencies dest="${build.lib.dir}" conf="test"/>
<javac target="5" destdir="${test.classes.dir}" debug="true">
<classpath refid="lib.path"/>
<classpath location="${classes.dir}"/>
<src refid="test.paths"/>
</javac>
<copy todir="${test.classes.dir}" overwrite="true">
<path refid="test.resources"/>
</copy>
</then>
</if>
</target>
<!-- run tests -->
<target name="test" depends="init, module-pre-test, common-test, module-post-test"/>
<target name="module-pre-test" description="Pre test hook." unless="skip.tests"/>
<target name="module-post-test" description="Post test hook." unless="skip.tests"/>
<target name="common-test" unless="skip.tests">
<echo message="----------------------------------------------"/>
<echo message=" Component: testing ${ivy.module} "/>
<echo message="----------------------------------------------"/>
<junit printsummary="yes" fork="on" failureProperty="test.failed" errorProperty="test.failed" outputtoformatters="false">
<sysproperty key="pulse.root" value="${project.root.dir}"/>
<classpath>
<pathelement location="${classes.dir}"/>
<pathelement location="${test.classes.dir}"/>
<path refid="lib.path"/>
</classpath>
<formatter type="xml"/>
<batchtest todir="${report.dir}/junit/xml">
<path refid="test.run.selection"/> <!-- TODO: replace with ${ivy.module}.test.selection -->
</batchtest>
</junit>
<!-- generate the junit html report. -->
<junitreport todir="${report.dir}/junit">
<fileset dir="${report.dir}/junit/xml">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="${report.dir}/junit/html"/>
</junitreport>
<fail if="test.failed" message="One or more tests failed. See the reports (${report.dir}) for details."/>
</target>
<!-- package artifacts -->
<target name="package" depends="init, module-pre-package, common-package, module-post-package"/>
<target name="module-pre-package" unless="skip.package"/>
<target name="module-post-package" unless="skip.package"/>
<target name="common-package" unless="skip.package">
<echo message="----------------------------------------------"/>
<echo message=" Component: package ${ivy.module} "/>
<echo message="----------------------------------------------"/>
<!--
Bundles and normal pulse components are jared slightly differently. Bundles
contain extracted 3rd party jars and use custom manifests, whilst pulse components
do not.
-->
<if>
<isset property="${ivy.module}.bundle"/>
<then>
<property name="3rd.party.extracted" value="${current.dir}/build/3rdparty/extracted"/>
<property name="3rd.party.jars" value="${current.dir}/build/3rdparty/jars"/>
<prepare.3rdparty extracted="${3rd.party.extracted}" jars="${3rd.party.jars}"/>
<jar file="build/${ivy.module}.jar" manifest="resources/META-INF/MANIFEST.MF">
<fileset dir="${classes.dir}">
<patternset refid="release.excludes"/>
</fileset>
<fileset dir="resources" excludes="resources/META-INF/MANIFEST.MF"/>
<fileset dir="${3rd.party.extracted}">
<exclude name="META-INF/**"/>
</fileset>
<!-- include license text files. -->
<fileset dir="${3rd.party.jars}">
<exclude name="*.jar"/>
</fileset>
</jar>
</then>
</if>
<if>
<not><isset property="${ivy.module}.bundle"/></not>
<then>
<jar file="build/${ivy.module}.jar" basedir="${classes.dir}">
<patternset refid="release.excludes"/>
</jar>
</then>
</if>
<if>
<not><isset property="no.src"/></not>
<then>
<package-src name="${ivy.module}-src.jar" pathref="src.export.selection"/>
</then>
</if>
<if>
<not><isset property="no.tests"/></not>
<then>
<jar file="build/${ivy.module}-test.jar" basedir="${test.classes.dir}">
<patternset refid="release.excludes"/>
</jar>
<package-src name="${ivy.module}-test-src.jar" pathref="test.export.selection"/>
</then>
</if>
</target>
<!-- publish the artifacts to the defined repository. -->
<target name="publish" depends="init, module-pre-publish, common-publish, module-post-publish"/>
<target name="module-pre-publish" unless="skip.publish"/>
<target name="module-post-publish" unless="skip.publish"/>
<target name="common-publish" unless="skip.publish">
<dirname property="current.dir" file="ivy.xml"/>
<!-- copy built artifacts to the build/repository -->
<ivy:publish resolver="build" artifactspattern="${current.dir}/build/[artifact].[ext]"/>
</target>
<target name="dist" depends="init, module-pre-dist, common-dist, module-post-dist"/>
<target name="module-pre-dist"/>
<target name="module-post-dist"/>
<target name="common-dist">
<dirname property="current.dir" file="ivy.xml"/>
<ivy:resolve file="ivy.xml" conf="${distconf}"/>
<ivy:publish resolver="private" artifactspattern="${current.dir}/build/[artifact].[ext]" conf="${distconf}"/>
</target>
<!-- build this module and its dependencies. -->
<target name="build.module" depends="clean, prepare, build, test, package, publish"/>
<target name="extract.prepackaged" depends="init" if="${ivy.module}.bundle"
description="Copy and extract the third party packages for the bundle into the plugin/prepackages/<pluginId> directory.">
<property name="3rd.party.extracted" value="${current.dir}/build/3rdparty/extracted"/>
<property name="3rd.party.jars" value="${current.dir}/build/3rdparty/jars"/>
<prepare.3rdparty extracted="${3rd.party.extracted}" jars="${3rd.party.jars}"/>
<copy todir="${project.root.dir}/plugins/prepackaged/${ivy.module}">
<fileset dir="${3rd.party.extracted}">
<exclude name="META-INF/**"/>
</fileset>
<!-- include license text files. -->
<fileset dir="${3rd.party.jars}">
<exclude name="*.jar"/>
</fileset>
</copy>
</target>
<macrodef name="package-src">
<attribute name="pathref"/>
<attribute name="name"/>
<sequential>
<delete dir="${build.tmp.dir}"/>
<mkdir dir="${build.tmp.dir}"/>
<copy todir="${build.tmp.dir}" overwrite="true">
<path refid="@{pathref}"/>
</copy>
<copyright src="${build.tmp.dir}" value="${copyright.statement}">
<include name="**/*.java"/>
</copyright>
<jar file="build/@{name}">
<fileset dir="${build.tmp.dir}"/>
</jar>
<delete dir="${build.tmp.dir}"/>
</sequential>
</macrodef>
<macrodef name="prepare.3rdparty">
<attribute name="extracted"/>
<attribute name="jars"/>
<sequential>
<mkdir dir="@{extracted}"/>
<mkdir dir="@{jars}"/>
<retrieve-dependencies dest="@{jars}" conf="bundled_3rd_party"/>
<unzip dest="@{extracted}">
<fileset dir="@{jars}">
<include name="*.jar"/>
</fileset>
</unzip>
</sequential>
</macrodef>
</project>