From b10bf232ba67322a7c3ab689984c1e39710f0d66 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 4 Oct 2006 21:18:59 +0000 Subject: [PATCH] another go at bugzilla 38747, isolate resources get the baseloader for resources in isolate mode git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@453032 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 --- .../org/apache/tools/ant/AntClassLoader.java | 27 ++++++++++++++++--- .../ant/AntClassLoaderDelegationTest.java | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index f744295da..4bc3ca058 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -44,10 +44,6 @@ Other changes: * Added resource collection for convenient creation of string resources from other resources' content. Inspired by Bugzilla 40504. -* REVERTED for the moment: AntClassLoader did not isolate - resources when isolate was set. Bugzilla report 38747. - - Changes from Ant 1.7.0Beta1 to Ant 1.7.0Beta2 ============================================= diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 5f1a839f0..8dd99b468 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -871,6 +871,18 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { return useParentFirst; } + /** + * Used for isolated resource seaching. + * @return the root classloader of AntClassLoader. + */ + private ClassLoader getRootLoader() { + ClassLoader ret = getClass().getClassLoader(); + while (ret != null && ret.getParent() != null) { + ret = ret.getParent(); + } + return ret; + } + /** * Finds the resource with the given name. A resource is * some data (images, audio, text, etc) that can be accessed by class @@ -913,9 +925,13 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { if (url == null && !isParentFirst(name)) { // this loader was first but it didn't find it - try the parent - - url = (parent == null) ? super.getResource(name) - : parent.getResource(name); + if (ignoreBase) { + url = (getRootLoader() == null) ? null + : getRootLoader().getResource(name); + } else { + url = (parent == null) ? super.getResource(name) + : parent.getResource(name); + } if (url != null) { log("Resource " + name + " loaded from parent loader", Project.MSG_DEBUG); @@ -953,6 +969,11 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { if (isParentFirst(name)) { // Normal case. return CollectionUtils.append(base, mine); + } else if (ignoreBase) { + return getRootLoader() == null + ? mine + : CollectionUtils.append( + mine, getRootLoader().getResources(name)); } else { // Inverted. return CollectionUtils.append(mine, base); diff --git a/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java b/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java index 2b1fce70b..d66ed7d5e 100644 --- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java +++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java @@ -78,7 +78,7 @@ public class AntClassLoaderDelegationTest extends TestCase { enum2List(acl.getResources(TEST_RESOURCE))); } - public void NottestFindIsolateResources() throws Exception { + public void testFindIsolateResources() throws Exception { String buildTestcases = System.getProperty("build.tests"); assertNotNull("defined ${build.tests}", buildTestcases); assertTrue("have a dir " + buildTestcases, new File(buildTestcases).isDirectory());