You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by da...@cartridgeorder.com on 2011/01/25 22:32:37 UTC

Possible to dynamically reference a property?

Hi,

I'm using Ant 1.8.  I load a properties file that loads define these properties ...

dev.baseurl=http://devurl
qa.baseurl=http://qaurl
approval.baseurl=http://approvalurl
staging.baseurl=http://stagingurl
prod.baseurl=http://produrl

Then I pass in this command line argument to my script "-Denv=...".  So, in my ant script, how do I dynamically access a property using the ${env} param?  For example, if "-Denv=dev" is passed in to the command line, what is a generic way of accessing the property, "dev.baseurl"?

Thanks, - Dave

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


Re: Possible to dynamically reference a property?

Posted by da...@cartridgeorder.com.
Cool.  I went the macrodef route and everything worked

        <macrodef name="propertycopy">
                <attribute name="name"/>
                <attribute name="from"/>
                <sequential>
                        <property name="@{name}" value="${@{from}}"/>
                </sequential>
        </macrodef>
        <property name="baseurl.prop" value="selenium.vlv.${buildtarget}.baseurl"/>
        <propertycopy name="baseurl" from="${baseurl.prop}"/>


 - Dave




>  -------Original Message-------
>  From: Dominique Devienne <dd...@gmail.com>
>  To: Ant Users List <us...@ant.apache.org>, dave.alvarado@cartridgeorder.com
>  Subject: Re: Possible to dynamically reference a property?
>  Sent: Jan 25 '11 16:16
>  
>  On Tue, Jan 25, 2011 at 4:10 PM,  <da...@cartridgeorder.com> wrote:
>  > ON the doc it mentions "external" to ANt ... [...]
>  > So doesn't that mean it would NOT be part of the normal distrib? - Dave
>  
>  You might be right. Sorry, can't help more on this particular topic,
>  as I mentioned I've never done it myself.
>  
>  The easiest is to define the macro to emulate the AntContrib task.
>  That's pure Ant, no dependencies. Or use the <property
>  file="${env}.properties" /> idiom I mentioned. --DD
>  
>  ---------------------------------------------------------------------
>  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


Re: Possible to dynamically reference a property?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jan 25, 2011 at 4:10 PM,  <da...@cartridgeorder.com> wrote:
> ON the doc it mentions "external" to ANt ... [...]
> So doesn't that mean it would NOT be part of the normal distrib? - Dave

You might be right. Sorry, can't help more on this particular topic,
as I mentioned I've never done it myself.

The easiest is to define the macro to emulate the AntContrib task.
That's pure Ant, no dependencies. Or use the <property
file="${env}.properties" /> idiom I mentioned. --DD

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


Re: Possible to dynamically reference a property?

Posted by Matt Benson <gu...@gmail.com>.
On Jan 25, 2011, at 4:27 PM, Dominique Devienne wrote:

> On Tue, Jan 25, 2011 at 4:10 PM,  <da...@cartridgeorder.com> wrote:
>> So doesn't that mean it would NOT be part of the normal distrib? - Dave
> 
> A Google search turned up this post, but he builds it from source,
> http://wdarby.blogspot.com/2010/06/using-antlib-props-in-ant-18.html
> 
> I suppose 'props' can be considered an AntLib (not even sure), but
> there doesn't seem to be an official release since it's not in
> http://www.apache.org/dist/ant/antlibs/
> 

props is an Antlib, it has never seen a formal release, and the blog posting you referenced seems in order.  :)

Matt (primary/only? author of the props Antlib)

> Hope this helps. --DD
> 
> ---------------------------------------------------------------------
> 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


Re: Possible to dynamically reference a property?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jan 25, 2011 at 4:10 PM,  <da...@cartridgeorder.com> wrote:
> So doesn't that mean it would NOT be part of the normal distrib? - Dave

A Google search turned up this post, but he builds it from source,
http://wdarby.blogspot.com/2010/06/using-antlib-props-in-ant-18.html

I suppose 'props' can be considered an AntLib (not even sure), but
there doesn't seem to be an official release since it's not in
http://www.apache.org/dist/ant/antlibs/

Hope this helps. --DD

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


Re: Possible to dynamically reference a property?

Posted by da...@cartridgeorder.com.
ON the doc it mentions "external" to ANt ...

