root/trunk/build/buildTools/deftasks.xml

Revision 3254 (checked in by douglm, 2 years ago)

Add a javadoc ant macro

Line 
1 <!-- Define a number of tasks and macros
2      deftasks:  define someuseful build tasks
3      projectDefs: standard project definitions
4      xMsg: x=info,debug etc. For message output
5
6      Authors: Mike Douglass   douglm rpi.edu
7 -->
8
9 <project name="do.deftasks" basedir="." default="">
10   <macrodef name="deftasks">
11     <sequential>
12       <path id="build.cp">
13         <fileset dir="${build.dir}">
14           <include name="*.jar"/>
15         </fileset>
16       </path>
17  
18       <taskdef name="forEachApp"
19                classname="org.bedework.deployment.ForEachAppTask">
20         <classpath refid="build.cp"/>
21       </taskdef>
22      
23       <taskdef name="forApp"
24                classname="org.bedework.deployment.ForAppTask">
25         <classpath refid="build.cp"/>
26       </taskdef>
27
28       <taskdef name="resolveFile"
29                classname="org.bedework.deployment.ResolveFile">
30         <classpath refid="build.cp"/>
31       </taskdef>
32
33       <taskdef name="makeLangXsl"
34                classname="org.bedework.deployment.MakeLangXsl">
35         <classpath refid="build.cp"/>
36       </taskdef>
37
38       <taskdef name="applicationXml"
39                classname="org.bedework.deployment.ApplicationXmlTask">
40         <classpath refid="build.cp"/>
41       </taskdef>
42     </sequential>
43   </macrodef>
44  
45   <macrodef name="projectDefs">
46     <attribute name="name"/>
47     <attribute name="version"/>
48     <attribute name="deployment-name" default=""/>
49     <attribute name="subproject" default="false"/>
50     <sequential>
51       <property name="project.name" value="@{name}"/>
52      
53       <property name="project.version" value="@{version}"/>
54      
55       <property name="dist.home" location="${project.home}/dist"/>
56       <mkdir dir="${dist.home}" />
57
58       <property name="lib.dir" location="${project.home}/lib"/>
59
60       <property name="build.dir" location="${bedework.home}/build"/>
61
62       <property name="buildjar" location="${build.dir}/buildTools/buildjar.xml"/>
63       <property name="buildwar" location="${build.dir}/buildwar.xml"/>
64       <property name="buildsh" location="${build.dir}/buildsh.xml"/>
65
66       <property name="resources.dir" location="${project.home}/resources"/>
67
68       <property name="org.bedework.libcache.dir"
69                 location="${bedework.home}/libcache"/>
70      
71       <property name="org.bedework.temp.dir"
72                 location="${dist.home}/temp" />
73
74       <if>
75         <istrue value="@{subproject}" />
76         <then>
77           <property name="source.home" location="${project.home}/src"/>
78         </then>
79         <else>
80           <delete dir="${org.bedework.temp.dir}" />
81           <mkdir dir="${org.bedework.temp.dir}" />
82          
83           <property name="org.bedework.deployment.name"
84                     value="@{deployment-name}" />
85
86           <deftasks/>
87         </else>
88       </if>
89
90       <import file="${build.dir}/buildTools/getJar.xml"/>
91       <import file="${build.dir}/buildTools/jdoc.xml"/>
92     </sequential>
93   </macrodef>
94
95   <!-- =====================================================================
96        Assumes projectDefs was called previously.
97        ===================================================================== -->
98   <macrodef name="projectInit">
99     <sequential>
100       <infoMsg message="* =========== Building ${project.name}" />
101      
102       <delete dir="${lib.dir}" />
103       <mkdir dir="${lib.dir}" />
104
105       <property name="test.data.dir"
106                 location="${dist.home}/test-data" />
107
108       <property name="test.reports.dir"
109                 location="${dist.home}/test-reports" />
110
111       <property name="org.bedework.empty.dir"
112                 location="${dist.home}/empty-dir" />
113       <mkdir dir="${org.bedework.empty.dir}" />
114
115       <fileset id="empty.fileset" dir="${org.bedework.empty.dir}"
116                excludes="*" />
117
118       <!-- ==================== Compilation Classpath ==================== -->
119
120       <path id="compile.classpath">
121         <fileset dir="${lib.dir}">
122            <include name="*.jar"/>
123         </fileset>
124         <fileset dir="${dist.home}">
125            <include name="*.jar"/>
126         </fileset>
127       </path>
128     </sequential>
129   </macrodef>
130
131   <!-- =====================================================================
132        Assumes projectDefs was called previously.
133        Set things up ready for deployment
134        ===================================================================== -->
135   <macrodef name="deployInit">
136     <attribute name="ear-name"/>
137     <sequential>
138       <!-- Where we put ear stuff -->
139       <if>
140         <isset property="org.bedework.global.build.ear" />
141         <then>
142           <property name="app.ear.file.name"
143                     value="@{ear-name}.ear" />
144
145           <property name="org.bedework.ear.name"
146                     value="@{ear-name}" />
147
148           <property name="org.bedework.ear.templib"
149                     location="${org.bedework.temp.dir}/earlib" />
150
151           <property name="org.bedework.ear.properties.dir"
152                     location="${org.bedework.temp.dir}/ear-properties" />
153
154           <delete dir="${org.bedework.ear.templib}" />
155           <mkdir dir="${org.bedework.ear.templib}" />
156
157           <delete dir="${org.bedework.ear.properties.dir}" />
158           <mkdir dir="${org.bedework.ear.properties.dir}" />
159         </then>
160       </if>
161      
162       <property name="org.bedework.temp.shellscr.home"
163                 location="${org.bedework.temp.dir}/shellscr" />
164
165       <property name="org.bedework.temp.extrajars.dir"
166                 location="${org.bedework.temp.dir}/extrajars" />
167
168       <!-- Preserve extra jars for ear builds -->
169       <property name="org.bedework.temp.ear.extrajars.dir"
170                 location="${org.bedework.temp.dir}/earextrajars" />
171      
172       <property name="org.bedework.global.context.roots"
173                 location="${org.bedework.temp.dir}/context-roots.properties" />
174
175       <!-- ===== End of stuff in main bedework deployment build file ======   -->
176      
177       <!-- Clean up before we start -->
178       <if>
179         <isset property="org.bedework.temp.wars.home" />
180         <then>   
181           <delete dir="${org.bedework.temp.wars.home}" />
182           <mkdir dir="${org.bedework.temp.wars.home}" />
183         </then>
184       </if>
185
186       <delete dir="${org.bedework.temp.ear.extrajars.dir}" />
187       <mkdir dir="${org.bedework.temp.ear.extrajars.dir}" />
188
189       <delete dir="${org.bedework.temp.extrajars.dir}" />
190       <mkdir dir="${org.bedework.temp.extrajars.dir}" />
191     </sequential>
192   </macrodef>
193  
194   <macrodef name="deployTerm">
195     <sequential>
196       <ant antfile="${build.dir}/../deployment/termination/webapp/build.xml"
197            target="deploy" inheritRefs="true" />
198      
199       <!-- Platform specific -->
200       <ant antfile="${build.dir}/../deployment/termination/build.xml"
201            target="deploy" inheritRefs="true" />
202     </sequential>
203   </macrodef>
204  
205   <!-- Standard targets for build files. Two targets need to be overridden by
206        the importing task
207        
208        init - carry out project specific initialisation
209        build-source - builds the source to creat ejars.
210     -->
211  
212   <!-- Override this -->
213   <target name="init" />
214  
215   <!-- Override this -->
216   <target name="build-init" />
217
218   <!-- Override this -->
219   <target name="build-source" />
220
221   <!-- =================================================================
222        Clean out all library files from other projects and all generated
223        files in preparation for a complete rebuild.
224
225        Needed because switching versions leaves a load of old bedework
226        generated stuff in the libraries.
227        ================================================================= -->
228   <target name="deep-clean" depends="clean">
229     <delete dir="${lib.dir}" />
230   </target>
231
232   <!-- =================================================================
233        Clean all generated files
234        ================================================================= -->
235   <target name="clean">
236     <delete dir="${dist.home}" />
237   </target>
238
239   <!-- =================================================================
240        Clean up after a build.
241        ================================================================= -->
242   <target name="cleanup">
243     <!--
244     <delete dir="${org.bedework.empty.dir}" />
245     -->
246   </target>
247
248   <!-- ========================== Base build Targets ===================
249        Here we have one target building the classes and interfaces that make
250        up the access control suite.
251        ================================================================= -->
252
253   <target name="clean-build" depends="clean,build"
254           description="Clean and compile access control classes"/>
255
256   <target name="clean-build-all" depends="clean,build-all"
257           description="Clean and compile access control classes"/>
258
259   <target name="build" depends="init,build-source,cleanup"
260           description="Compile access control classes"/>
261
262   <target name="build-all" depends="build"
263           description="Compile access control classes"/>
264  
265   <target name="javadoc" depends="build-init"
266           description="Create Javadoc API documentation">
267     <jdoc/>
268   </target>
269  
270   <macrodef name="build-jar-stats">
271     <sequential>
272       <if>
273         <not>
274           <isset property="org.bedework.jars.built" />
275         </not>
276         <then>
277           <echo message="No jars were checked or built" />
278         </then>
279         <else>
280           <echo message="${org.bedework.jars.checked} jars checked: ${org.bedework.jars.built} built" />
281         </else>
282       </if>
283     </sequential>
284   </macrodef>
285  
286   <!-- This macro builds a single jar file. It just sets defaults for the java
287        compiler then invokes it.
288
289        This is the only place we compile files.
290
291        On entry we require:
292          jar.file              Fully specified name of destination jar file.
293          base.java.sources     Defines the java source files
294          base.class.patternset Defines the java class files
295          base.resource.files   Defines extra resources to go in the jar
296
297        We will copy all files defined by base.java.patternset to a temporary
298        location and compile out of that into a temporary classes location.
299
300        We do that to avoid a problematic feature of the java compilers, the
301        tendency to recompile any referenced sources found on the source path.
302
303        So, if we have all our sources under the directory "src" and compile a
304        single package in that tree, all referenced classes will be compiled,
305        even if they exist in a jar file on the class path.
306
307        The other side-effect is that we might compile and include classes we
308        didn't realise we were compiling.
309
310        The downside is that we need to be very specific about the classes we
311        compile for a package and we might need to put classes in
312        base.java.sources which we don't want in the final jar file.
313
314        On exit we will have created classes in the directory
315           ${jar.temp.classes}
316        and a jar file
317           ${build.jar.file}
318
319        Authors: Mike Douglass   douglm rpi.edu
320   -->
321   <macrodef name="build-jar">
322     <attribute name="module-base"/>
323     <attribute name="jar-file"/>
324     <attribute name="jar-dependency" default=""/>
325     <attribute name="generated-sources" default=""/>
326     <attribute name="property-resources" default=""/>
327    
328     <sequential>
329       <if>
330         <not>
331           <isset property="org.bedework.jars.built" />
332         </not>
333         <then>
334           <var name="org.bedework.jars.built" value="0" />
335           <var name="org.bedework.jars.checked" value="0" />
336         </then>
337       </if>
338      
339       <math result="org.bedework.jars.checked"
340             operand1="${org.bedework.jars.checked}"
341             operation="+" operand2="1" datatype="int"/>
342
343       <if>
344         <equals arg1="@{generated-sources}" arg2="" />
345         <then>
346           <fileset id="buildjar.generated.java.sources" refid="empty.fileset" />
347         </then>
348         <else>
349           <fileset id="buildjar.generated.java.sources" dir="@{generated-sources}" >
350             <include name="org/bedework/**/*.java"/>
351           </fileset>
352         </else>
353       </if>
354
355       <if>
356         <equals arg1="@{property-resources}" arg2="" />
357         <then>
358           <fileset id="buildjar.resource.files" refid="empty.fileset" />
359         </then>
360         <else>
361           <fileset id="buildjar.resource.files" dir="@{property-resources}" >
362             <include name="**/*.properties"/>
363           </fileset>
364         </else>
365       </if>
366
367       <fileset id="buildjar.java.sources" dir="@{module-base}/src" >
368         <include name="**/*.java"/>
369       </fileset>
370
371       <patternset id="base.class.patternset">
372         <include name="**/*.class"/>
373       </patternset>
374
375       <if>
376         <not>
377           <equals arg1="@{jar-dependency}" arg2="" />
378         </not>
379         <then>
380           <var name="build.jar.dependency" value="@{jar-dependency}" />
381         </then>
382       </if>
383      
384       <!--  =================== Compilation Control Options ===============
385         These properties control option settings on the Javac compiler when it
386         is invoked using the <javac> task.
387
388         compile.debug        Should compilation include the debug option?
389         compile.deprecation  Should compilation include the deprecation option?
390         compile.optimize     Should compilation include the optimize option?
391
392         Below are the defaults. They may already be set in the build properties.
393       -->
394
395       <property name="compile.debug" value="true"/>
396       <property name="compile.deprecation" value="false"/>
397       <property name="compile.optimize" value="true"/>
398       <property name="compile.verbose" value="false"/>
399       <property name="compile.listfiles" value="false"/>
400
401       <var name="jar.temp.sources"
402            value="${dist.home}/source" />
403       <var name="jar.temp.classes"
404            value="${dist.home}/classes" />
405
406       <!-- ==============================================================
407             See if the jar is up to date. We recompile if any of the
408             source files or metainf files are newer. We also recompile if
409             any jars on the package classpath are newer.
410            ============================================================== -->
411
412       <noisyMsg message="build.jar.file=@{jar-file}" />
413      
414       <if>
415         <isset property="build.jar.dependency"/>
416         <then>
417           <dirname file="${build.jar.dependency}"
418                    property="dependency.dirname" />
419           <basename file="${build.jar.dependency}"
420                     property="dependency.basename" />
421           <fileset dir="${dependency.dirname}" id="dependency.fileset">
422             <include name="${dependency.basename}"/>
423           </fileset>
424         </then>
425         <else>
426           <fileset refid="empty.fileset" id="dependency.fileset"/>
427         </else>
428       </if>     
429
430       <!-- See if the libraries are later than any classes -->
431
432       <var name="org.bedework.libraries.changed" value="false" />
433      
434       <outofdate outputsources="org.bedework,changed.sources">
435         <sourcefiles>
436           <fileset dir="${lib.dir}">
437              <include name="*.jar"/>
438           </fileset>
439           <!-- This makes almost everything rebuild all the time
440                because it has the generated jars for the current package
441           <path refid="compile.classpath"/>
442           -->
443         </sourcefiles>
444         <targetfiles>
445           <pathelement path="@{jar-file}"/>
446         </targetfiles>
447         <sequential>
448           <var name="org.bedework.libraries.changed" value="true" />
449           <noisyMsg message="**** @{jar-file} needs rebuilding - libraries changed" />
450         </sequential>
451       </outofdate>
452      
453       <noisyMsg message="**** org.bedework,changed.sources = ${org.bedework,changed.sources}" />
454       <noisyMsg message="**** org.bedework.libraries.changed = ${org.bedework.libraries.changed}" />
455
456       <if>
457         <and>
458           <not>
459             <equals arg1="${org.bedework.libraries.changed}" arg2="true" />
460           </not>
461           <uptodate targetfile="@{jar-file}" >
462             <srcfiles refid="buildjar.java.sources" />
463             <srcfiles refid="buildjar.generated.java.sources" />
464             <srcfiles refid="buildjar.resource.files"/>
465             <srcfiles refid="dependency.fileset"/>
466           </uptodate>
467         </and>
468         <then>
469           <noisyMsg message="**** @{jar-file} is up to date" />
470         </then>
471         <else>
472           <noisyMsg message="**** @{jar-file} needs rebuilding" />
473
474           <math result="org.bedework.jars.built"
475                 operand1="${org.bedework.jars.built}"
476                 operation="+" operand2="1" datatype="int"/>
477
478           <!-- Delete jar file -->
479           <delete file="@{jar-file}"/>
480
481           <dirname property="build.jar.dir" file="@{jar-file}"/>
482
483           <mkdir dir="${build.jar.dir}" />
484
485           <!-- ==========================================================
486                             Build the classes
487                ========================================================== -->
488
489           <!-- First copy the sources we are going to compile into a temp
490                directory. -->
491           <delete dir="${jar.temp.sources}" />
492           <mkdir dir="${jar.temp.sources}" />
493          
494           <copy toDir="${jar.temp.sources}">
495             <fileset refid="buildjar.java.sources" />
496             <fileset refid="buildjar.generated.java.sources" />
497             <fileset refid="buildjar.resource.files"/>
498           </copy>
499
500           <mkdir dir="${jar.temp.classes}"/>
501          
502           <debugMsg message="About to build jar @{jar-file}"/>
503           <debugCpid idpar="compile.classpath" />
504
505           <javac srcdir="${jar.temp.sources}"
506                  destdir="${jar.temp.classes}"
507                  debug="${compile.debug}"
508                  verbose="${compile.verbose}"
509                  listfiles="${compile.listfiles}"
510                  deprecation="${compile.deprecation}"
511                  optimize="${compile.optimize}">
512             <classpath refid="compile.classpath"/>
513             <include name="**/*.java"/>
514             <compilerarg value="-nowarn" compiler="jikes" />
515           </javac>
516
517           <!-- ==========================================================
518                             Build jar file
519                ========================================================== -->
520
521           <jar jarfile="@{jar-file}">
522             <fileset dir="${jar.temp.classes}">
523               <patternset refid="base.class.patternset"/>
524             </fileset>
525             <fileset refid="buildjar.resource.files"/>
526           </jar>
527
528           <!-- ==========================================================
529                             Clean up
530                ========================================================== -->
531
532           <delete dir="${jar.temp.sources}" />
533           <delete dir="${jar.temp.classes}"/>
534         </else>
535       </if>
536     </sequential>
537   </macrodef>
538  
539   <macrodef name="infoMsg">
540     <attribute name="message"/>
541     <sequential>
542       <if>
543         <not>
544           <istrue value="${org.bedework.build.silent}" />
545         </not>
546         <then>
547           <echo message="@{message}" />
548         </then>
549       </if>
550     </sequential>
551   </macrodef>
552  
553   <macrodef name="noisyMsg">
554     <attribute name="message"/>
555     <sequential>
556       <if>
557         <istrue value="${org.bedework.build.noisy}" />
558         <then>
559           <echo message="@{message}" />
560         </then>
561       </if>
562     </sequential>
563   </macrodef>
564  
565   <macrodef name="debugMsg">
566     <attribute name="message"/>
567     <sequential>
568       <if>
569         <istrue value="${org.bedework.build.debug}" />
570         <then>
571           <echo message="@{message}" />
572         </then>
573       </if>
574     </sequential>
575   </macrodef>
576  
577   <macrodef name="debugCpid">
578     <attribute name="idpar"/>
579     <sequential>
580       <if>
581         <istrue value="${org.bedework.build.debug}" />
582         <then>
583           <property name="cp" refid="@{idpar}" />
584           <echo message="***************cp: ${cp}"/>
585         </then>
586       </if>
587     </sequential>
588   </macrodef>
589 </project>
Note: See TracBrowser for help on using the browser.