ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Double-expansion - reading environment variables "dynamically"?
Date Mon, 07 Jul 2003 10:42:26 GMT
Or you may try propertycopy from
http://sourceforge.net/projects/ant-contrib/

    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    <property environment="env"/>
    <property name="x" value="ANT_HOME"/>
    <propertycopy name="v" from="env.${x}"/>
    <echo>v is ${v}</echo>

Peter.

On Mon, 2003-07-07 at 10:18, Antoine Levy-Lambert wrote:
> Hi Morten,
> 
> this is a first answer.
> 
> Because this uses script, you will need to download js.jar and bsf.jar
> 
> If you are using ant 1.5.3 refer to installing ant / library dependencies in
> your manual or
> http://ant.apache.org/manual/install.html#librarydependencies
> 
> If you are working with ant 1.6 alpha, read this
> from the ant documentation in CVS head (install.html) :
> - bsf.jar script task
> Note: Ant 1.6 and later require Apache BSF, not the IBM version. I.e. you
> need BSF 2.3.0-rc1 or later. http://jakarta.apache.org/bsf/
> 
> - js.jar Javascript with script task
> If you use Apache BSF 2.3.0-rc1, you must use rhino 1.5R3 - later versions
> of BSF work with 1.5R4 as well. www.mozilla.org/rhino
> 
> Cheers
> Antoine
> 
> <project name="dynamicproperty">
>   <property environment="env"/>
>   <property name="envvar" value="ANT_HOME"/>
>   <script language="javascript"> <![CDATA[
>      project.setProperty("envvarvalue", project.getProperty("env."+
> project.getProperty("envvar")));
>         ]]> </script>
>   <echo message="${envvarvalue}"/>
> </project>
> ----- Original Message -----
> From: "Morten Mortensen" <morten.mortensen@tietoenator.com>
> To: <user@ant.apache.org>
> Sent: Sunday, July 06, 2003 5:30 AM
> Subject: Q: Double-expansion - reading environment variables "dynamically"?
> 
> 
> >
> > Given a defined property "x" assigned the name of an environment-variable,
> > how do I read the value of the environment-variable?
> >
> >
> > I can read the environment-variable "XXX_HOME" by introducing the
> > environment as "env" and using "${env.XXX_HOME}" in my Ant-file.
> >
> > But what if "XXX_HOME" is specified as the value of a property?
> >
> >
> > Constructed example:
> >
> >   <target
> >     name="test"
> >   >
> >     <property environment="env"/>
> >
> >     <!-- Property wired here for the example; is to be read by other
> means:
> > -->
> >     <property name="x" value="XXX_HOME"/>
> >
> >     <!-- Gee, does some kind of double-expansion work?: -->
> >     <property name="v" value="${env.${x}}"/>
> >
> >     <!-- Would like to see the value identical to "${env.XXX_HOME}" here:
> > -->
> >     <echo>Result: ${v}</echo>
> >   </target>
> >
> >
> > If anyone knows how to do this, please tell me how.
> >
> >     ?
> >
> > Morten Sabroe Mortensen
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


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


Mime
View raw message