antoine 2004/07/27 00:15:11 Modified: src/testcases/org/apache/tools/ant Tag: ANT_16_BRANCH AntClassLoaderTest.java src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH CollectionUtils.java src/main/org/apache/tools/ant Tag: ANT_16_BRANCH AntClassLoader.java . Tag: ANT_16_BRANCH build.xml WHATSNEW Log: Merge from HEAD solve problem : Impossible to use implicit classpath for <taskdef> when Ant core loader != Java application loader and Path.systemClassPath taken from ${java.class.path} PR: 30161 Submitted by: Jesse Glick (jglick at netbeans dot org) Revision Changes Path No revision No revision 1.3.2.5 +65 -2 ant/src/testcases/org/apache/tools/ant/AntClassLoaderTest.java Index: AntClassLoaderTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/AntClassLoaderTest.java,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -u -r1.3.2.4 -r1.3.2.5 --- AntClassLoaderTest.java 9 Mar 2004 17:02:00 -0000 1.3.2.4 +++ AntClassLoaderTest.java 27 Jul 2004 07:15:09 -0000 1.3.2.5 @@ -16,8 +16,20 @@ */ package org.apache.tools.ant; -import org.apache.tools.ant.types.Path; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; import junit.framework.TestCase; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; /** * Test case for ant class loader @@ -70,5 +82,56 @@ fail("loader should not fail even if project finished"); } } + + /** Sample resource present in build/testcases/ */ + private static final String TEST_RESOURCE = "org/apache/tools/ant/IncludeTest.class"; + + public void testFindResources() throws Exception { + //System.err.println("loading from: " + AntClassLoader.class.getProtectionDomain().getCodeSource().getLocation()); + // See bug #30161. + // This path should contain the class files for these testcases: + String buildTestcases = System.getProperty("build.tests"); + assertNotNull("defined ${build.tests}", buildTestcases); + assertTrue("have a dir " + buildTestcases, new File(buildTestcases).isDirectory()); + Path path = new Path(p, buildTestcases); + // A special parent loader which is not the system class loader: + ClassLoader parent = new ParentLoader(); + // An AntClassLoader which is supposed to delegate to the parent and then to the disk path: + ClassLoader acl = new AntClassLoader(parent, p, path, true); + // The intended result URLs: + URL urlFromPath = new URL(FileUtils.newFileUtils().toURI(buildTestcases) + TEST_RESOURCE); + URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE); + assertEquals("correct resources (regular delegation order)", + Arrays.asList(new URL[] {urlFromParent, urlFromPath}), + enum2List(acl.getResources(TEST_RESOURCE))); + acl = new AntClassLoader(parent, p, path, false); + assertEquals("correct resources (reverse delegation order)", + Arrays.asList(new URL[] {urlFromPath, urlFromParent}), + enum2List(acl.getResources(TEST_RESOURCE))); + } + + private static List enum2List(Enumeration e) { + // JDK 1.4: return Collections.list(e); + List l = new ArrayList(); + while (e.hasMoreElements()) { + l.add(e.nextElement()); + } + return l; + } + + /** Special loader that just knows how to find TEST_RESOURCE. */ + private static final class ParentLoader extends ClassLoader { + + public ParentLoader() {} + + protected Enumeration findResources(String name) throws IOException { + if (name.equals(TEST_RESOURCE)) { + return Collections.enumeration(Collections.singleton(new URL("http://ant.apache.org/" + name))); + } else { + return Collections.enumeration(Collections.EMPTY_SET); + } + } + + } + } - No revision No revision 1.10.2.5 +35 -0 ant/src/main/org/apache/tools/ant/util/CollectionUtils.java Index: CollectionUtils.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/CollectionUtils.java,v retrieving revision 1.10.2.4 retrieving revision 1.10.2.5 diff -u -r1.10.2.4 -r1.10.2.5 --- CollectionUtils.java 9 Mar 2004 17:01:57 -0000 1.10.2.4 +++ CollectionUtils.java 27 Jul 2004 07:15:09 -0000 1.10.2.5 @@ -114,4 +114,39 @@ } } + /** + * Append one enumeration to another. + * Elements are evaluated lazily. + * @param e1 the first enumeration + * @param e2 the subsequent enumeration + * @return an enumeration representing e1 followed by e2 + * @since Ant 1.6.3 + */ + public static Enumeration append(Enumeration e1, Enumeration e2) { + return new CompoundEnumeration(e1, e2); + } + + private static final class CompoundEnumeration implements Enumeration { + + private final Enumeration e1, e2; + + public CompoundEnumeration(Enumeration e1, Enumeration e2) { + this.e1 = e1; + this.e2 = e2; + } + + public boolean hasMoreElements() { + return e1.hasMoreElements() || e2.hasMoreElements(); + } + + public Object nextElement() throws NoSuchElementException { + if (e1.hasMoreElements()) { + return e1.nextElement(); + } else { + return e2.nextElement(); + } + } + + } + } No revision No revision 1.76.2.8 +19 -2 ant/src/main/org/apache/tools/ant/AntClassLoader.java Index: AntClassLoader.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/AntClassLoader.java,v retrieving revision 1.76.2.7 retrieving revision 1.76.2.8 diff -u -r1.76.2.7 -r1.76.2.8 --- AntClassLoader.java 28 Jun 2004 07:47:05 -0000 1.76.2.7 +++ AntClassLoader.java 27 Jul 2004 07:15:10 -0000 1.76.2.8 @@ -32,6 +32,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.CollectionUtils; import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.LoaderUtils; @@ -864,8 +865,24 @@ * @return an enumeration of URLs for the resources * @exception IOException if I/O errors occurs (can't happen) */ - protected Enumeration findResources(String name) throws IOException { - return new ResourceEnumeration(name); + protected Enumeration/*<URL>*/ findResources(String name) throws IOException { + Enumeration/*<URL>*/ mine = new ResourceEnumeration(name); + Enumeration/*<URL>*/ base; + if (parent != null && parent != getParent()) { + // Delegate to the parent: + base = parent.getResources(name); + // Note: could cause overlaps in case ClassLoader.this.parent has matches. + } else { + // ClassLoader.this.parent is already delegated to from ClassLoader.getResources, no need: + base = new CollectionUtils.EmptyEnumeration(); + } + if (isParentFirst(name)) { + // Normal case. + return CollectionUtils.append(base, mine); + } else { + // Inverted. + return CollectionUtils.append(mine, base); + } } /** No revision No revision 1.392.2.34 +8 -4 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.392.2.33 retrieving revision 1.392.2.34 diff -u -r1.392.2.33 -r1.392.2.34 --- build.xml 16 Jul 2004 07:25:04 -0000 1.392.2.33 +++ build.xml 27 Jul 2004 07:15:10 -0000 1.392.2.34 @@ -85,6 +85,8 @@ <property name="build.tests" value="${build.dir}/testcases"/> <property name="build.tests.javadocs" value="${build.dir}/javadocs.test/"/> <property name="manifest.tmp" value="${build.dir}/optional.manifest"/> + <!-- the absolute path --> + <property name="build.tests.value" location="${build.tests}"/> <!-- =================================================================== @@ -365,7 +367,7 @@ the java version =================================================================== --> - + <target name="javac.preset" depends="javac.preset.1.5+,javac.preset.1.5-"/> <target name="javac.preset.1.5+" depends="check_for_optional_packages" if="jdk1.5+"> @@ -1454,7 +1456,8 @@ <classpath refid="tests-classpath"/> <sysproperty key="ant.home" value="${ant.home}"/> - <sysproperty key="build.tests" value="${build.tests}"/> + <sysproperty key="build.tests" file="${build.tests}"/> + <sysproperty key="build.tests.value" value="${build.tests.value}"/> <sysproperty key="tests-classpath.value" value="${tests-classpath.value}"/> @@ -1603,7 +1606,8 @@ filtertrace="${junit.filtertrace}"> <!-- <jvmarg value="-classic"/> --> <sysproperty key="ant.home" value="${ant.home}"/> - <sysproperty key="build.tests" value="${build.tests}"/> + <sysproperty key="build.tests" file="${build.tests}"/> + <sysproperty key="build.tests.value" value="${build.tests.value}"/> <sysproperty key="tests-classpath.value" value="${tests-classpath.value}"/> <classpath refid="tests-classpath"/> @@ -1629,4 +1633,4 @@ description="--> creates a minimum distribution in ./dist" depends="dist-lite"/> -</project> +</project> \ No newline at end of file 1.503.2.123 +4 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.503.2.122 retrieving revision 1.503.2.123 diff -u -r1.503.2.122 -r1.503.2.123 --- WHATSNEW 19 Jul 2004 18:22:35 -0000 1.503.2.122 +++ WHATSNEW 27 Jul 2004 07:15:10 -0000 1.503.2.123 @@ -20,6 +20,10 @@ * Target Location was always UNKNOWN_LOCATION due to an omitted merge. +* Impossible to use implicit classpath for <taskdef> + when Ant core loader != Java application loader and Path.systemClassPath taken from ${java.class.path} + Bugzilla 30161. + Changes from Ant 1.6.1 to Ant 1.6.2 ===================================
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]