peterreilly 2003/10/24 03:16:17 Modified: . build.xml src/etc/testcases/taskdefs antlib.xml src/main/org/apache/tools/ant/taskdefs Definer.java src/testcases/org/apache/tools/ant/taskdefs AntlibTest.java Added: src/etc/testcases/taskdefs test2.antlib.xml Log: Allow typedef resource to pick up all the resources of the name in the classloader, not just the first PR: 24024 Obtained from: Jesse Glick Revision Changes Path 1.401 +7 -0 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.400 retrieving revision 1.401 diff -u -r1.400 -r1.401 --- build.xml 22 Oct 2003 09:23:34 -0000 1.400 +++ build.xml 24 Oct 2003 10:16:16 -0000 1.401 @@ -1339,6 +1339,13 @@ <selector refid="conditional-patterns"/> </javac> + + <!-- Used by AntlibTest.testAntlibResource: --> + <jar jarfile="${build.tests}/org/apache/tools/ant/taskdefs/test2-antlib.jar"> + <zipfileset dir="${tests.etc.dir}" fullpath="taskdefs/test.antlib.xml"> + <include name="taskdefs/test2.antlib.xml"/> + </zipfileset> + </jar> </target> <target name="dump-info" depends="dump-sys-properties,run-which"/> 1.4 +16 -0 ant/src/etc/testcases/taskdefs/antlib.xml Index: antlib.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/antlib.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- antlib.xml 17 Sep 2003 16:17:56 -0000 1.3 +++ antlib.xml 24 Oct 2003 10:16:16 -0000 1.4 @@ -14,6 +14,22 @@ <mytask/> </target> + <target name="antlib.resource"> + <typedef resource="taskdefs/test.antlib.xml"> + <classpath> + <!-- To load the task classes: --> + <path refid="testclasses"/> + <!-- For test.antlib.xml: --> + <pathelement location=".."/> + <!-- For test2.antlib.xml: --> + <pathelement location="${testcases.dir}/org/apache/tools/ant/taskdefs/test2-antlib.jar"/> + </classpath> + </typedef> + <mytask/> + <echo>-and-then-</echo> + <mytask2/> + </target> + <target name="ns.current"> <typedef file="antlib.current-test.xml" uri="abc"/> <x:useecho2 xmlns:x="abc"/> 1.1 ant/src/etc/testcases/taskdefs/test2.antlib.xml Index: test2.antlib.xml =================================================================== <?xml version="1.0"?> <antlib> <typedef name="mytask2" onerror="ignore" classname="org.apache.tools.ant.taskdefs.AntlibTest$MyTask2"/> </antlib> 1.45 +41 -19 ant/src/main/org/apache/tools/ant/taskdefs/Definer.java Index: Definer.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- Definer.java 22 Sep 2003 08:58:58 -0000 1.44 +++ Definer.java 24 Oct 2003 10:16:17 -0000 1.45 @@ -60,6 +60,7 @@ import java.net.URL; import java.util.Enumeration; import java.util.Locale; +import java.util.NoSuchElementException; import java.util.Properties; import org.apache.tools.ant.AntTypeDefinition; @@ -217,26 +218,40 @@ + "together with file or resource."; throw new BuildException(msg, getLocation()); } - URL url = null; + Enumeration/*<URL>*/ urls = null; if (file != null) { - url = fileToURL(); - } - if (resource != null) { - url = resourceToURL(al); + final URL url = fileToURL(); + urls = new Enumeration() { + private boolean more = true; + public boolean hasMoreElements() { + return more; + } + public Object nextElement() throws NoSuchElementException { + if (more) { + more = false; + return url; + } else { + throw new NoSuchElementException(); + } + } + }; + } else { + urls = resourceToURLs(al); } - if (url == null) { - return; - } + while (urls.hasMoreElements()) { + URL url = (URL) urls.nextElement(); - if (url.toString().toLowerCase(Locale.US).endsWith(".xml")) { - format = Format.XML; - } - - if (format == Format.PROPERTIES) { - loadProperties(al, url); - } else { - loadAntlib(al, url); + int format = this.format; + if (url.toString().toLowerCase(Locale.US).endsWith(".xml")) { + format = Format.XML; + } + + if (format == Format.PROPERTIES) { + loadProperties(al, url); + } else { + loadAntlib(al, url); + } } } } @@ -259,9 +274,16 @@ } } - private URL resourceToURL(ClassLoader classLoader) { - URL ret = classLoader.getResource(resource); - if (ret == null) { + private Enumeration/*<URL>*/ resourceToURLs(ClassLoader classLoader) { + Enumeration ret; + try { + ret = classLoader.getResources(resource); + } catch (IOException e) { + throw new BuildException( + "Could not fetch resources named " + resource, + e, getLocation()); + } + if (!ret.hasMoreElements()) { if (onError != OnError.IGNORE) { log("Could not load definitions from resource " + resource + ". It could not be found.", 1.4 +15 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java Index: AntlibTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AntlibTest.java 17 Sep 2003 16:17:56 -0000 1.3 +++ AntlibTest.java 24 Oct 2003 10:16:17 -0000 1.4 @@ -73,6 +73,15 @@ public void testAntlibFile() { expectLog("antlib.file", "MyTask called"); } + + /** + * Confirms that all matching resources will be used, so that you + * can collect several antlibs in one Definer call. + * @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=24024" + */ + public void testAntlibResource() { + expectLog("antlib.resource", "MyTask called-and-then-MyTask2 called"); + } public void testNsCurrent() { expectLog("ns.current", "Echo2 inside a macroHello from x:p"); @@ -81,6 +90,12 @@ public static class MyTask extends Task { public void execute() { log("MyTask called"); + } + } + + public static class MyTask2 extends Task { + public void execute() { + log("MyTask2 called"); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]