root/trunk/build/buildTools/buildjar.xml

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

Commit missed buildTools

Line 
1 <!-- This file builds a single jar file. It just sets defaults for the java
2      compiler then invokes it.
3
4      This is the only place we compile files.
5
6      On entry we require:
7        build.jar.file        Fully specified name of destination jar file.
8        base.java.sources     Defines the java source files
9        base.class.patternset Defines the java class files
10        base.resource.files   Defines extra resources to go in the jar
11
12      We will copy all files defined by base.java.patternset to a temporary
13      location and compile out of that into a temporary classes location.
14
15      We do that to avoid a problematic feature of the java compilers, the
16      tendency to recompile any referenced sources found on the source path.
17
18      So, if we have all our sources under the directory "src" and compile a
19      single package in that tree, all referenced classes will be compiled,
20      even if they exist in a jar file on the class path.
21
22      The other side-effect is that we might compile and include classes we
23      didn't realise we were compiling.
24
25      The downside is that we need to be very specific about the classes we
26      compile for a package and we might need to put classes in
27      base.java.sources which we don't want in the final jar file.
28
29      On exit we will have created classes in the directory
30         ${jar.temp.classes}
31      and a jar file
32         ${build.jar.file}
33
34      Authors: Mike Douglass   douglm rpi.edu
35 -->
36
37 <project name="buildjar" default="build" >
38   <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
39
40   <target name="init">
41     <!--  =================== Compilation Control Options ===============
42       These properties control option settings on the Javac compiler when it
43       is invoked using the <javac> task.
44
45       compile.debug        Should compilation include the debug option?
46       compile.deprecation  Should compilation include the deprecation option?
47       compile.optimize     Should compilation include the optimize option?
48
49       Below are the defaults. They may already be set in the build properties.
50     -->
51
52     <property name="compile.debug" value="true"/>
53     <property name="compile.deprecation" value="false"/>
54     <property name="compile.optimize" value="true"/>
55     <property name="compile.verbose" value="false"/>
56     <property name="compile.listfiles" value="false"/>
57
58     <property name="jar.temp.sources"
59              location="${dist.home}/source" />
60     <property name="jar.temp.classes"
61              location="${dist.home}/classes" />
62   </target>
63
64   <target name="build" depends="init"
65           description="Compile Java sources">
66     <!-- ==============================================================
67           See if the jar is up to date. We recompile if any of the
68           source files or metainf files are newer. We also recompile if
69           any jars on the package classpath are newer.
70          ============================================================== -->
71
72     <noisyMsg message="build.jar.file=${build.jar.file}" />
73
74     <uptodate property="build.jar.uptodate"
75               targetfile="${build.jar.file}" >
76       <srcfiles refid="buildjar.java.sources" />
77       <srcfiles refid="buildjar.generated.java.sources" />
78       <srcfiles refid="buildjar.resource.files"/>
79     </uptodate>
80
81     <if>
82       <isset property="build.jar.uptodate"/>
83       <then>
84         <noisyMsg message="**** ${build.jar.file} is up to date" />
85       </then>
86       <else>
87         <noisyMsg message="**** ${build.jar.file} needs rebuilding" />
88
89         <!-- Delete jar file -->
90         <delete file="${build.jar.file}"/>
91
92         <dirname property="build.jar.dir" file="${build.jar.file}"/>
93
94         <mkdir dir="${build.jar.dir}" />
95
96         <!-- ==========================================================
97                           Build the classes
98              ========================================================== -->
99
100         <!-- First copy the sources we are going to compile into a temp
101              directory. -->
102         <delete dir="${jar.temp.sources}" />
103         <mkdir dir="${jar.temp.sources}" />
104        
105         <copy toDir="${jar.temp.sources}">
106           <fileset refid="buildjar.java.sources" />
107           <fileset refid="buildjar.generated.java.sources" />
108           <fileset refid="buildjar.resource.files"/>
109         </copy>
110
111         <mkdir dir="${jar.temp.classes}"/>
112        
113         <debugMsg message="About to build jar ${build.jar.file}"/>
114         <debugCpid idpar="compile.classpath" />
115
116         <javac srcdir="${jar.temp.sources}"
117                destdir="${jar.temp.classes}"
118                debug="${compile.debug}"
119                verbose="${compile.verbose}"
120                listfiles="${compile.listfiles}"
121                deprecation="${compile.deprecation}"
122                optimize="${compile.optimize}">
123           <classpath refid="compile.classpath"/>
124           <include name="**/*.java"/>
125           <compilerarg value="-nowarn" compiler="jikes" />
126         </javac>
127
128         <!-- ==========================================================
129                           Build jar file
130              ========================================================== -->
131
132         <jar jarfile="${build.jar.file}">
133           <fileset dir="${jar.temp.classes}">
134             <patternset refid="base.class.patternset"/>
135           </fileset>
136           <fileset refid="buildjar.resource.files"/>
137         </jar>
138
139         <!-- ==========================================================
140                           Clean up
141              ========================================================== -->
142
143         <delete dir="${jar.temp.sources}" />
144         <delete dir="${jar.temp.classes}"/>
145       </else>
146     </if>
147   </target>
148 </project>
Note: See TracBrowser for help on using the browser.