root/trunk/build/buildjar.xml

Revision 1951 (checked in by douglm, 5 years ago)

Changes to the build process an adding some install scripts

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