You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mark Soderquist <co...@cosmoworx.com> on 2001/08/09 00:55:35 UTC

Decision making with ANT.

I would like to set the value of a property based on the value of another property.  Specifically I have a variable that is being passed in on the command line with -D.  I need to examine the value of that property and set a different property based on that value.  Is this possible?  If so, how can it be done?

=Mark

Re: Decision making with ANT.

Posted by Stefan Bodewig <bo...@apache.org>.
In addition to Don's response

On Wed, 8 Aug 2001, Mark Soderquist <co...@cosmoworx.com> wrote:

> I would like to set the value of a property based on the value of
> another property.

Using Ant 1.4 from recent nightly builds (or the upcoming beta of
course):

<condition property="my-dependent-property" value="hamstibamsti">
  <equals arg1="${mork}" value="from-ork" />
</condition>

Which will set my-dependent-property to the given value if the
condition holds true.

Stefan

Re: Decision making with ANT.

Posted by Don Taylor <do...@yahoo.com>.
--- Mark Soderquist <co...@cosmoworx.com> wrote:
> I would like to set the value of a property based on the value of
> another property.  Specifically I have a variable that is being
> passed in on the command line with -D.  I need to examine the value
> of that property and set a different property based on that value. 
> Is this possible?  If so, how can it be done?
> 
> =Mark
> 

OK, suppose you have -Dvar=value1 on the Ant command line. Suppose the
values of var could be value1, value2, and value3. Now define a
property to test the value:

<property name="var.${var}" value="true" />

So you need to test var for 3 different values (let's say), and set
another property accordingly. Here's how you do it:

<target name="test-value1" if="var.value1">
   <!-- Define your property here -->
</target>

<target name="test-value2" if="var.value2">
   <!-- Define your property here -->
</target>

<target name="test-value3" if="var.value3">
   <!-- Define your property here -->
</target>

Now to perform the test all you need is:

<target name="set-property"
depends="test-value1,test-value2,test-value3" />

So when the target "set-property" is invoked your property will be set
according to the value of the property you defined on the command line.
Admittedly it's a bit of a kludge, but that's how it's done.

-- Don


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/