You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Brad Lyon <ly...@y12.doe.gov> on 2000/10/05 21:39:34 UTC

Without dynamic properties, how are you supposed to ...?

Note: this applies to the latest cvs build of ant, not just 1.1 (which had 
different, but still unuseful, behavior)

The current default behavior for <property>'s is that you can't override 
their values.  So how are you supposed to set a property to different 
values based on whether or not another property is defined?  The way I 
would think you would do it, is something like

<target name ="setpropsA" if="propforA">
	<property name="foo" value ="A">
</target>

<target name="setpropsB" if="propforB">
	<property name="foo" value ="B">
</target>


But this doesn't work, even if property "propforA" is not defined, and 
"propforB" is.  During the initial xml parsing, it apparently sets property 
"foo" to "A" no matter what, and this can't ever be overridden (except 
using the hacked ant I have now, which required just two line changes in 
Property.java).

I'm worried I'm missing the boat somehow.  Am I supposed to be using some 
other method to accomplish what I want?  Something trivial?

Thanks in advance.

-Brad

Cool - Re: Without dynamic properties, how are you supposed to ...?

Posted by Brad Lyon <ly...@y12.doe.gov>.
Thanks for the response, Stefan, and I really wasn't making the problem up 
- at least I didn't think so-  and I did have a couple of versions of ant 
hanging around earlier.  I should have done a simple test like the one you 
included after I got the latest cvs code.  GiddyUp.

-Brad


Re: Without dynamic properties, how are you supposed to ...?

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "BL" == Brad Lyon <ly...@y12.doe.gov> writes:

 BL> Note: this applies to the latest cvs build of ant, not just 1.1
 BL> (which had different, but still unuseful, behavior)

I doubt so. Latest cvs - in fact anything calling itself 1.2alpha2 or
alpha3:

<project name="test" default="all">
  <target name ="setpropsA" if="propforA">
    <property name="foo" value ="A" />
  </target>

  <target name="setpropsB" if="propforB">
    <property name="foo" value ="B" />
  </target>

  <target name="all" depends="setpropsA,setpropsB">
    <echo message="foo has the value ${foo}" />
  </target>
</project>

No property defined:

bodewig@sbodewig /tmp >ant -f test.xml 
Buildfile: test.xml

setpropsA:
setpropsB:
all:
foo has the value ${foo}

Defining the property for A:

bodewig@sbodewig /tmp >ant -f test.xml -DpropforA=1
Buildfile: test.xml

setpropsA:
setpropsB:
all:
foo has the value A

Defining the property for B:

bodewig@sbodewig /tmp >ant -f test.xml -DpropforB=1
Buildfile: test.xml

setpropsA:
setpropsB:
all:
foo has the value B

Make sure the Ant you are really using is the Ant you want to use 8^),
I guess there's an older version lurking in your CLASSPATH.

Stefan