You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Christoph Thommes <ct...@gmx.net> on 2002/03/05 12:55:54 UTC

Environment Variable Retrieval in Future Ant Versions

I would like to read an environment variable on a Windows machine, for
example SystemRoot.

Since the environment variable retrieval in Ant is case-sensitive, I cannot
be sure that 

<property environment="env" />
<property name="SystemRoot" value="${env.SystemRoot}" />

will always return a value. I, therefore, would like to have a default
value, if no value is available.

In Ant1.4.1 I am using the following code to accomplish this:

<?xml version="1.0"?>
<project name="test_env" default="all" basedir=".">
        <target name="all">
                <property environment="env" />
                <property name="tmp.SystemRoot" value="${env.SystemRoot}" />
                <condition property="SystemRoot" value="C:\WINNT">
                        <and>
                                <equals arg1="${tmp.SystemRoot}"
arg2="$${env.SystemRoot}"/>
                        </and>
                </condition>
                <property name="SystemRoot" value="${tmp.SystemRoot}" />
                <echo message="SystemRoot: ${SystemRoot}" />    
        </target>
</project>

Is the condition statement going to work the same way in future versions of
Ant (1.5+)?

Christoph

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Environment Variable Retrieval in Future Ant Versions

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 5 Mar 2002, Christoph Thommes <ct...@gmx.net> wrote:
> I would like to read an environment variable on a Windows machine,
> for example SystemRoot.
> 
> Since the environment variable retrieval in Ant is case-sensitive, I
> cannot be sure that
> 
> <property environment="env" />
> <property name="SystemRoot" value="${env.SystemRoot}" />
> 
> will always return a value. I, therefore, would like to have a
> default value, if no value is available.

Simply assign your default value to env.SystemRoot after the
<property environment="env" /> - if no environment varibale of that
name has been defined, Ant will set your defauklt value.  Otherwise it
won't override the original value.

> Is the condition statement going to work the same way in future
> versions of Ant (1.5+)?

No.

But you could do

<condition property="SystemRoot" value="${env.SystemRoot}">
  <isset property="env.SystemRoot" />
</condition>
<property name="SystemRoot" value="your-default-value" />

taking advantage of <property> not overriding existing properties.

The Ant 1.4.1 way would be

<condition property="SystemRoot" value="${env.SystemRoot}">
  <not>
    <equals arg1="${env.SystemRoot}" arg2="$${env.SystemRoot}" />
  </not>
</condition>
<property name="SystemRoot" value="your-default-value" />

I'd stick with 

<property environment="env" />
<property name="env.SystemRoot" value="your-default-value" />

and use ${env.SystemRoot} through the whole build.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Environment Variable Retrieval in Future Ant Versions

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Man, there sure is a lot of confusion about how to use properties properly
in Ant.... somebody oughta write a book about this stuff...

Replace everything you have below with this:

<property environment="env" />
<property name="env.SystemRoot" value="C:\WINNT">
<property name="SystemRoot" value="${env.SystemRoot}" />

Explanation: properties are immutable.  If env.SystemRoot is set from the
first line above then the second "assignment" is ignored.

    Erik



----- Original Message -----
From: "Christoph Thommes" <ct...@gmx.net>
To: <an...@jakarta.apache.org>
Sent: Tuesday, March 05, 2002 6:55 AM
Subject: Environment Variable Retrieval in Future Ant Versions


>
> I would like to read an environment variable on a Windows machine, for
> example SystemRoot.
>
> Since the environment variable retrieval in Ant is case-sensitive, I
cannot
> be sure that
>
> <property environment="env" />
> <property name="SystemRoot" value="${env.SystemRoot}" />
>
> will always return a value. I, therefore, would like to have a default
> value, if no value is available.
>
> In Ant1.4.1 I am using the following code to accomplish this:
>
> <?xml version="1.0"?>
> <project name="test_env" default="all" basedir=".">
>         <target name="all">
>                 <property environment="env" />
>                 <property name="tmp.SystemRoot" value="${env.SystemRoot}"
/>
>                 <condition property="SystemRoot" value="C:\WINNT">
>                         <and>
>                                 <equals arg1="${tmp.SystemRoot}"
> arg2="$${env.SystemRoot}"/>
>                         </and>
>                 </condition>
>                 <property name="SystemRoot" value="${tmp.SystemRoot}" />
>                 <echo message="SystemRoot: ${SystemRoot}" />
>         </target>
> </project>
>
> Is the condition statement going to work the same way in future versions
of
> Ant (1.5+)?
>
> Christoph
>
> --
> GMX - Die Kommunikationsplattform im Internet.
> http://www.gmx.net
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>