> From: Charl Gerber [mailto:[EMAIL PROTECTED]
> Set a global variable 'env' in my ant script based on:
> the command line value, if not set, then
> environment variable value, if not set, then
> default value
> 
> I have this in my project root, ie, not in a target,
> but it does not work:
> 
> <project...
> 
>   <property environment="ENV" />
> 
>   <target name="set.build.environment">
>       <antcall target="check.environment.env" />
>       <property name="env" value="LOC" />
>   </target>
>   <target name="check.environment.env"
>           if="ENV.env">
>       <property name="env" value="${ENV.env}"/>
>   </target>
> 
> The 'env' properties in these contexts are not visible
> outside the targets and only set locally. Ie, I cannot
> set a global property this way. I aslo cannot find a
> way to do an "if-then-else" in the project root.
> 
> Suggestions?

<antcall> opens it's own scope for properties, which are then
lost when it returns. Use this logic:

<!-- 1) env property set on command line always wins -->

<!-- 2) If 'env' env. var. defined, use it -->
<property environment="ENV" />
<condition property="env" value="${ENV.env}">
  <isset property="ENV.env" />
</condition>

<!-- 3) Default value if neiher set on command line, or env. var. -->
<property name="env" value="LOC" />

--DD

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to