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 19:34:36 GMT

Thanks for your question, Brian,
I didn't know about the "else" parameter on <condition> before I checked that out.
I generally learn from helping others.
:-)

Rob 

> -----Original Message-----
> From: Brian McCann [mailto:bmccann01@comcast.net] 
> Sent: Monday, June 06, 2011 3:02 PM
> To: user@ant.apache.org
> Cc: Echlin, Robert
> Subject: RE: How change variable based on environment variable value
> 
> Many thanks for your help :)
> BPM
> 
> -----Original Message-----
> From: Echlin, Robert [mailto:Robert.Echlin@windriver.com]
> Sent: Monday, June 06, 2011 1:51 PM
> To: Brian McCann
> Subject: RE: How change variable based on environment variable value
> 
> 
> > -----Original Message-----
> > From: Brian McCann [mailto:bmccann01@comcast.net] 
> > Sent: Monday, June 06, 2011 1:34 PM
> > To: 'Ant Users List'
> > Cc: Echlin, Robert
> > Subject: RE: How change variable based on environment variable value
> > 
> > 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?
> 
> Whatever gets set first stays set. Properties are immutable.
> 
> > 
> > 
> > 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?
> 
> No, a properties file is not an XML file.
> The "build.user.properties" file would look like:
> ----  two samples ---
> # Set JOF for my computer
> JOF=C:/Inetpub/wwwroot/wo30
> 
> -- OR --
> # Set values for my computer
> JOF           = C:/Inetpub/wwwroot/wo30
> Princelieness = 100
> 
> --- end samples --
> Notes about propertye files:
> - Space around the "=" is ignored
> - comment lines start with #
> 
> 
> > 
> > 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>
> 
> Yuppers, you got it.
> This would load the build.user.properties file after the check for the
> BUILD_BOX variable.
> 
> However, I would put this code VERY close to the top of the 
> build.xml file,
> so that when you set other properties there, they are available early.
> And of course, if you want to override them, you need to do 
> that before the
> properties are loaded from the local users file.
> :-)
> 
> Anyway, you can use the pattern of setting the variable names 
> to a "default"
> or "local" property name in the file, and then set the 
> correct one before
> you use it, taking into account other info like the 
> "BUILD_BOX" environment
> variable.
> 
> Rob
> 
> > 
> > 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