diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index 3626243d0..13c572cc5 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -85,6 +85,9 @@ public class RuntimeConfigurable implements Serializable { /** the polymorphic type */ private String polyType = null; + /** the "id" of this Element if it has one */ + private String id = null; + /** * Sole constructor creating a wrapper for the specified object. * @@ -130,6 +133,14 @@ public class RuntimeConfigurable implements Serializable { return wrappedObject; } + /** + * Returns the id for this element. + * @return the id. + */ + public synchronized String getId() { + return id; + } + /** * Get the polymorphic type for this element. * @return the ant component type name, null if not set. @@ -176,6 +187,9 @@ public class RuntimeConfigurable implements Serializable { } attributeNames.add(name); attributeMap.put(name, value); + if (name.equals("id")) { + this.id = value; + } } } @@ -346,11 +360,11 @@ public class RuntimeConfigurable implements Serializable { */ public synchronized void maybeConfigure(Project p, boolean configureChildren) throws BuildException { - String id = null; if (proxyConfigured) { return; } + // Configure the object Object target = (wrappedObject instanceof TypeAdapter) ? ((TypeAdapter) wrappedObject).getProxy() : wrappedObject; @@ -388,7 +402,6 @@ public class RuntimeConfigurable implements Serializable { } } } - id = (String) attributeMap.get("id"); } if (characters != null) { diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java index b34d28575..d11fb0e9b 100644 --- a/src/main/org/apache/tools/ant/UnknownElement.java +++ b/src/main/org/apache/tools/ant/UnknownElement.java @@ -175,10 +175,13 @@ public class UnknownElement extends Task { task.setRuntimeConfigurableWrapper(getWrapper()); - // For Script to work. Ugly + // For Script example that modifies id'ed tasks in other + // targets to work. *very* Ugly // The reference is replaced by RuntimeConfigurable - this.getOwningTarget().replaceChild(this, (Task) realThing); - } + if (getWrapper().getId() != null) { + this.getOwningTarget().replaceChild(this, (Task) realThing); + } + } handleChildren(realThing, getWrapper());