You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Peter Vogel <pv...@arsin.com> on 2001/06/18 21:52:54 UTC
PATCH: Attributes of Target can reference properties
--- ProjectHelper.java Fri Jun 8 03:11:27 2001
+++ ProjectHelper.java.new Mon Jun 18 12:39:38 2001
@@ -385,7 +385,8 @@
for (int i = 0; i < attrs.getLength(); i++) {
String key = attrs.getName(i);
- String value = attrs.getValue(i);
+ String value = replaceProperties(project, attrs.getValue(i),
+ project.getProperties());
if (key.equals("name")) {
name = value;
The idea here is to allow dependencies to be somewhat dynamic, for example,
we
have a "targets.xml" file that has things that look like this:
<property name="dist" value="globaldist"/>
<target name="dist" depends="${dist}"/>
<target name="globaldist" depends="build">
....
</target>
<target name="noop"/>
Where a build.xml that does an XML include of target.xml can then
do this before it includes target.xml:
<property name="dist" value="localdist, globaldist"/>
to add some non-default steps to the dist target, or this:
<property name="compile" value="noop"/>
To indicate that there is nothing to compile in this tree...
We find this incredibly powerful for "templating" our build process. It
could be argued that
"real" templates (using XSLT, etc.) are the "right" solution for this, but I
don't want to go into
that argument, and I don't want to wait for ant2 to effectively templatize
my build.
This is a fairly standard sort of pattern when abstracting functionality
into a common set of
files -- to enable a local definition of a target to override a global
definition, since the local
tree obviously knows more about its circumstances than the global stuff.
Since target definition
duplication isn't allowed (as opposed to just silently ignoring the second
definition of a target,
for example) and would be truly ugly if it were, this seems the most
effective method of following
this sort of build design pattern.
Thanks!
-Peter
Re: PATCH: Attributes of Target can reference properties
Posted by Peter Donald <do...@apache.org>.
On Tue, 19 Jun 2001 16:47, Stefan Bodewig wrote:
> Peter,
>
> I've proposed something like your patch back in December 2000 - see
> <http://marc.theaimsgroup.com/?t=97669669300001&w=2&r=1>.
>
> Most people didn't have problems to expand properties for target's
> attributes at parser time (that is, only properties that have been
> defined at the same level as targets and be placed before this target
> would be expanded) - and this is what your patch does. But this may
> not be what people expect. Given
>
> <target name="set">
> <property name="dep" value=", foo">
> </target>
>
> <target name="bar" depends="set ${dep}">
Wan't the recomended way of doing this something like
<target name="bar" depends="dep1,dep2,dep3,dep4"/>
<target name="dep1" depends="set" if="do.dep1"/>
<target name="dep2" depends="set" if="do.dep2"/>
<target name="dep3" depends="set" if="do.dep3"/>
<target name="dep4" depends="set" if="do.dep4"/>
<target name="set">
<property name="do.dep${depend}" value="true">
</target>
Cheers,
Pete
*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof." |
| - John Kenneth Galbraith |
*-----------------------------------------------------*
Re: PATCH: Attributes of Target can reference properties
Posted by Stefan Bodewig <bo...@apache.org>.
Peter,
I've proposed something like your patch back in December 2000 - see
<http://marc.theaimsgroup.com/?t=97669669300001&w=2&r=1>.
Most people didn't have problems to expand properties for target's
attributes at parser time (that is, only properties that have been
defined at the same level as targets and be placed before this target
would be expanded) - and this is what your patch does. But this may
not be what people expect. Given
<target name="set">
<property name="dep" value=", foo">
</target>
<target name="bar" depends="set ${dep}">
wouldn't resolve dep. We cannot allow dynamic expansion of the
property as this implies we'd have to rebuild the target dependency
graph. Even worse, we might start building a project which has an
illegal build file (dep points to a target that in turn depends on bar
- so we have a cycle in the dependency graph that we couldn't detect
before we actually try to run target bar).
But you don't want dynamic property expansion either.
The problem here is, that we have moved property expansion from parser
time to runtime in Ant 1.2 (at least for tasks) and from the users
point of view targets will be executed at some point in time, but this
is not parser time. This may be inconsistent, or not - don't know.
It probably is just a matter of proper documentation.
Finally, you are not only expanding properties in the depends
attribute, but also for the if/unless attributes - which is fine with
me, but users will expect runtime instead of parser time here! - and
the name attribute - which I'd -1 because it doesn't add any value
(except obfuscation).
All in all, I support parser time evaluation of the depends attribute
and the if/unless attributes - the later could be runtime evaluated,
but this would make things even less consistent.
Stefan