jstrachan 2002/11/21 04:41:24 Modified: jelly maven.xml jelly/src/test/org/apache/commons/jelly/ant suite.jelly jelly/src/java/org/apache/commons/jelly/tags/ant AntTag.java Added: jelly/src/test simplelog.properties jelly/src/test/org/apache/commons/jelly/ant sample.txt Log: I've enabled the JellyUnit test case that Peter wrote and added another to both test for a regular nested <filterset> and one using a refid. Also added a fix for it too! The short answer is the problem was due to treating <filter> as a new task rather than a nested property of <filterset> Again this is due to the complexity of the Ant behaviour. Sometimes Ant tags are meant to be Tasks, sometimes they are meant to be nested properties, and this can get confusing. I think the correct logic right now is that... a tag should be considered task if it is the root node in the tree of Ant tags and the name of the tag is a valid Ant task name, otherwise treat it as a nested property or datatype. So the root tag can be a <filterset id="...">. Also there are times when a task shouldn't be treated as a task but instead as a nested property. e.g. <filter> and <manifest> are tasks but should be treated as nested properties. Revision Changes Path 1.1 jakarta-commons-sandbox/jelly/src/test/simplelog.properties Index: simplelog.properties =================================================================== org.apache.commons.logging.simplelog.defaultlog = info # uncomment this line to turn on debugging #org.apache.commons.logging.simplelog.log.org.apache.commons.jelly = debug 1.47 +0 -15 jakarta-commons-sandbox/jelly/maven.xml Index: maven.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/maven.xml,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- maven.xml 5 Nov 2002 07:45:57 -0000 1.46 +++ maven.xml 21 Nov 2002 12:41:23 -0000 1.47 @@ -539,13 +539,6 @@ </java> </goal> - <goal name="test:discovery" prereqs="jelly-task"> - <java classname="org.apache.commons.jelly.impl.TestTagLibraryResolver" fork="yes"> - <classpath refid="test.classpath"/> - <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/> - </java> - </goal> - <goal name="demo:compactxml" prereqs="jelly-task"> <mkdir dir="build/compactxml"/> @@ -568,14 +561,6 @@ <java classname="org.apache.commons.jelly.Jelly" fork="yes"> <classpath refid="test.classpath"/> <arg value="src/test/org/apache/commons/jelly/benchmark/benchmark.jelly"/> - </java> - </goal> - - <goal name="test:task" prereqs="jelly-task" - description="A simple test case for working with Ant tasks"> - <java classname="org.apache.commons.jelly.Jelly" fork="yes"> - <classpath refid="test.classpath"/> - <arg value="src/test/org/apache/commons/jelly/ant/task/example.jelly"/> </java> </goal> 1.4 +33 -6 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- suite.jelly 16 Oct 2002 12:45:52 -0000 1.3 +++ suite.jelly 21 Nov 2002 12:41:23 -0000 1.4 @@ -2,6 +2,7 @@ <test:suite xmlns:j="jelly:core" xmlns:test="jelly:junit" + xmlns:util="jelly:util" xmlns:ant="jelly:jeez"> <j:set var="dir" value="target/test-classes/org/apache/commons/jelly/ant"/> @@ -82,19 +83,45 @@ </test:case> -<!--test:case name="copy"> - - this is broken, but i'm not sure how to test it. +<test:case name="copy"> + <ant:mkdir dir="${base.dir}/target/tmp/ant-tests"/> + <ant:copy - file="TestCase.java" - tofile="TestCase.txt"> + 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> + + <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + + <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> + +</test:case> + +<test:case name="copyWithReference"> + + <ant:mkdir dir="${base.dir}/target/tmp/ant-tests"/> -</test:case--> + <ant:filterset id="myFilter"> + <ant:filter token="foo" value="bar"/> + </ant:filterset> + + <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> + + <util:loadText var="text" file="${basedir}/target/tmp/ant-tests/output.txt"/> + + <test:assertEquals expected="hello bar how are you?" actual="${text.trim()}"/> + +</test:case> 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/sample.txt Index: sample.txt =================================================================== hello @foo@ how are you? 1.19 +29 -3 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- AntTag.java 12 Nov 2002 08:13:09 -0000 1.18 +++ AntTag.java 21 Nov 2002 12:41:23 -0000 1.19 @@ -109,6 +109,10 @@ /** 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. * @@ -147,6 +151,7 @@ //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { + hasIDAttribute = false; Project project = getAntProject(); String tagName = getTagName(); Object parentObject = findBeanAncestor(); @@ -154,13 +159,17 @@ // 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 + // + // also its possible to have a root Ant tag which isn't a task, such as when + // defining <fileset id="...">...</fileset> - if ( ! ( parentObject instanceof Task ) && - project.getTaskDefinitions().containsKey( tagName ) ) { + if (findParentTaskSource() == null && + project.getTaskDefinitions().containsKey( tagName )) { if ( log.isDebugEnabled() ) { log.debug( "Creating an ant Task for name: " + tagName ); } + // the following algorithm follows the lifetime of a tag // http://jakarta.apache.org/ant/manual/develop.html#writingowntask // kindly recommended by Stefan Bodewig @@ -177,6 +186,7 @@ // set the task ID if one is given Object id = getAttributes().remove( "id" ); if ( id != null ) { + hasIDAttribute = true; project.addReference( (String) id, task ); } @@ -212,7 +222,7 @@ if ( log.isDebugEnabled() ) { log.debug( "Creating a nested object name: " + tagName ); } - + Object nested = createNestedObject( parentObject, tagName ); if ( nested == null ) { @@ -225,6 +235,7 @@ // set the task ID if one is given Object id = getAttributes().remove( "id" ); if ( id != null ) { + hasIDAttribute = true; project.addReference( (String) id, nested ); } @@ -489,4 +500,19 @@ } return getParent(); } + + /** + * Walks the hierarchy until it finds a parent TaskSource or returns null + */ + protected TaskSource findParentTaskSource() throws Exception { + Tag tag = getParent(); + while (tag != null) { + if (tag instanceof TaskSource) { + return (TaskSource) tag; + } + tag = tag.getParent(); + } + return null; + } + }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>