Path.systemClasspath in the antclassloader Doing so causes resources to appear twice git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277160 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -174,6 +174,10 @@ Fixed bugs: | |||||
| * Incorrect classloader parent in junittask when using with ant-junit.jar and junit.jar | * Incorrect classloader parent in junittask when using with ant-junit.jar and junit.jar | ||||
| not in the project classloader. Bugzilla report 28474. | 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 | Changes from Ant 1.6.1 to Ant 1.6.2 | ||||
| =================================== | =================================== | ||||
| @@ -156,13 +156,13 @@ public class ClasspathUtils { | |||||
| * 'ant.reuse.loader' this will try to reuse the perviously | * 'ant.reuse.loader' this will try to reuse the perviously | ||||
| * created loader with that id, and of course store it there upon | * created loader with that id, and of course store it there upon | ||||
| * creation.</p> | * creation.</p> | ||||
| * @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 | * @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( | public static ClassLoader getClassLoaderForPath( | ||||
| Project p, Path path, String loaderId, boolean reverseLoader, | Project p, Path path, String loaderId, boolean reverseLoader, | ||||
| @@ -205,9 +205,7 @@ public class ClasspathUtils { | |||||
| Project p, | Project p, | ||||
| Path path, | Path path, | ||||
| boolean reverseLoader) { | boolean reverseLoader) { | ||||
| AntClassLoader acl = p.createClassLoader(path != null | |||||
| ? path : Path.systemClasspath); | |||||
| AntClassLoader acl = p.createClassLoader(path); | |||||
| if (reverseLoader) { | if (reverseLoader) { | ||||
| acl.setParentFirst(false); | acl.setParentFirst(false); | ||||
| acl.addJavaLibraries(); | acl.addJavaLibraries(); | ||||
| @@ -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); | |||||
| } | |||||
| } | |||||