root/trunk/build/buildTools/deftasks.xml

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

Fix to allow build of shell scripts

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