jstrachan 2002/11/25 06:31:56 Modified: jelly/src/test/org/apache/commons/jelly/ant suite.jelly jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java Log: Patch and test case for the use case brought up by Stefan recently that an Ant Task can be nested inside a TaskContainer (typically this is also a Task) such as the parallel task. Revision Changes Path 1.5 +51 -0 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/suite.jelly Index: suite.jelly =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/suite.jelly,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- suite.jelly 21 Nov 2002 12:41:23 -0000 1.4 +++ suite.jelly 25 Nov 2002 14:31:56 -0000 1.5 @@ -97,6 +97,7 @@ </ant:copy> <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + <ant:delete file="${basedir}/target/tmp/ant-tests/output.txt"/> <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> @@ -118,6 +119,56 @@ </ant:copy> <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + <ant:delete file="${basedir}/target/tmp/ant-tests/output.txt"/> + + <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> + +</test:case> + + +<test:case name="parallelCopy"> + + <ant:mkdir dir="${base.dir}/target/tmp/ant-tests"/> + + <ant:parallel> + <ant:copy + overwrite="true" + file="${basedir}/src/test/org/apache/commons/jelly/ant/sample.txt" + tofile="${basedir}/target/tmp/ant-tests/output.txt"> + <ant:filterset> + <ant:filter token="foo" value="bar"/> + </ant:filterset> + </ant:copy> + <ant:echo>Performing copy in parallel</ant:echo> + </ant:parallel> + + <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + <ant:delete file="${basedir}/target/tmp/ant-tests/output.txt"/> + + <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> + +</test:case> + +<test:case name="parallelCopyWithReference"> + + <ant:mkdir dir="${base.dir}/target/tmp/ant-tests"/> + + <ant:filterset id="myFilter"> + <ant:filter token="foo" value="bar"/> + </ant:filterset> + + <ant:parallel> + <ant:copy + overwrite="true" + file="${basedir}/src/test/org/apache/commons/jelly/ant/sample.txt" + tofile="${basedir}/target/tmp/ant-tests/output.txt"> + <ant:filterset refid="myFilter"/> + </ant:copy> + <ant:echo>Performing copy in parallel</ant:echo> + </ant:parallel> + + <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + <ant:delete file="${basedir}/target/tmp/ant-tests/output.txt"/> <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> 1.20 +8 -11 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java Index: AntTag.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTag.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- AntTag.java 21 Nov 2002 12:41:23 -0000 1.19 +++ AntTag.java 25 Nov 2002 14:31:56 -0000 1.20 @@ -82,6 +82,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.TaskAdapter; +import org.apache.tools.ant.TaskContainer; import org.apache.tools.ant.types.DataType; /** @@ -110,9 +111,6 @@ /** Task, if this tag represents a task. */ protected Task task; - /** Does this task have an ID attribute */ - private boolean hasIDAttribute; - /** Construct with a project and tag name. * @@ -151,11 +149,11 @@ //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { - hasIDAttribute = false; Project project = getAntProject(); String tagName = getTagName(); Object parentObject = findBeanAncestor(); - + Object parentTask = findParentTaskObject(); + // lets assume that Task instances are not nested inside other Task instances // for example <manifest> inside a <jar> should be a nested object, where as // if the parent is not a Task the <manifest> should create a ManifestTask @@ -163,7 +161,7 @@ // also its possible to have a root Ant tag which isn't a task, such as when // defining <fileset id="...">...</fileset> - if (findParentTaskSource() == null && + if ( (parentTask == null || parentTask instanceof TaskContainer) && project.getTaskDefinitions().containsKey( tagName )) { if ( log.isDebugEnabled() ) { @@ -186,7 +184,6 @@ // set the task ID if one is given Object id = getAttributes().remove( "id" ); if ( id != null ) { - hasIDAttribute = true; project.addReference( (String) id, task ); } @@ -235,7 +232,6 @@ // set the task ID if one is given Object id = getAttributes().remove( "id" ); if ( id != null ) { - hasIDAttribute = true; project.addReference( (String) id, nested ); } @@ -502,13 +498,14 @@ } /** - * Walks the hierarchy until it finds a parent TaskSource or returns null + * Walks the hierarchy until it finds a parent TaskSource and returns its source or returns null */ - protected TaskSource findParentTaskSource() throws Exception { + protected Object findParentTaskObject() throws Exception { Tag tag = getParent(); while (tag != null) { if (tag instanceof TaskSource) { - return (TaskSource) tag; + TaskSource source = (TaskSource) tag; + return source.getTaskObject(); } tag = tag.getParent(); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>