ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: overriding references
Date Mon, 03 Nov 2003 08:42:09 GMT
On Fri, 31 Oct 2003, Matt Benson <> wrote:

> What's the rationale for why references can be
> overridden?  This seems to contrast sharply with the
> treatment of properties.

I'm not sure I'll get all historical details right without browsing
through my archives, but let me try:

(1) properties haven't been immutable from the start, they became
immutable more or less by accident sometime before the release of Ant
1.1 and it caused a lot of grief with people who used the version of
Ant that was released with Tomcat 3.0.  <antcall> was invented as
syntactic sugar over <ant> to solve some problems.  In retrospect
macros would have been better, but Ant's core was nowhere near the
shape to allow them.

(2) By the same time, references have already been there but not in
widespread use as we didn't have any data-types in Ant 1.1.  The key
use was <script>, it's probably fair to say that almost nobody looked
at references or even used them.  The "accident" that made properties
immutable never happened to references.

(3) With <path>, <patternset> and <fileset> in Ant 1.2, references
became widely used.  By then, people learned that they had to use
conditionals on <target> to set properties depending on environmental
conditions (it took two more releases to get to <condition>).  They
used the

<target name="set-foo-1" if="a">
  <property name="foo" value="a is set"/>
<target name="set-foo-2" unless="a">
  <property name="foo" value="a is not set"/>
<target name="set-foo" depends="set-foo-1,set-foo-2"/>

style.  Of course, they wanted to be able to do the same for <path>.

And there was the problem, references in Ant get set at parser time in
lexical order.  So in a construct like the above, say

<target name="set-foo-1" if="a">
  <path id="foo" path="a is set"/>
<target name="set-foo-2" unless="a">
  <path id="foo" path="a is not set"/>
<target name="set-foo" depends="set-foo-1,set-foo-2"/>

Ant sets the project reference "foo" to the <path> instance created in
set-foo-1 and triwa to reset it to the instance created in set-foo-2
before running a single target.  When the targets finally get
executed, the reference is set once again.  The only way to allow
references to be set conditionally is to keep them mutable because of
the way Ant works.

In Ant 1.6 you can replace "instance created" with UnknownElement and
the element itself is going to get resolved when the reference is
used, but the reference setting logic is still in place - and has to
remain so for backwards compatibility of some <script> use cases.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message