Discussion:
Nested Variables in ANT?
Mattos, John
2004-06-09 14:25:37 UTC
Permalink
Hi All



I'd like to use properties in a target that vary depending on a parameter
sent in... for example instead of



<target name="dev-target">

<echo massage = "${location.dev}>

</target>

<target name="qa-target">

<echo massage = "${location.qa}>

</target>



I have a variable called ${envir} and I'd like to do something like

<target name="general-target">

<echo massage = "${location.${envir}}>

</target>



Can I do anything like this? It doesn't seem to like the nested ${} 's



John
J***@rzf.fin-nrw.de
2004-06-09 14:30:32 UTC
Permalink
See FAQ
http://ant.apache.org/faq.html#propertyvalue-as-name-for-property

Jan
-----Original Message-----
Sent: Wednesday, June 09, 2004 4:26 PM
Subject: Nested Variables in ANT?
Hi All
I'd like to use properties in a target that vary depending on
a parameter
sent in... for example instead of
<target name="dev-target">
<echo massage = "${location.dev}>
</target>
<target name="qa-target">
<echo massage = "${location.qa}>
</target>
I have a variable called ${envir} and I'd like to do something like
<target name="general-target">
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like the nested ${} 's
John
Mattos, John
2004-06-09 14:32:26 UTC
Permalink
What are the external libraries needed and where might I find them?

Thanks for the help!

-----Original Message-----
From: ***@rzf.fin-nrw.de [mailto:***@rzf.fin-nrw.de]
Sent: Wednesday, June 09, 2004 10:31 AM
To: ***@ant.apache.org
Subject: RE: Nested Variables in ANT?

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

Jan
-----Original Message-----
Sent: Wednesday, June 09, 2004 4:26 PM
Subject: Nested Variables in ANT?
Hi All
I'd like to use properties in a target that vary depending on
a parameter
sent in... for example instead of
<target name="dev-target">
<echo massage = "${location.dev}>
</target>
<target name="qa-target">
<echo massage = "${location.qa}>
</target>
I have a variable called ${envir} and I'd like to do something like
<target name="general-target">
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like the nested ${} 's
John
J***@rzf.fin-nrw.de
2004-06-09 14:35:51 UTC
Permalink
http://ant.apache.org/projects.html#antcontrib
-----Original Message-----
Sent: Wednesday, June 09, 2004 4:32 PM
To: Ant Users List
Subject: RE: Nested Variables in ANT?
What are the external libraries needed and where might I find them?
Thanks for the help!
-----Original Message-----
Sent: Wednesday, June 09, 2004 10:31 AM
Subject: RE: Nested Variables in ANT?
See FAQ
http://ant.apache.org/faq.html#propertyvalue-as-name-for-property
Jan
-----Original Message-----
Sent: Wednesday, June 09, 2004 4:26 PM
Subject: Nested Variables in ANT?
Hi All
I'd like to use properties in a target that vary depending on
a parameter
sent in... for example instead of
<target name="dev-target">
<echo massage = "${location.dev}>
</target>
<target name="qa-target">
<echo massage = "${location.qa}>
</target>
I have a variable called ${envir} and I'd like to do something like
<target name="general-target">
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like the
nested ${} 's
John
---------------------------------------------------------------------
Erik Hatcher
2004-06-09 14:50:32 UTC
Permalink
Post by Mattos, John
<target name="dev-target">
<echo massage = "${location.dev}>
</target>
<target name="qa-target">
<echo massage = "${location.qa}>
</target>
I have a variable called ${envir} and I'd like to do something like
<target name="general-target">
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like the nested ${} 's
A cleaner solution is to have a qa.properties file and a dev.properties
file.

<property name="envir" value="dev"/>
<property file="${envir}.properties"/>

To run for QA, use:

ant -Denvir=qa

Place whatever properties need to be different into each of those files
appropriately (location, for example).

Erik
Ivan Ivanov
2004-06-09 14:52:40 UTC
Permalink
It can (almost):

<property name="qa" value="location-qa"
refid="qa.env"/>
<property name="dev" value="location-dev"
refid="dev.env"/>
<property name="envir" value="${dev}"/>
<property name="location" refid="${envir}.env">
<echo>${location}<echo>

If you invoke this it will echo
location-dev.
In you invoke this with ant -Denvir=qa, it will echo
location-qa.

This is a litle bit tricky. A better decision is to
encapsulate your environment specific properties in
properies files, say qa.properties and dev.properties.
In your build.xml file that you do this:
<property name="envir" value="dev"/>
<property file="${envir}.properties">

When you invoke this, it will pickup properties from
dev.properties file.
If you invoke it with ant -Denvir=qa, it will pickup
properties from
qa.properties.

I think that the second is better since, you may found
there there must be more than one property that will
be differen for dev "case" and qa "case". But if you
have only one property to be different (I've had it
once), you can go with first.

HTH Ivan
Post by Mattos, John
Hi All
I'd like to use properties in a target that vary
depending on a parameter
sent in... for example instead of
<target name="dev-target">
<echo massage = "${location.dev}>
</target>
<target name="qa-target">
<echo massage = "${location.qa}>
</target>
I have a variable called ${envir} and I'd like to do
something like
<target name="general-target">
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like
the nested ${} 's
John
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Jack J. Woehr
2004-06-10 17:05:31 UTC
Permalink
Post by Mattos, John
Hi All
I'd like to use properties in a target that vary depending on a parameter
sent in... for example instead of
<echo massage = "${location.${envir}}>
</target>
Can I do anything like this? It doesn't seem to like the nested ${} 's
Serendipity -- I've submitted a patch for Ant after which Ant behaves in the way you suggest.

If you'd like to try the patch (against the current tree) take a look at bug #29347

http://issues.apache.org/bugzilla/show_bug.cgi?id=29347

--
Jack J. Woehr # We have gone from the horse and buggy
Senior Consultant # to the moon rocket in one lifetime, but
Purematrix, Inc. # there has not been a corresponding moral
www.purematrix.com # growth in mankind. - Dwight D. Eisenhower

Loading...