Hi,
thank you very much for this detailed answer. I hope to satisfy all your
points. I have a context-diff with full-javadoc, testdata and junit-testcase.
Caused by the immutable-rule in ANT it is not really testable, because the value of properties doesn't change between the first and the second execution of targets and tasks. So you only mention a differnce in the implementations if you use the Variable-Ant-Task (from ant-contrib.sf.net) or with the Available-Ant-Task which can overwrite existing properties.
One unclear points is left:
Why doesn't work a reconfigure with a sequential-Task or in generall with Task-Container-Task as expected. This containers never walk through their childs (not after line 436 in RuntimeConfigurable).
-- Michael Augustin
Index: src/main/org/apache/tools/ant/RuntimeConfigurable.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
retrieving revision 1.54
diff -c -r1.54 RuntimeConfigurable.java
*** src/main/org/apache/tools/ant/RuntimeConfigurable.java 27 Sep 2004
09:03:17 -0000 1.54
--- src/main/org/apache/tools/ant/RuntimeConfigurable.java 9 Dec 2004
23:19:57 -0000
***************
*** 341,346 ****
--- 341,375 ----
* an element which doesn't accept it.
*/
public void maybeConfigure(Project p, boolean configureChildren)
+ throws BuildException
+ {
+ maybeConfigure(p, configureChildren, false);
+ }
+
+ /**
+ * Configures the wrapped element. The attributes and text for
+ * the wrapped element are configured. Each time the wrapper is
+ * configured, the attributes and text for it are reset.
+ *
+ * If the element has an <code>id</code> attribute, a reference
+ * is added to the project as well.
+ *
+ * @param p The project containing the wrapped element.
+ * Must not be <code>null</code>.
+ *
+ * @param configureChildren Whether to configure child elements as
+ * well. if true, child elements will be configured after the
+ * wrapped element.
+ *
+ * @param reconfigure This param should be true, if we are called
+ * from [EMAIL PROTECTED] #reconfigure(Project)} method, so we can tell it
+ * our children.
+ *
+ * @exception BuildException if the configuration fails, for instance due
+ * to invalid attributes or children, or text being added to
+ * an element which doesn't accept it.
+ */
+ public void maybeConfigure(Project p, boolean configureChildren, boolean
reconfigure)
throws BuildException {
String id = null;
***************
*** 398,410 ****
while (e.hasMoreElements()) {
RuntimeConfigurable child
= (RuntimeConfigurable) e.nextElement();
if (child.wrappedObject instanceof Task) {
! Task childTask = (Task) child.wrappedObject;
childTask.setRuntimeConfigurableWrapper(child);
}
if ((child.creator != null) && configureChildren) {
! child.maybeConfigure(p);
child.creator.store();
continue;
}
--- 427,451 ----
while (e.hasMoreElements()) {
RuntimeConfigurable child
= (RuntimeConfigurable) e.nextElement();
+ Task childTask = null;
if (child.wrappedObject instanceof Task) {
! childTask = (Task) child.wrappedObject;
childTask.setRuntimeConfigurableWrapper(child);
}
if ((child.creator != null) && configureChildren) {
! // call reconfigure also for children
! if (reconfigure == true) {
! if (childTask != null)
! childTask.reconfigure();
! else
! child.reconfigure(p);
! } else {
! if (childTask != null)
! childTask.maybeConfigure();
! else
! child.maybeConfigure(p);
! }
child.creator.store();
continue;
}
***************
*** 416,426 ****
* For TaskContainers, we simply skip configuration here.
*/
String tag = child.getElementTag().toLowerCase(Locale.US);
! if (configureChildren
! && ih.supportsNestedElement(tag)) {
! child.maybeConfigure(p);
! ProjectHelper.storeChild(p, target, child.wrappedObject,
! tag);
}
}
--- 457,476 ----
* For TaskContainers, we simply skip configuration here.
*/
String tag = child.getElementTag().toLowerCase(Locale.US);
! if (configureChildren && ih.supportsNestedElement(tag)) {
! // call reconfigure also for children
! if (reconfigure == true) {
! if (childTask != null)
! childTask.reconfigure();
! else
! child.reconfigure(p);
! } else {
! if (childTask != null)
! childTask.maybeConfigure();
! else
! child.maybeConfigure(p);
! ProjectHelper.storeChild(p, target, child.wrappedObject,
tag);
! }
}
}
***************
*** 432,443 ****
/**
* Reconfigure the element, even if it has already been configured.
*
* @param p the project instance for this configuration.
*/
public void reconfigure(Project p) {
proxyConfigured = false;
! maybeConfigure(p);
}
--- 482,497 ----
/**
* Reconfigure the element, even if it has already been configured.
+ * That way variables (modifyable properties) could be evaluated again,
+ * before perfoming task again.
*
* @param p the project instance for this configuration.
*/
public void reconfigure(Project p) {
proxyConfigured = false;
!
! // call reconfigure also for children
! maybeConfigure(p, true, true);
}
Index: src/etc/testcases/core/reconfigure.xml
===================================================================
RCS file: src/etc/testcases/core/reconfigure.xml
diff -N src/etc/testcases/core/reconfigure.xml
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- src/etc/testcases/core/reconfigure.xml 1 Jan 1970 00:00:00 -0000
***************
*** 0 ****
--- 1,37 ----
+ <?xml version="1.0"?>
+
+ <project name="reconfigure-test" basedir="." default="test1">
+
+ <target name="set">
+ <property name="test" value="original"/>
+ </target>
+
+ <target name="modify">
+ <available file="reconfigure.xml" property="test" value="override"/>
+ </target>
+
+ <target name="echo">
+ <echo message="Value of test=${test}"/>
+ </target>
+
+ <target name="childProblem">
+ <echo>One line only.</echo>
+ </target>
+
+ <target name="childProblemSolved">
+ <NewEcho>One line only.</NewEcho>
+ </target>
+
+ <target name="container">
+ <sequential>
+ <echo>One line only.</echo>
+ </sequential>
+ </target>
+
+ <target name="containerNew">
+ <sequential>
+ <NewEcho>One line only.</NewEcho>
+ </sequential>
+ </target>
+
+ </project>
Index: src/testcases/org/apache/tools/ant/ReconfigureTest.java
===================================================================
RCS file: src/testcases/org/apache/tools/ant/ReconfigureTest.java
diff -N src/testcases/org/apache/tools/ant/ReconfigureTest.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- src/testcases/org/apache/tools/ant/ReconfigureTest.java 1 Jan 1970
00:00:00 -0000
***************
*** 0 ****
--- 1,154 ----
+ /*
+ * Copyright 2001,2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+ package org.apache.tools.ant;
+
+ import org.apache.tools.ant.taskdefs.Echo;
+
+ import junit.framework.TestCase;
+
+ /**
+ * @author Michael Augustin
+ *
+ * Test the reconfigure-method.
+ */
+ public class ReconfigureTest extends BuildFileTest {
+
+ /**
+ * @param name
+ */
+ public ReconfigureTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ junit.swingui.TestRunner.run(ReconfigureTest.class);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/core/reconfigure.xml");
+ getProject().addTaskDefinition("NewEcho", NewEcho.class);
+ }
+
+ public void testWithoutReconfigure() {
+ executeTarget("set");
+ expectLog("echo", "Value of test=original");
+ executeTarget("modify");
+ expectLog("echo", "Value of test=original");
+ }
+
+ public void testWithReconfigure() {
+ executeTarget("set");
+ expectLog("echo", "Value of test=original");
+ executeTarget("modify");
+
+ reconfigure("echo");
+
+ expectLog("echo", "Value of test=override");
+ }
+
+ public void testReconfigureProblem() {
+ String tn = "childProblem";
+
+ expectLog(tn, "One line only.");
+ expectLog(tn, "One line only.");
+
+ reconfigure(tn);
+ executeTarget(tn);
+ String log = getLog();
+ assertTrue(! log.equals("One line only."));
+ assertTrue(log.equals("One line only.One line only."));
+
+ reconfigure(tn);
+ executeTarget(tn);
+ log = getLog();
+ assertTrue("Each reconfigure adds the text again to the task.",
log.equals("One line only.One line only.One line only."));
+ }
+
+ public void testReconfigureProblemSolved() {
+ String tn = "childProblemSolved";
+
+ expectLog(tn, "One line only.");
+ expectLog(tn, "One line only.");
+
+ reconfigure(tn);
+ executeTarget(tn);
+ String log = getLog();
+ assertTrue(log.equals("One line only."));
+
+ reconfigure(tn);
+ executeTarget(tn);
+ log = getLog();
+ assertTrue("Each reconfigure doesnt add text.", log.equals("One
line only."));
+ }
+
+ // public void testReconfigureContainer() {
+ // String tn = "container";
+ //
+ // expectLog(tn, "One line only.");
+ // expectLog(tn, "One line only.");
+ //
+ // reconfigure(tn);
+ // executeTarget(tn);
+ // String log = getLog();
+ // assertTrue(log.equals("One line only."));
+ //
+ // reconfigure(tn);
+ // executeTarget(tn);
+ // log = getLog();
+ // assertTrue(log.equals("One line only.One line only.One line
only."));
+ // }
+ //
+ // public void testReconfigureContainerNew() {
+ // String tn = "containerNew";
+ //
+ // expectLog(tn, "One line only.");
+ // expectLog(tn, "One line only.");
+ //
+ // reconfigure(tn);
+ // executeTarget(tn);
+ // String log = getLog();
+ // assertTrue(log.equals("One line only."));
+ //
+ // reconfigure(tn);
+ // executeTarget(tn);
+ // log = getLog();
+ // assertTrue("Each reconfigure doesnt add text.", log.equals("One
line only."));
+ // }
+
+ private void reconfigure(String target)
+ {
+ Target t = (Target)getProject().getTargets().get(target);
+ Task[] tasks = t.getTasks();
+ for (int i=0; i<tasks.length; i++)
+ {
+ tasks[i].reconfigure();
+ }
+ }
+
+ public static class NewEcho extends Echo
+ {
+ /* (non-Javadoc)
+ * @see org.apache.tools.ant.Task#reconfigure()
+ */
+ public void reconfigure() {
+ // clear message before added again on reconfigure
+ super.setMessage("");
+
+ super.reconfigure();
+ }
+ }
+ }--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
