ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Echlin, Robert" <Robert.Ech...@windriver.com>
Subject RE: How change variable based on environment variable value
Date Mon, 06 Jun 2011 16:45:54 GMT
Hi Brian,
Try this code.
Note: you can't put the default value of JOF into a file that will be loaded automatically
when ant is run, such as (home)/.antrc,
as that would set JOF before your code executes. First set works, last set fails.

On the other hand, you could set "JOF_default" in a properties file that is loaded before
this code is run, then have an "else" clause in your condition to use it when BUILD_BOX is
not set in your environment:
  <condition property="JOF" value="F:/Inetpub/wwwroot/wo30" else="${JOF_default}">

Rob

------------ simplified code ----------
<?xml version="1.0" encoding="utf-8"?>
<project name="plugin-rules" basedir="." default="setJOF">
  <target name="setJOF">
    <property environment="env"/>
    <echo>BUILD_BOX = ${env.BUILD_BOX}</echo>
    <condition property="JOF" value="F:/Inetpub/wwwroot/wo30">
      <isset property="env.BUILD_BOX"/>
    </condition>
    <echo>JOF = ${JOF}</echo>

    <property file="jof.properties" />
    <echo>After Property file, JOF = ${JOF}</echo>
  </target>

</project>
---------------- output of test run - no build-run ---------
C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>set BUILD_BOX=

C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>echo %BUILD_BOX%
%BUILD_BOX%

C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>ant -f jof-test.xml
Buildfile: C:\Documents and Settings\rechlin\My Documents\test\TEST-ant\jof-test.xml

setJOF:
     [echo] BUILD_BOX = ${env.BUILD_BOX}
     [echo] JOF = ${JOF}
     [echo] After Property file, JOF = C:/Inetpub/wwwroot/wo30

BUILD SUCCESSFUL
Total time: 0 seconds
------------------------ output of test run with BUILD_RUN set in the environment ---------
C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>set BUILD_BOX=true

C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>echo %BUILD_BOX%
true

C:\Documents and Settings\rechlin\My Documents\test\TEST-ant>ant -f jof-test.xml
Buildfile: C:\Documents and Settings\rechlin\My Documents\test\TEST-ant\jof-test.xml

setJOF:
     [echo] BUILD_BOX = true
     [echo] JOF = F:/Inetpub/wwwroot/wo30
     [echo] After Property file, JOF = F:/Inetpub/wwwroot/wo30

BUILD SUCCESSFUL
Total time: 0 seconds
--------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message