# start of contents of property file appl.properties
appl.type=java or
appl.type=c
# end of contents of property file
<project name="compile-java-or-c" default="do-build">
<property file="appl.properties" />
<target name="do-build" depends="echo-build, build-java-files,build-c-files"/>
<target name="echo-build">
<echo> appl.type = ${appl.type} </echo>
</target>
<!-- Do a Java build -->
<target name="build-java-files" if="java.build" depends="determine-build-type">
<!-- We will only do this build if "java.build" = "java" -->
<echo> doing a Java Compile </echo>
</target>
<!-- Do a C build -->
<target name="build-c-files" unless="java.build" depends="determine-build-type">
<!-- We will only do this build if "java.build" IS NOT "java" -->
<echo> Doing a C compile </echo>
</target>
<!-- this target will set the java.build property
if the build is for java -->
<target name="determine-build-type">
<condition property="java.build">
<!-- if appl type is Java -->
<contains string="${appl.type}" substring="java" />
</condition>
</target>
</project>
*************start Results test 1 **************
** start appl.properties contents
appl.type=java
** end appl.properties contents
C:\Documents and Settings\BLang\My Documents\AntFileProcessing>ant -f buildappl.xml
Buildfile: buildappl.xml
echo-build:
[echo] appl.type = java
determine-build-type:
build-java-files:
[echo] doing a Java Compile
build-c-files:
do-build:
BUILD SUCCESSFUL
Total time: 0 seconds
*************end Results test 1 **************
*************start Results test 2 **************
** start appl.properties contents
appl.type=c
** end appl.properties contents
C:\Documents and Settings\BLang\My Documents\AntFileProcessing>ant -f buildappl.xml
Buildfile: buildappl.xml
echo-build:
[echo] appl.type = c
determine-build-type:
build-java-files:
build-c-files:
[echo] Doing a C compile
do-build:
BUILD SUCCESSFUL
Total time: 0 seconds
*************end Results test 2 **************