| | 186 | <!-- This macro builds a single jar file. It just sets defaults for the java |
|---|
| | 187 | compiler then invokes it. |
|---|
| | 188 | |
|---|
| | 189 | This is the only place we compile files. |
|---|
| | 190 | |
|---|
| | 191 | On entry we require: |
|---|
| | 192 | jar.file Fully specified name of destination jar file. |
|---|
| | 193 | base.java.sources Defines the java source files |
|---|
| | 194 | base.class.patternset Defines the java class files |
|---|
| | 195 | base.resource.files Defines extra resources to go in the jar |
|---|
| | 196 | |
|---|
| | 197 | We will copy all files defined by base.java.patternset to a temporary |
|---|
| | 198 | location and compile out of that into a temporary classes location. |
|---|
| | 199 | |
|---|
| | 200 | We do that to avoid a problematic feature of the java compilers, the |
|---|
| | 201 | tendency to recompile any referenced sources found on the source path. |
|---|
| | 202 | |
|---|
| | 203 | So, if we have all our sources under the directory "src" and compile a |
|---|
| | 204 | single package in that tree, all referenced classes will be compiled, |
|---|
| | 205 | even if they exist in a jar file on the class path. |
|---|
| | 206 | |
|---|
| | 207 | The other side-effect is that we might compile and include classes we |
|---|
| | 208 | didn't realise we were compiling. |
|---|
| | 209 | |
|---|
| | 210 | The downside is that we need to be very specific about the classes we |
|---|
| | 211 | compile for a package and we might need to put classes in |
|---|
| | 212 | base.java.sources which we don't want in the final jar file. |
|---|
| | 213 | |
|---|
| | 214 | On exit we will have created classes in the directory |
|---|
| | 215 | ${jar.temp.classes} |
|---|
| | 216 | and a jar file |
|---|
| | 217 | ${build.jar.file} |
|---|
| | 218 | |
|---|
| | 219 | Authors: Mike Douglass douglm rpi.edu |
|---|
| | 220 | --> |
|---|
| 232 | | |
|---|
| 233 | | <ant antfile="${buildjar}" inheritRefs="true" target="build" > |
|---|
| 234 | | <property name="build.jar.file" location="@{jar-file}" /> |
|---|
| 235 | | </ant> |
|---|
| | 269 | |
|---|
| | 270 | <!-- =================== Compilation Control Options =============== |
|---|
| | 271 | These properties control option settings on the Javac compiler when it |
|---|
| | 272 | is invoked using the <javac> task. |
|---|
| | 273 | |
|---|
| | 274 | compile.debug Should compilation include the debug option? |
|---|
| | 275 | compile.deprecation Should compilation include the deprecation option? |
|---|
| | 276 | compile.optimize Should compilation include the optimize option? |
|---|
| | 277 | |
|---|
| | 278 | Below are the defaults. They may already be set in the build properties. |
|---|
| | 279 | --> |
|---|
| | 280 | |
|---|
| | 281 | <property name="compile.debug" value="true"/> |
|---|
| | 282 | <property name="compile.deprecation" value="false"/> |
|---|
| | 283 | <property name="compile.optimize" value="true"/> |
|---|
| | 284 | <property name="compile.verbose" value="false"/> |
|---|
| | 285 | <property name="compile.listfiles" value="false"/> |
|---|
| | 286 | |
|---|
| | 287 | <property name="jar.temp.sources" |
|---|
| | 288 | location="${dist.home}/source" /> |
|---|
| | 289 | <property name="jar.temp.classes" |
|---|
| | 290 | location="${dist.home}/classes" /> |
|---|
| | 291 | |
|---|
| | 292 | <!-- ============================================================== |
|---|
| | 293 | See if the jar is up to date. We recompile if any of the |
|---|
| | 294 | source files or metainf files are newer. We also recompile if |
|---|
| | 295 | any jars on the package classpath are newer. |
|---|
| | 296 | ============================================================== --> |
|---|
| | 297 | |
|---|
| | 298 | <noisyMsg message="build.jar.file=@{jar-file}" /> |
|---|
| | 299 | |
|---|
| | 300 | <if> |
|---|
| | 301 | <isset property="build.jar.dependency"/> |
|---|
| | 302 | <then> |
|---|
| | 303 | <dirname file="${build.jar.dependency}" |
|---|
| | 304 | property="dependency.dirname" /> |
|---|
| | 305 | <basename file="${build.jar.dependency}" |
|---|
| | 306 | property="dependency.basename" /> |
|---|
| | 307 | <fileset dir="${dependency.dirname}" id="dependency.fileset"> |
|---|
| | 308 | <include name="${dependency.basename}"/> |
|---|
| | 309 | </fileset> |
|---|
| | 310 | </then> |
|---|
| | 311 | <else> |
|---|
| | 312 | <fileset refid="empty.fileset" id="dependency.fileset"/> |
|---|
| | 313 | </else> |
|---|
| | 314 | </if> |
|---|
| | 315 | |
|---|
| | 316 | <uptodate property="build.jar.uptodate" |
|---|
| | 317 | targetfile="@{jar-file}" > |
|---|
| | 318 | <srcfiles refid="buildjar.java.sources" /> |
|---|
| | 319 | <srcfiles refid="buildjar.generated.java.sources" /> |
|---|
| | 320 | <srcfiles refid="buildjar.resource.files"/> |
|---|
| | 321 | <srcfiles refid="dependency.fileset"/> |
|---|
| | 322 | </uptodate> |
|---|
| | 323 | |
|---|
| | 324 | <if> |
|---|
| | 325 | <isset property="build.jar.uptodate"/> |
|---|
| | 326 | <then> |
|---|
| | 327 | <noisyMsg message="**** @{jar-file} is up to date" /> |
|---|
| | 328 | </then> |
|---|
| | 329 | <else> |
|---|
| | 330 | <noisyMsg message="**** @{jar-file} needs rebuilding" /> |
|---|
| | 331 | |
|---|
| | 332 | <!-- Delete jar file --> |
|---|
| | 333 | <delete file="@{jar-file}"/> |
|---|
| | 334 | |
|---|
| | 335 | <dirname property="build.jar.dir" file="@{jar-file}"/> |
|---|
| | 336 | |
|---|
| | 337 | <mkdir dir="${build.jar.dir}" /> |
|---|
| | 338 | |
|---|
| | 339 | <!-- ========================================================== |
|---|
| | 340 | Build the classes |
|---|
| | 341 | ========================================================== --> |
|---|
| | 342 | |
|---|
| | 343 | <!-- First copy the sources we are going to compile into a temp |
|---|
| | 344 | directory. --> |
|---|
| | 345 | <delete dir="${jar.temp.sources}" /> |
|---|
| | 346 | <mkdir dir="${jar.temp.sources}" /> |
|---|
| | 347 | |
|---|
| | 348 | <copy toDir="${jar.temp.sources}"> |
|---|
| | 349 | <fileset refid="buildjar.java.sources" /> |
|---|
| | 350 | <fileset refid="buildjar.generated.java.sources" /> |
|---|
| | 351 | <fileset refid="buildjar.resource.files"/> |
|---|
| | 352 | </copy> |
|---|
| | 353 | |
|---|
| | 354 | <mkdir dir="${jar.temp.classes}"/> |
|---|
| | 355 | |
|---|
| | 356 | <debugMsg message="About to build jar @{jar-file}"/> |
|---|
| | 357 | <debugCpid idpar="compile.classpath" /> |
|---|
| | 358 | |
|---|
| | 359 | <javac srcdir="${jar.temp.sources}" |
|---|
| | 360 | destdir="${jar.temp.classes}" |
|---|
| | 361 | debug="${compile.debug}" |
|---|
| | 362 | verbose="${compile.verbose}" |
|---|
| | 363 | listfiles="${compile.listfiles}" |
|---|
| | 364 | deprecation="${compile.deprecation}" |
|---|
| | 365 | optimize="${compile.optimize}"> |
|---|
| | 366 | <classpath refid="compile.classpath"/> |
|---|
| | 367 | <include name="**/*.java"/> |
|---|
| | 368 | <compilerarg value="-nowarn" compiler="jikes" /> |
|---|
| | 369 | </javac> |
|---|
| | 370 | |
|---|
| | 371 | <!-- ========================================================== |
|---|
| | 372 | Build jar file |
|---|
| | 373 | ========================================================== --> |
|---|
| | 374 | |
|---|
| | 375 | <jar jarfile="@{jar-file}"> |
|---|
| | 376 | <fileset dir="${jar.temp.classes}"> |
|---|
| | 377 | <patternset refid="base.class.patternset"/> |
|---|
| | 378 | </fileset> |
|---|
| | 379 | <fileset refid="buildjar.resource.files"/> |
|---|
| | 380 | </jar> |
|---|
| | 381 | |
|---|
| | 382 | <!-- ========================================================== |
|---|
| | 383 | Clean up |
|---|
| | 384 | ========================================================== --> |
|---|
| | 385 | |
|---|
| | 386 | <delete dir="${jar.temp.sources}" /> |
|---|
| | 387 | <delete dir="${jar.temp.classes}"/> |
|---|
| | 388 | </else> |
|---|
| | 389 | </if> |
|---|