git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274402 13f79535-47bb-0310-9956-ffa450edef68master
@@ -302,7 +302,6 @@ | |||
<patternset id="teststhatfail"> | |||
<exclude name="${optional.package}/BeanShellScriptTest.java"/> | |||
<exclude name="${ant.package}/taskdefs/ImportTest.java"/> | |||
<exclude name="${ant.package}/TaskContainerTest.java"/> | |||
</patternset> | |||
<!-- | |||
@@ -57,6 +57,7 @@ import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.TaskContainer; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.types.FileSet; | |||
import org.apache.tools.ant.taskdefs.Echo; | |||
import java.util.*; | |||
public class SpecialSeq extends Task implements TaskContainer { | |||
@@ -65,6 +66,8 @@ public class SpecialSeq extends Task implements TaskContainer { | |||
private FileSet fileset; | |||
private Echo nestedEcho; | |||
/** | |||
* Add a nested task. | |||
* <p> | |||
@@ -79,13 +82,22 @@ public class SpecialSeq extends Task implements TaskContainer { | |||
* Execute all nestedTasks. | |||
*/ | |||
public void execute() throws BuildException { | |||
if (fileset == null || fileset.getDir(getProject()) == null) { | |||
throw new BuildException("Fileset was not configured"); | |||
} | |||
for (Enumeration e = nestedTasks.elements(); e.hasMoreElements();) { | |||
Task nestedTask = (Task) e.nextElement(); | |||
nestedTask.perform(); | |||
} | |||
nestedEcho.reconfigure(); | |||
nestedEcho.perform(); | |||
} | |||
public void addFileset(FileSet fileset) { | |||
this.fileset = fileset; | |||
} | |||
public void addNested(Echo nestedEcho) { | |||
this.nestedEcho = nestedEcho; | |||
} | |||
} |
@@ -22,9 +22,11 @@ | |||
<sequential> | |||
<taskdef name="sseq" classpath="${build.dir}" classname="test.SpecialSeq"/> | |||
<sseq> | |||
<fileset dir="."/> | |||
<property name="foo" value="it worked"/> | |||
<echo message="As attribute: ${foo}"/> | |||
<echo>As nested text: ${foo}</echo> | |||
<nested message="As nested task: ${foo}"/> | |||
</sseq> | |||
</sequential> | |||
</target> | |||
@@ -577,7 +577,8 @@ public class IntrospectionHelper implements BuildListener { | |||
* @return true if the given nested element is supported | |||
*/ | |||
public boolean supportsNestedElement(String elementName) { | |||
return nestedCreators.containsKey(elementName); | |||
return nestedCreators.containsKey(elementName) || | |||
DynamicConfigurator.class.isAssignableFrom(bean); | |||
} | |||
/** | |||
@@ -336,18 +336,9 @@ public class RuntimeConfigurable implements Serializable { | |||
childTask.setRuntimeConfigurableWrapper(child); | |||
} | |||
if (configureChildren) { | |||
if (child.wrappedObject instanceof Task) { | |||
Task childTask = (Task) child.wrappedObject; | |||
// we don't configure tasks of task containers These | |||
// we be configured at the time they are used. | |||
if (!(target instanceof TaskContainer)) { | |||
childTask.maybeConfigure(); | |||
} | |||
} else { | |||
child.maybeConfigure(p); | |||
} | |||
if (configureChildren | |||
&& ih.supportsNestedElement(child.getElementTag())) { | |||
child.maybeConfigure(p); | |||
Object container = wrappedObject; | |||
if (container instanceof TaskAdapter) { | |||
container = ((TaskAdapter) container).getProxy(); | |||
@@ -363,4 +354,12 @@ public class RuntimeConfigurable implements Serializable { | |||
} | |||
proxyConfigured = true; | |||
} | |||
/** | |||
* Reconfigure the element, even if it has already been configured. | |||
*/ | |||
public void reconfigure(Project p) { | |||
proxyConfigured = false; | |||
maybeConfigure(p); | |||
} | |||
} |
@@ -293,6 +293,16 @@ public abstract class Task extends ProjectComponent { | |||
} | |||
} | |||
/** | |||
* Force the task to be reconfigured from it's RuntimeConfigurable | |||
* | |||
*/ | |||
public void reconfigure() { | |||
if (wrapper != null) { | |||
wrapper.reconfigure(getProject()); | |||
} | |||
} | |||
/** | |||
* Handles a line of output by logging it with the INFO priority. | |||
* | |||
@@ -127,12 +127,7 @@ public class UnknownElement extends Task { | |||
if (realThing instanceof Task) { | |||
Task task = (Task) realThing; | |||
task.setProject(project); | |||
task.setRuntimeConfigurableWrapper(getWrapper()); | |||
task.setLocation(this.getLocation()); | |||
// UnknownElement always has an associated target | |||
task.setOwningTarget(this.getOwningTarget()); | |||
task.init(); | |||
// For Script to work. Ugly | |||
// The reference is replaced by RuntimeConfigurable | |||
@@ -272,38 +267,26 @@ public class UnknownElement extends Task { | |||
UnknownElement child = (UnknownElement) children.elementAt(i); | |||
Object realChild = null; | |||
if (!ih.supportsNestedElement(child.getTag()) | |||
&& parent instanceof TaskContainer) { | |||
realChild = makeTask(child, childWrapper); | |||
if (realChild == null) { | |||
ih.throwNotSupported(getProject(), parent, child.getTag()); | |||
} | |||
// XXX DataTypes will be wrapped or treated like normal components | |||
if (realChild instanceof Task) { | |||
Task task = (Task) realChild; | |||
((TaskContainer) parent).addTask(task); | |||
task.setLocation(child.getLocation()); | |||
// UnknownElement always has an associated target | |||
task.setOwningTarget(this.getOwningTarget()); | |||
task.init(); | |||
} else { | |||
// should not happen | |||
ih.throwNotSupported(getProject(), parent, child.getTag()); | |||
} | |||
} else { | |||
if (ih.supportsNestedElement(child.getTag())) { | |||
realChild | |||
= ih.createElement(getProject(), parent, child.getTag()); | |||
} | |||
childWrapper.setProxy(realChild); | |||
if (parent instanceof TaskContainer | |||
&& realChild instanceof Task) { | |||
((Task) realChild).setRuntimeConfigurableWrapper(childWrapper); | |||
} | |||
childWrapper.setProxy(realChild); | |||
if (realChild instanceof Task) { | |||
Task childTask = (Task) realChild; | |||
childTask.setRuntimeConfigurableWrapper(childWrapper); | |||
childTask.setTaskName(child.getTag()); | |||
childTask.setTaskType(child.getTag()); | |||
} | |||
child.handleChildren(realChild, childWrapper); | |||
child.handleChildren(realChild, childWrapper); | |||
} else if (!(parent instanceof TaskContainer)) { | |||
ih.throwNotSupported(getProject(), parent, child.getTag()); | |||
} else { | |||
// a task container - anything could happen - just add the | |||
// child to the container | |||
TaskContainer container = (TaskContainer) parent; | |||
container.addTask(child); | |||
} | |||
} | |||
} | |||
@@ -745,7 +745,6 @@ public class ProjectHelper2 extends ProjectHelper { | |||
AntXMLContext context) | |||
throws SAXParseException { | |||
RuntimeConfigurable parentWrapper = context.currentWrapper(); | |||
RuntimeConfigurable wrapper = null; | |||
Object parent = null; | |||
if (parentWrapper != null) { | |||
@@ -796,7 +795,8 @@ public class ProjectHelper2 extends ProjectHelper { | |||
// container.addTask(task); | |||
// This is a nop in UE: task.init(); | |||
wrapper = new RuntimeConfigurable(task, task.getTaskName()); | |||
RuntimeConfigurable wrapper | |||
= new RuntimeConfigurable(task, task.getTaskName()); | |||
for (int i = 0; i < attrs.getLength(); i++) { | |||
wrapper.setAttribute(attrs.getQName(i), | |||
@@ -852,10 +852,5 @@ public class ProjectHelper2 extends ProjectHelper { | |||
public void onEndElement(String uri, String tag, AntXMLContext context) { | |||
context.popWrapper(); | |||
} | |||
public void onEndChild(String uri, String tag, String qname, | |||
AntXMLContext context) | |||
throws SAXParseException { | |||
} | |||
} | |||
} |
@@ -82,6 +82,8 @@ public class TaskContainerTest extends BuildFileTest { | |||
getLog().indexOf("As attribute: it worked") > -1); | |||
assertTrue("nested text worked", | |||
getLog().indexOf("As nested text: it worked") > -1); | |||
assertTrue("nested text worked", | |||
getLog().indexOf("As nested task: it worked") > -1); | |||
} | |||
} |