diff --git a/WHATSNEW b/WHATSNEW index db7dd8787..813f74fad 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -174,6 +174,10 @@ Fixed bugs: * Incorrect classloader parent in junittask when using with ant-junit.jar and junit.jar not in the project classloader. Bugzilla report 28474. +* getResources() on the classloader returned by ClasspathUtils would see each resource + twice - if the resource is in the project classpath and if the classloader is requested + with a null path. + Changes from Ant 1.6.1 to Ant 1.6.2 =================================== diff --git a/src/main/org/apache/tools/ant/util/ClasspathUtils.java b/src/main/org/apache/tools/ant/util/ClasspathUtils.java index 944c00130..83ae4fb55 100644 --- a/src/main/org/apache/tools/ant/util/ClasspathUtils.java +++ b/src/main/org/apache/tools/ant/util/ClasspathUtils.java @@ -156,13 +156,13 @@ public class ClasspathUtils { * 'ant.reuse.loader' this will try to reuse the perviously * created loader with that id, and of course store it there upon * creation.

- * @param path Path object to be used as classpath for this classloader - * @param loaderId identification for this Loader, + * @param path Path object to be used as classpath for this classloader + * @param loaderId identification for this Loader, * @param reverseLoader if set to true this new loader will take - * precedence over it's parent (which is contra the regular - * @param p Ant Project where the handled components are living in. - * classloader behaviour) - * @return ClassLoader that uses the Path as its classpath. + * precedence over it's parent (which is contra the regular + * classloader behaviour) + * @param p Ant Project where the handled components are living in. + * @return ClassLoader that uses the Path as its classpath. */ public static ClassLoader getClassLoaderForPath( Project p, Path path, String loaderId, boolean reverseLoader, @@ -205,9 +205,7 @@ public class ClasspathUtils { Project p, Path path, boolean reverseLoader) { - - AntClassLoader acl = p.createClassLoader(path != null - ? path : Path.systemClasspath); + AntClassLoader acl = p.createClassLoader(path); if (reverseLoader) { acl.setParentFirst(false); acl.addJavaLibraries(); diff --git a/src/testcases/org/apache/tools/ant/util/ClasspathUtilsTest.java b/src/testcases/org/apache/tools/ant/util/ClasspathUtilsTest.java new file mode 100644 index 000000000..4fdca9843 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/util/ClasspathUtilsTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2000-2002,2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.tools.ant.util; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import junit.framework.TestCase; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; + + +/** + * Test case for ClasspathUtils + * + */ +public class ClasspathUtilsTest extends TestCase { + + private Project p; + + public ClasspathUtilsTest(String name) { + super(name); + } + + public void setUp() { + p = new Project(); + p.init(); + } + + + public void testOnlyOneInstance() { + Enumeration enumeration; + String list = ""; + ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p, (Path) null, false); + try { + enumeration = c.getResources( + "org/apache/tools/ant/taskdefs/defaults.properties"); + } catch (IOException e) { + throw new BuildException( + "Could not get the defaults.properties resource"); + } + int count = 0; + while (enumeration.hasMoreElements()) { + list = list + " " + enumeration.nextElement(); + count++; + } + assertTrue("Should be only one and not " + count + " " + list, count == 1); + } +}