With the 'props' antlib (external, but also from Ant) you could do the dereferencing with ${${anotherprop} - not just in the property task - instead everywhere in your buildfile (after registering the required property helper).

<propertyhelper>
  <props:nested />
</propertyhelper>
<property name="foo" value="foo.value" />
<property name="var" value="foo" />
<echo> ${${var}} = foo.value </echo>


So doesn't that mean it would NOT be part of the normal distrib? - Dave


>  -------Original Message-------
>  From: Dominique Devienne <dd...@gmail.com>
>  To: Ant Users List <us...@ant.apache.org>, dave.alvarado@cartridgeorder.com
>  Subject: Re: Possible to dynamically reference a property?
>  Sent: Jan 25 '11 16:08
>  
>  On Tue, Jan 25, 2011 at 3:58 PM,  <da...@cartridgeorder.com> wrote:
>  > Thanks, Dominique.  The nested properties (props) task seems like it will do the job.  However, do you know where to download this thing?  The links don't seem to have anything
>  >
>  > http://ant.apache.org/manual/properties.html
>  > http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
>  
>  props is not a task, but a PropertyHelper extension. I suspect it's
>  part of the normal Ant distrib, so no need to download anything, but
>  I've never used it myself. You could try adding the declaration the
>  FAQ shows to enable it in your own build file and see if it works.
>  --DD
>  

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


Re: Possible to dynamically reference a property?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jan 25, 2011 at 3:58 PM,  <da...@cartridgeorder.com> wrote:
> Thanks, Dominique.  The nested properties (props) task seems like it will do the job.  However, do you know where to download this thing?  The links don't seem to have anything
>
> http://ant.apache.org/manual/properties.html
> http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

props is not a task, but a PropertyHelper extension. I suspect it's
part of the normal Ant distrib, so no need to download anything, but
I've never used it myself. You could try adding the declaration the
FAQ shows to enable it in your own build file and see if it works.
--DD

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


Re: Possible to dynamically reference a property?

Posted by da...@cartridgeorder.com.
Thanks, Dominique.  The nested properties (props) task seems like it will do the job.  However, do you know where to download this thing?  The links don't seem to have anything

http://ant.apache.org/manual/properties.html
http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

 - Dave


>  -------Original Message-------
>  From: Dominique Devienne <dd...@gmail.com>
>  To: Ant Users List <us...@ant.apache.org>, dave.alvarado@cartridgeorder.com
>  Subject: Re: Possible to dynamically reference a property?
>  Sent: Jan 25 '11 15:39
>  
>  On Tue, Jan 25, 2011 at 3:32 PM,  <da...@cartridgeorder.com> wrote:
>  > Then I pass in this command line argument to my script "-Denv=...".  So, in my ant script, how do I dynamically access a property using the ${env} param?  For example, if "-Denv=dev" is passed in to the command line, what is a generic way of accessing the property, "dev.baseurl"?
>  
>  See http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
>  
>  Thanks, --DD
>  
>  ---------------------------------------------------------------------
>  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


Re: Possible to dynamically reference a property?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jan 25, 2011 at 3:39 PM, Dominique Devienne <dd...@gmail.com> wrote:
> On Tue, Jan 25, 2011 at 3:32 PM,  <da...@cartridgeorder.com> wrote:
>> Then I pass in this command line argument to my script "-Denv=...".  So, in my ant script, how do I dynamically access a property using the ${env} param?  For example, if "-Denv=dev" is passed in to the command line, what is a generic way of accessing the property, "dev.baseurl"?
>
> See http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

Note that an alternative is to split your property file into several,
one per "prefix". Then you only have to <property
file="${env}.properties" /> and simply refer to the prefix-less
properties 'baseurl'. Put common (or default) properties into another
file yet, and load both in order, keeping in mind that the first
property defined "wins".

There's also <propertyset> which can work with prefixes and remove
them, but I don't think it applies here. --DD

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


Re: Possible to dynamically reference a property?

Posted by Dominique Devienne <dd...@gmail.com>.
On Tue, Jan 25, 2011 at 3:32 PM,  <da...@cartridgeorder.com> wrote:
> Then I pass in this command line argument to my script "-Denv=...".  So, in my ant script, how do I dynamically access a property using the ${env} param?  For example, if "-Denv=dev" is passed in to the command line, what is a generic way of accessing the property, "dev.baseurl"?

See http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

Thanks, --DD

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