Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract and compare values

Status
Not open for further replies.

mirakulix

Programmer
Jul 14, 2006
1
0
0
DK
Hi

I have a file app_cfg containing some configurations i wanna use when running my ant-script.

app_cfg:
appl_type=java_app

depending on what application defined at appl_type i want to run different targets in my ant-script.
ex. if it is a java_app I want to run <target name=coffee/>
but if is C application I wanna run <target name=c> ect.

at this point I extract the value of appl_type with loadproperties, but how do I check the value and only run the correct target?
 
# 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 **************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top