ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wolfgang haefelinger <whaefelin...@gmail.com>
Subject Re: How change variable based on environment variable value
Date Wed, 08 Jun 2011 13:01:16 GMT
Hi,

>>    <condition property="JOF" value="F:/Inetpub/wwwroot/wo30">
>>      <isset property="env.BUILD_BOX"/>
>>    </condition>

This would also enable the "build system settings" if environment
variable BUILD_BOX is set to "false". Would be better to check
existence and then variable's content as well - just to avoid any
confusion.

A second thought on maintaining such a script later on - you would
move "F:/Inetpub/wwwroot/wo30" into a property cause you don't want to
have such hard-wired paths in your build scripts, do you?

Perhaps you should drop the idear of depending on environment
variables and depend on (property) files instead, for example:

<project>
  <property file="buildsystem.properties" />
  <property file="common.properties" />
  <echo>JOF=${JOF}</echo>
</project>

Property file "buildsystem.properties" would only exist on
build-servers while "common.properties" is assumed to exist on
developer and build-server hosts. Then

== buildserver.properties ==
JOF = F:/Inetpub/wwwroot/wo30

== common.properties ==
JOF=C:/Inetpub/wwwroot/wo30

Notice that <property /> graciously ignores non-existent files. You
may also want to put those <property /> tasks  directly below <project
/> to ensure that your properties are set before *any* target is
executed. Btw, you should also assert that property JOF is set to
avoid unexpected script behavior.

// Wolfgang




On Mon, Jun 6, 2011 at 7:33 PM, Brian McCann <bmccann01@comcast.net> wrote:
> 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
>
>



-- 
Wolfgang Häfelinger
häfelinger IT - Applied Information Technology
http://www.haefelinger.it

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


Mime
View raw message