| 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 |
<antcall target="do.build.uptodate" inheritRefs="true" /> |
|---|
| 83 |
<antcall target="do.build.notuptodate" inheritRefs="true" /> |
|---|
| 84 |
</target> |
|---|
| 85 |
|
|---|
| 86 |
<target name="do.build.notuptodate" |
|---|
| 87 |
if="build.jar.uptodate"> |
|---|
| 88 |
<echo message="**** ${build.jar.file} is up to date" /> |
|---|
| 89 |
</target> |
|---|
| 90 |
|
|---|
| 91 |
<target name="do.build.uptodate" |
|---|
| 92 |
unless="build.jar.uptodate"> |
|---|
| 93 |
<echo message="**** ${build.jar.file} needs rebuilding" /> |
|---|
| 94 |
|
|---|
| 95 |
<!-- Delete jar file --> |
|---|
| 96 |
<delete file="${build.jar.file}"/> |
|---|
| 97 |
|
|---|
| 98 |
<dirname property="build.jar.dir" file="${build.jar.file}"/> |
|---|
| 99 |
|
|---|
| 100 |
<mkdir dir="${build.jar.dir}" /> |
|---|
| 101 |
|
|---|
| 102 |
<!-- ============================================================== |
|---|
| 103 |
Build the classes |
|---|
| 104 |
============================================================== --> |
|---|
| 105 |
|
|---|
| 106 |
<!-- First copy the sources we are going to compile into a temp |
|---|
| 107 |
directory. --> |
|---|
| 108 |
<mkdir dir="${jar.temp.sources}" /> |
|---|
| 109 |
<copy toDir="${jar.temp.sources}"> |
|---|
| 110 |
<fileset refid="base.java.sources" /> |
|---|
| 111 |
<fileset refid="base.resource.files"/> |
|---|
| 112 |
</copy> |
|---|
| 113 |
|
|---|
| 114 |
<mkdir dir="${jar.temp.classes}"/> |
|---|
| 115 |
<echo message="About to build jar ${build.jar.file}"/> |
|---|
| 116 |
<property name="cp" refid="compile.classpath" /> |
|---|
| 117 |
<echo message="***************cp: ${cp}"/> |
|---|
| 118 |
|
|---|
| 119 |
<javac srcdir="${jar.temp.sources}" |
|---|
| 120 |
destdir="${jar.temp.classes}" |
|---|
| 121 |
debug="${compile.debug}" |
|---|
| 122 |
verbose="${compile.verbose}" |
|---|
| 123 |
listfiles="${compile.listfiles}" |
|---|
| 124 |
deprecation="${compile.deprecation}" |
|---|
| 125 |
optimize="${compile.optimize}"> |
|---|
| 126 |
<classpath refid="compile.classpath"/> |
|---|
| 127 |
<include name="**/*.java"/> |
|---|
| 128 |
<compilerarg value="-nowarn" compiler="jikes" /> |
|---|
| 129 |
</javac> |
|---|
| 130 |
|
|---|
| 131 |
<!-- ============================================================== |
|---|
| 132 |
Build jar file |
|---|
| 133 |
============================================================== --> |
|---|
| 134 |
|
|---|
| 135 |
<jar jarfile="${build.jar.file}"> |
|---|
| 136 |
<fileset dir="${jar.temp.classes}"> |
|---|
| 137 |
<patternset refid="base.class.patternset"/> |
|---|
| 138 |
</fileset> |
|---|
| 139 |
<fileset refid="base.resource.files"/> |
|---|
| 140 |
</jar> |
|---|
| 141 |
|
|---|
| 142 |
<!-- ============================================================== |
|---|
| 143 |
Clean up |
|---|
| 144 |
============================================================== --> |
|---|
| 145 |
|
|---|
| 146 |
<delete dir="${jar.temp.sources}" /> |
|---|
| 147 |
<delete dir="${jar.temp.classes}"/> |
|---|
| 148 |
</target> |
|---|
| 149 |
</project> |
|---|