d210ff5ca3be533c87b7e58407231f383fc1f76b
[utils] / build / trailer.xml
1 <!-- PROPERTIES -->
2
3
4 <!-- Default entry point for the build -->
5 <target name="all" depends="clean, init, compile, jar" />
6
7 <target name="startup" depends="init_directory_properties">
8   <property name="module.classpath_id" value="module.build.path" />
9   <property name="module.classpath" refid="${module.classpath_id}" />
10   
11   <path id="module.build.path">
12     <fileset dir="${external.lib.dir}">
13       <include name="**/*.jar"/>
14     </fileset>
15   </path>
16   
17   <path id="module.testbuild.path">
18     <fileset dir="${test.lib.dir}">
19       <include name="**/*.jar"/>
20     </fileset>
21   </path>
22
23 </target>
24
25 <target name="init" depends="import_header,startup">
26         <tstamp />
27 </target>
28
29 <!-- ============================================================================
30         Cleanup 
31         ============================================================================ -->
32
33 <target name="ant.deps">
34 </target>
35
36 <target name="deps" depends="import_header">
37   <antcall target="module.build.deps">
38     <param name="download.dir" value="${external.lib.dir}"/>
39   </antcall>
40   <antcall target="test.d">
41     <param name="download.dir" value="${test.lib.dir}"/>
42   </antcall>
43   <antcall target="ant.d">
44     <param name="download.dir" value="${ant.downloaded.lib.dir}"/>
45   </antcall>
46   <antcall target="module.test.deps">
47     <param name="download.dir" value="${test.lib.dir}"/>
48   </antcall>
49 </target>
50
51 <target name="clean" depends="init_directory_properties,base-test-clean">
52         <delete dir="${module.classes.dir}" />
53         <delete dir="${module.testclasses.dir}" />
54         <delete dir="${module.testoutput.dir}" />
55         <delete dir="${module.jars.dir}" />
56         <delete dir="${module.docbase.dir}" />
57         <delete dir="${module.report.dir}" />
58         <delete dir="${module.sql.dir}" />
59         <delete dir="${module.build.dir}"/>
60 </target>
61
62 <target name="clean-deps" depends="init_directory_properties">
63   <delete>
64     <fileset dir="${external.lib.dir}" includes="*"/>
65   </delete>
66   <delete>
67     <fileset dir="${test.lib.dir}" includes="*"/>
68   </delete>
69   <delete>
70     <fileset dir="${ant.downloaded.lib.dir}" includes="*"/>
71   </delete>
72 </target>
73
74 <!-- ============================================================================
75         Compilation of java code. 
76         ============================================================================ -->
77
78 <!--  Compilation of java code, requires a srcdirs variable to be
79       set to a path of one of more directories separated by : or ;
80 -->
81 <target name="compile-impl" depends="init">
82         <mkdir dir="${module.classes.dir}" />
83         <echo level="info" message="compile ${module.name}, source dirs ${srcdirs}" />
84         <javac srcdir="${srcdirs}" source="${javac.source}"
85                 destdir="${module.classes.dir}" classpath="${module.classpath}"
86                 debug="${javac.debug}" debuglevel="${javac.debug.level}" />
87         <copy todir="${module.classes.dir}">
88                 <fileset dir="${module.source.dir}" excludes="**/*.java" />
89         </copy>
90 </target>
91
92 <!--  Compilation of regular source code --> 
93 <target name="compile-src" unless="ejbsource.available" depends="init">
94     <antcall target="compile-impl">
95         <param name="srcdirs" value="${module.source.dir}"/>
96     </antcall>
97 </target>
98
99 <!--  Compilation of regular source code and generated source code
100       for EJBs -->
101 <target name="compile-src-ejb" if="ejbsource.available" depends="init">
102     <antcall target="compile-impl">
103         <param name="srcdirs" value="${module.source.dir}:${module.ejbsource.dir}"/>
104     </antcall>
105 </target>
106
107 <target name="compile" depends="init">
108     <available file="${module.ejbsource.dir}" type="dir" property="ejbsource.available"/>
109     <antcall target="compile-src"/>
110     <antcall target="compile-src-ejb"/>
111 </target>
112
113 <!-- ============================================================================
114         Generating a jar file. 
115         ============================================================================ -->
116
117 <target name="jar" depends="compile">
118         <mkdir dir="${module.jars.dir}" />
119         <echo level="info" message="jar cdmvbase ${module.name}" />
120         <!-- Hack: how to remove the schemas directory from the jar when it does not exist -->
121         <mkdir dir="${xmlschemas.dir}" />
122         <jar jarfile="${module.jars.dir}/${module.jar.name}"
123                 compress="${jarcompress}">
124                 <fileset dir="${module.classes.dir}" />
125                 <fileset dir="${xmlschemas.dir}" />
126         </jar>
127 </target>
128
129
130 <!-- ============================================================================
131         Generate javadoc.
132         ============================================================================ -->
133
134 <target name="javadoc" depends="init">
135         <!-- create javadocs -->
136         <javadoc packagenames="*" destdir="${module.javadoc.dir}"
137                 author="true" version="true" use="true" private="yes"
138                 windowtitle="Dragon documentation" source="${javac.source}"
139                 sourcepath="${module.source.dir}"
140                 classpath="${module.classpath}">
141                 <arg value="-docfilessubdirs"/>
142                 <arg value="-overview"/>
143                 <arg value="${module.source.dir}/overview.html"/>
144         </javadoc>
145 </target>
146
147 <target name="testjavadoc" depends="testclasses">
148         <!-- create javadocs -->
149         <javadoc packagenames="*" destdir="${module.testjavadoc.dir}"
150                 author="true" version="true" use="true" private="yes"
151                 windowtitle="Dragon test documentation" source="${javac.source}"
152                 sourcepath="${module.test.dir}"
153                 classpathref="test.classpath">
154         </javadoc>
155 </target>
156
157 <!-- ============================================================================
158         Generate javadoc in pdf format
159         ============================================================================ -->
160
161 <target name="pdfdoc" depends="init">
162         <!-- create javadocs -->
163         <mkdir dir="${module.pdfdoc.dir}" />
164         <javadoc packagenames="*" author="true" version="true" private="yes"
165                 source="${javac.source}" doclet="com.tarsec.javadoc.pdfdoclet.PDFDoclet"
166                 docletpathref="pdfdoclet.path"
167                 classpath="${module.classpath}"
168                 sourcepath="${module.source.dir}"
169                 additionalparam="-pdf ${module.pdfdoc.dir}/${module.name}.pdf">
170                 <!-- fileset dir="${module.source.dir}">
171                         <include name="**/*.java" />
172                 </fileset -->
173         </javadoc>
174         <echo
175                 message="Unfortuantely, this target will have generated some errors but the pdf will still look fine" />
176         <echo>Result is available in ${module.pdfdoc.dir}"</echo>
177 </target>
178
179 <!-- ============================================================================
180         Check javadoc
181         ============================================================================ -->
182
183 <target name="doccheck" depends="init">
184         <mkdir dir="${module.doccheck.dir}" />
185         <javadoc packagenames="*" destdir="${module.doccheck.dir}"
186                 author="true" version="true"
187                 doclet="com.sun.tools.doclets.doccheck.DocCheck"
188                 docletpathref="doccheck.path" 
189                 classpath="${module.classpath}"
190                 sourcepath="${module.source.dir}">
191         </javadoc>
192         <echo>Results are available in ${module.doccheck.dir}"</echo>
193 </target>
194
195 <!-- ============================================================================
196         Copy build results to a standard location. 
197         ============================================================================ -->
198         
199 <target name="clean-dist" depends="clean">
200   <delete>
201     <fileset dir="${module.dist.dir}" includes="**"/>
202   </delete> 
203 </target>
204         
205 <target name="dist-lite-product" depends="deps,jar">
206     <mkdir dir="${module.dist.dir}"/>
207         <delete>
208                 <fileset dir="${module.dist.dir}" excludes="**/CVS" />
209         </delete>
210         <copy todir="${module.dist.dir}" flatten="yes">
211                 <fileset dir="${module.build.dir}">
212                         <include name="**/*.jar" />
213                 </fileset>
214                 <fileset dir="${module.build.dir}">
215                         <include name="**/*.pdf" />
216                 </fileset>
217         </copy>
218         <if>
219           <isset property="webroot.dir"/>
220           <then>
221             <jar destfile="${module.dist.dir}/${module.name}.war"
222                      basedir="${webroot.dir}"/>
223           </then>
224         </if>
225 </target>
226
227 <target name="dist-lite-test" depends="deps,testclasses">
228     <jar destfile="${module.dist.dir}/${module.testjar.name}"
229                 basedir="${module.testclasses.dir}" 
230                 includes="**/*.class"/>
231     <jar destfile="${module.dist.dir}/${module.testresourcesjar.name}"
232                 basedir="${module.testresource.dir}" />
233 </target>
234
235 <target name="dist-lite" depends="clean,dist-lite-product,dist-lite-test">
236   <if> 
237     <isset property="post-dist-lite"/>
238         <then> 
239           <antcall target="post-dist-lite"/>
240         </then>
241   </if>
242 </target>
243
244 <target name="dist-javadoc" depends="javadoc,pdfdoc,testjavadoc">
245     <jar destfile="${module.dist.dir}/${module.javadocjar.name}"
246                 basedir="${module.javadoc.dir}" />
247         <jar destfile="${module.dist.dir}/${module.testjavadocjar.name}"
248                 basedir="${module.testjavadoc.dir}" />          
249         <copy todir="${module.api.forrest.dir}">
250                 <fileset dir="${module.javadoc.dir}" />
251         </copy>                         
252 </target>
253
254 <target name="dist"
255         depends="dist-lite,dist-javadoc"
256         description="copying compiled sources to dist location and copy documentation to forrest site">
257         <echo
258                 message="Copying build results for ${module.name} to a location where other modules can find it." />
259 </target>
260
261 <!-- ============================================================================
262         Check style, 
263         ============================================================================ -->
264
265 <target name="checkstyle-impl">
266    <checkstyle config="${build.dir}/${checkstyle.rules}"
267                 failOnViolation="false">
268                 <classpath>
269                   <pathelement path="${checkstyle.classpath}"/>
270                 </classpath>
271                 <fileset dir="${checkstyle.srcdir}" includes="**/*.java"/>
272                 <formatter type="xml" tofile="${module.checkstyle.dir}/${checkstyle.report}.xml"/>
273         </checkstyle>
274         <style style="${build.dir}/checkstyle-simple.xsl"
275                    in="${module.checkstyle.dir}/${checkstyle.report}.xml"
276                    out="${module.checkstyle.dir}/${checkstyle.report}.html"/>
277         <echo>Results are available at ${module.checkstyle.dir}/${checkstyle.report}.html</echo>
278 </target>
279
280 <target name="checkstyle" depends="testclasses">
281     <mkdir dir="${module.checkstyle.dir}"/>
282         <antcall target="checkstyle-impl">
283           <param name="checkstyle.classpath" refid="module.build.path"/>
284           <param name="checkstyle.srcdir" value="${module.source.dir}"/>
285           <param name="checkstyle.report" value="source-results"/>
286         </antcall>
287         <antcall target="checkstyle-impl">
288           <param name="checkstyle.classpath" refid="module.testbuild.path"/>
289           <param name="checkstyle.srcdir" value="${module.test.dir}"/>
290           <param name="checkstyle.report" value="test-results"/>
291         </antcall>
292 </target>
293
294 <!-- ============================================================================
295         Formatting source code.  
296         ============================================================================ -->
297 <target name="format" depends="init">
298         <jalopy loglevel="INFO" classpathref="module.testbuild.path"
299                 convention="${jalopy.rules}">
300                 <fileset dir="${module.source.dir}">
301                         <include name="**/*.java" />
302                 </fileset>
303                 <fileset dir="${module.test.dir}">
304                         <include name="**/*.java" />
305                 </fileset>
306         </jalopy>
307 </target>
308
309 <!-- =========================================================================
310         Check redundancy in the code
311         ========================================================================= -->
312 <target name="simian" depends="init">
313         <simian threshold="7">
314                 <fileset dir="${module.source.dir}" includes="**/*.java" />
315         </simian>
316 </target>
317
318
319 <!-- =========================================================================
320         Check dependencies using macker.
321         ========================================================================= -->
322 <property name="macker.file" value="macker.xml" />
323 <target name="macker" depends="compile">
324         <available file="${macker.file}" property="macker.file.found" />
325         <fail message="Macker source file ${macker.file} was not found."
326                 unless="macker.file.found" />
327         <macker>
328                 <rules dir="." includes="macker.xml" />
329                 <classes dir="${module.classes.dir}">
330                         <include name="**/*.class" />
331                 </classes>
332                 <classpath>
333                     <pathelement path="${module.classes.dir}" />
334                         <path refid="module.build.path" />
335                 </classpath>
336         </macker>
337 </target>
338
339
340 <!-- ===========================================================================
341         JUnit tests.
342         =========================================================================== -->
343
344 <target name="testclasses" depends="compile">
345         <mkdir dir="${module.test.dir}" />
346         <mkdir dir="${module.testresource.dir}" />
347         <mkdir dir="${module.testclasses.dir}" />
348                 <path id="test.classpath">
349                 <pathelement path="${module.classes.dir}" />
350                 <pathelement path="${module.test.dir}" />
351                 <path refid="module.testbuild.path" />
352                 <path refid="module.build.path" />
353         </path>
354         <javac srcdir="${module.test.dir}"
355                 destdir="${module.testclasses.dir}" 
356                 debug="${javac.debug}" debuglevel="${javac.debug.level}" compiler="modern"
357                 source="${javac.source}" failonerror="yes">
358                 <classpath>
359                     <path refid="test.classpath"/>
360                 </classpath>
361         </javac>
362         <copy todir="${module.testclasses.dir}">
363                 <fileset dir="${module.test.dir}" excludes="**/*.java" />
364                 <fileset dir="${module.testresource.dir}" />
365         </copy>
366 </target>
367
368 <!-- test-base is a target mean to be used by other targets. 
369         It expects one parameter names 'testedclasses' to indicate the directory
370         where the compiled test classes reside. 
371 -->
372
373 <target name="base-test-clean">
374   <delete file="coverage.ec"/>
375   <delete file="coverage.em"/>
376 </target>
377
378
379 <target name="base-test-impl" depends="testclasses">
380         <mkdir dir="${module.report.dir}" />
381         <antcall target="emma"/>
382         <junit haltonfailure="${junit.halt.on.failure}" printsummary="on" dir="." fork="yes" showoutput="yes">
383                 <batchtest todir="${module.report.dir}">
384                         <fileset dir="${module.testclasses.dir}">
385                                 <include name="${testclassnames}" />
386                                 <!--  exclude inner classes --> 
387                                 <exclude name="**/*$$*.class"/>
388                         </fileset>
389                 </batchtest>
390                 <formatter type="xml" />
391                 <classpath>
392                         <path refid="xmlschemas.path" />
393                         <pathelement path="${module.testclasses.dir}" />
394                         <pathelement path="${testedclasses}" />
395                         <pathelement path="${testlibrary}" />
396                         <pathelement path="${module.classes.dir}" />
397                         <pathelement path="${log4j.properties.dir}" /><!--  for log4j.properties -->
398                         <!-- the test resource directory is added to the path as well to make it
399                                 easy to access resources from tests -->
400                         <pathelement path="${module.testresource.dir}" />
401                         <path refid="module.testbuild.path" />
402                         <path refid="module.build.path" />
403                 </classpath>
404         </junit>
405 </target>
406
407 <target name="base-test-allclasses" unless="test">
408         <echo>Testing all classes</echo>
409         <antcall target="base-test-impl">
410                 <param name="testclassnames" value="**/*Test.class" />
411         </antcall>
412 </target>
413
414 <target name="base-test-singleclass" if="test">
415         <echo>Testing testcases that conform to the pattern *${test}*</echo>
416         <antcall target="base-test-impl">
417                 <param name="testclassnames" value="**/*${test}*.class" />
418         </antcall>
419 </target>
420
421 <target name="base-test">
422         <antcall target="base-test-allclasses" />
423         <antcall target="base-test-singleclass" />
424 </target>
425
426 <!-- Run junit test -->
427
428 <target name="test">
429         <antcall target="base-test">
430                 <param name="testedclasses" value="${module.classes.dir}" />
431         </antcall>
432 </target>
433
434 <!-- reporting target used by other targets. This should not depend on 
435         the test target to avoid unnecessary duplicate runs of the tests -->
436
437 <target name="base-reports" depends="init">
438         <mkdir dir="${module.report.dir}/html" />
439         <mkdir dir="${module.report.dir}/html/unit" />
440         <junitreport todir="${module.report.dir}" tofile="${unitreport}">
441                 <fileset dir="${module.report.dir}">
442                         <include name="TEST-*.xml" />
443                 </fileset>
444                 <report todir="${module.report.dir}/html/unit" />
445         </junitreport>
446 </target>
447
448 <!-- Run junit tests with HTML reporting -->
449
450 <target name="junit-reports" depends="test">
451         <antcall target="base-reports" />
452         <antcall target="emma-reports" />
453 </target>
454
455 <target name="reports">
456   <antcall target="junit-reports">
457     <param name="emma.enabled" value="true"/>
458   </antcall>
459 </target>
460
461  <!-- Instrument classes using emma --> 
462   
463   <target name="emma" depends="init_directory_properties">
464     <emma enabled="${emma.enabled}">
465       <instr instrpath="${module.classes.dir}" mode="overwrite"/>
466     </emma>
467   </target>
468   
469   <target name="emma-reports" depends="init_directory_properties" if="emma.enabled">
470     <mkdir dir="${module.emmareport.dir}"/>
471     <emma enabled="${emma.enabled}" >
472       <report sourcepath="${module.source.dir}">
473         <!-- collect all EMMA data dumps (metadata and runtime): -->
474         <infileset dir="." includes="*.em, *.ec" />
475
476         <txt outfile="${module.emmareport.dir}/report.txt"/>
477         <html outfile="${module.emmareport.dir}/index.html"/>
478         <!-- sourcepath>
479           <dirset dir="${src}" >
480             <include name="." /> 
481           </dirset>
482         </sourcepath -->
483       </report>
484     </emma>
485   </target>
486
487 <!-- =======================================================================
488    FORREST
489    ======================================================================-->
490   <target name="forrest" description="runs Forrest">
491     <property name="forrest.home" location="${env.FORREST_HOME}" />
492     <property name="forrest.ant.home" location="${forrest.home}/tools/ant" />
493     <java classname="org.apache.tools.ant.Main" fork="true" failonerror="true" maxmemory="128M">
494       <classpath>
495         <fileset dir="${forrest.ant.home}/lib">
496           <include name="*.jar" />
497         </fileset>
498         <pathelement path="${java.home}/../lib/tools.jar" />
499       </classpath>
500       <sysproperty key="ant.home" value="${forrest.ant.home}" />
501       <sysproperty key="forrest.home" value="${forrest.home}" />
502       <sysproperty key="basedir" value="${basedir}" />
503       <sysproperty key="java.endorsed.dirs" value="${forrest.home}/lib/endorsed" />
504       <arg line="-f ${forrest.home}/main/forrest.build.xml" />
505     </java>
506   </target> 
507
508 <!--  ============================================================================
509       Database targets
510       ============================================================================ -->
511            
512 <!--  Runs a main program found in the test source tree. 
513       Properties:
514          - my.test.program: class name of the program to run 
515          - my.args: arguments to be passed to the program --> 
516 <target name="runTestProgram" depends="testclasses">
517         <java classname="${my.test.program}">
518             <arg line="${my.args}"/>
519                 <classpath>
520                         <path refid="xmlschemas.path" />
521                         <path refid="junit.path" />
522                         <pathelement path="${module.testclasses.dir}" />
523                         <pathelement path="${testedclasses}" />
524                         <pathelement path="${testlibrary}" />
525                         <pathelement path="${module.classes.dir}" />
526                         <pathelement path="${log4j.properties.dir}" /><!--  for log4j.properties -->
527                         <!-- the test resource directory is added to the path as well to make it
528                                 easy to access resources from tests -->
529                         <pathelement path="${module.testresource.dir}" />
530                         <path refid="module.testbuild.path" />
531                         <path refid="module.build.path" />
532                 </classpath>
533         </java>
534 </target>
535
536 <property name="database.starter" 
537           value="org.wamblee.persistence.test.DatabaseStarter"/>
538 <target name="startdb">
539     <echo>After the database has started, you must populate the database in some way.
540           For instance, using the schemaupdate ant target</echo>
541     <antcall target="runTestProgram">
542         <param name="my.test.program" value="${database.starter}"/>
543         <param name="my.args" value=""/>
544     </antcall>
545 </target>
546
547 <property name="schemaupdater" 
548           value="org.wamblee.test.HibernateUtils"/>
549 <target name="schemaupdate">
550     <antcall target="runTestProgram">
551         <param name="my.test.program" value="${schemaupdater}"/>
552         <param name="my.args" value="${hibernate.filelist}"/>
553     </antcall>
554 </target>
555
556 <target name="schemaexport" depends="init">
557     <mkdir dir="${module.sql.dir}" />
558     <echo>Generating schema in output file ${module.sql.dir}/hibernate.sql</echo>
559     <antcall target="runTestProgram">
560         <param name="my.test.program" value="${schemaupdater}"/>
561         <param name="my.args" value="-export ${module.sql.dir}/hibernate.sql ${hibernate.filelist}"/>
562     </antcall>
563 </target>
564
565 <!-- INCLUDED MARKER -->
566 <property name="build_trailer_included" value="true" />
567
568