ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian McCann" <bmccan...@comcast.net>
Subject RE: How change variable based on environment variable value
Date Mon, 06 Jun 2011 17:33:34 GMT
Hi Robert,

couple questions to make sure I'm following you right.

1. I'm currently setting the value of JOF in the build.userproperties file
to " JOF=C:/Inetpub/wwwroot/wo30"
and even if I try to run a conditional in the build.xml file < property
name="JOF" value="F:/Inetpub/wwwroot/wo30"/>
The value of JOF gets set in stone when build.xml runs? Build.properties
files always override build.xml?



2. Since I already have a file build.user.properties I could just set the
default value of JOF path in that file like <property name="JOF"
value="C:/Inetpub/wwwroot/wo30"/> which would be the state that the build
file is not being run on the build box?

so your code would look like:

<?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="build.user.properties" />
    <echo>After Property file, JOF = ${JOF}</echo>
  </target>

</project>

Thanks,
BPM


-----Original Message-----
From: Echlin, Robert [mailto:Robert.Echlin@windriver.com] 
Sent: Monday, June 06, 2011 12:46 PM
To: Ant Users List
Subject: RE: How change variable based on environment variable value

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


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


Mime
View raw message