root/releases/bedework-3.8/build/buildTools/deftasks.xml

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

Make clean.deploy work OK

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