OnJava8-Examples/Ant-Common.xml
2015-12-16 16:16:15 -07:00

217 lines
7.6 KiB
XML

<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="chapter" value="CHAPTER?"/>
<property name="antoutput" value="../Ant-output.txt"/>
<description>
Ant build.xml for the source code for chapter ${chapter}
Bruce Eckel On Java
Code available at https://github.com/BruceEckel/OnJava-Examples
See installation instructions in README.md
See copyright notice in CopyRight.txt
Ant available from http://ant.apache.org
To see options, type: ant -p
</description>
<condition property="version1.8">
<equals arg1="1.8" arg2="${ant.java.version}"/>
</condition>
<!--===========================================================-->
<macrodef name="jrun">
<attribute name="cls" default="NOT SET"/>
<attribute name="dirpath" default=""/>
<attribute name="arguments" default=""/>
<attribute name="failOnError" default="true"/>
<attribute name="timeOut" default="15000"/>
<attribute name="msg" default=""/>
<sequential>
<echo>[${chapter}] java @{cls} @{arguments}&#13;</echo>
<echo file="${antoutput}" append="true">[${chapter}] java @{cls} @{arguments}&#13;</echo>
<java
classname="@{cls}"
classpath="${java.class.path};${basedir};${basedir}/.."
dir="@{dirpath}"
failonerror="@{failOnError}"
fork="true"
timeout="@{timeOut}"
output="${antoutput}" append="true">
<arg line="@{arguments}"/>
<redirector
output="@{cls}.out"
error="@{cls}.err"
createemptyfiles="false"
append="false" />
</java>
<echo file="${antoutput}" append="true">[${chapter}] Finished: java @{cls} @{arguments}&#13;</echo>
<echo file="${antoutput}" append="true">@{msg}&#13;</echo>
<echo file="${antoutput}" append="true">--------------------------------&#13;</echo>
</sequential>
</macrodef>
<!--===========================================================-->
<macrodef name="jrunconsole">
<attribute name="cls" default="NOT SET"/>
<attribute name="dirpath" default=""/>
<attribute name="arguments" default=""/>
<attribute name="failOnError" default="true"/>
<attribute name="timeOut" default="15000"/>
<attribute name="msg" default=""/>
<sequential>
<echo>[${chapter}] java @{cls} @{arguments}&#13;</echo>
<echo append="true">[${chapter}] java @{cls} @{arguments}&#13;</echo>
<java
classname="@{cls}"
classpath="${java.class.path};${basedir};${basedir}/.."
dir="@{dirpath}"
failonerror="@{failOnError}"
fork="true"
timeout="@{timeOut}"
>
<arg line="@{arguments}"/>
</java>
<echo append="true">[${chapter}] Finished: java @{cls} @{arguments}&#13;</echo>
<echo append="true">@{msg}&#13;</echo>
<echo append="true">--------------------------------&#13;</echo>
</sequential>
</macrodef>
<macrodef name="execscript">
<attribute name="name"/>
<sequential>
<condition property="isWindows">
<os family="windows"/>
</condition>
<sequential if:true="isWindows">
<echo message="@{name}.bat"/>
<exec executable="cmd" dir=".">
<arg line="/c @{name}.bat"/>
</exec>
</sequential>
<sequential unless:true="isWindows">
<echo message="@{name}.sh"/>
<exec executable="sh" dir=".">
<arg line="@{name}.sh"/>
</exec>
</sequential>
</sequential>
</macrodef>
<!--===========================================================-->
<target name="base"
description="Build all common dependencies">
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../onjava/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../com/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../polymorphism/music/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../typeinfo/pets/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../collections/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../generics/coffee/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
srcdir="${basedir}/../enums/menu/">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
</target>
<!--===========================================================-->
<target name="build"
description="Build all classes in this directory"
depends="base">
<fail message="Java 8 required" unless="version1.8"/>
<echo message="Building '${chapter}'&#13;"/>
<echo file="${antoutput}" append="true" message="Building '${chapter}'&#13;"/>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
debug="true"
excludes="${excludedfiles}"
srcdir="${basedir}">
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<echo message="Build '${chapter}' succeeded&#13;"/>
<echo file="${antoutput}" append="true" message="Build '${chapter}' succeeded&#13;"/>
</target>
<!--===========================================================-->
<target name="buildw"
description="Build all classes in this directory, enabling 'Unchecked' warnings"
depends="base">
<fail message="Java 8 required" unless="version1.8"/>
<echo message="Building '${chapter}'&#13;"/>
<echo file="${antoutput}" append="true" message="Building '${chapter}'&#13;"/>
<javac includeantruntime="false"
classpath="${java.class.path};${basedir};${basedir}/.."
debug="true"
excludes="${excludedfiles}"
srcdir="${basedir}">
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-Xmaxerrs"/>
<compilerarg value="10"/>
</javac>
<echo message="Build '${chapter}' succeeded&#13;"/>
<echo file="${antoutput}" append="true" message="Build '${chapter}' succeeded&#13;"/>
</target>
<!--===========================================================-->
<target name="verifyclean"
description="delete ant verify output files" >
<delete>
<fileset dir="${basedir}" casesensitive="yes">
<include name="**/update_output.bat" />
<include name="**/validate_failures.txt" />
<include name="**/validate_successes.txt" />
<include name="**/strategies.txt" />
<include name="**/edit_errors.bat" />
</fileset>
</delete>
<echo message="verifyclean successful"/>
</target>
<target name="verify"
description="Verify output; requires Python 3.5"
depends="verifyclean">
<exec dir="${basedir}" executable="python" failonerror="true">
<arg line="../verify_output.py" />
</exec>
</target>
</project>