diff options
author | Basil Crow <me@basilcrow.com> | 2021-07-11 12:29:22 -0700 |
---|---|---|
committer | Basil Crow <me@basilcrow.com> | 2021-07-11 12:29:22 -0700 |
commit | ef85f491ee3fa0152e46a708253bda1435b45a35 (patch) | |
tree | 189734ff007ddd032ecb9b16df4a61378d1d133b | |
parent | cc9d93f49fbd6730e057ec0ad6e2e382f8e3c331 (diff) | |
download | ant-ef85f491ee3fa0152e46a708253bda1435b45a35.tar.gz |
Implement ClassLoader#findResource(String)
-rw-r--r-- | CONTRIBUTORS | 1 | ||||
-rw-r--r-- | contributors.xml | 4 | ||||
-rw-r--r-- | src/main/org/apache/tools/ant/AntClassLoader.java | 45 |
3 files changed, 41 insertions, 9 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 064e6ad34..bc935a7c2 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -43,6 +43,7 @@ Avik Sengupta Balazs Fejes 2 barney2k7 Bart Vanhaute +Basil Crow Ben Galbraith Ben Gertzfield Benjamin Burgess diff --git a/contributors.xml b/contributors.xml index cff2bf718..c84ec148b 100644 --- a/contributors.xml +++ b/contributors.xml @@ -200,6 +200,10 @@ <last>Vanhaute</last> </name> <name> + <first>Basil</first> + <last>Crow</last> + </name> + <name> <first>Benjamin</first> <last>Burgess</last> </name> diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java index 189351f24..9791fb327 100644 --- a/src/main/org/apache/tools/ant/AntClassLoader.java +++ b/src/main/org/apache/tools/ant/AntClassLoader.java @@ -889,15 +889,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo if (url != null) { log("Resource " + name + " loaded from parent loader", Project.MSG_DEBUG); } else { - // try and load from this loader if the parent either didn't find - // it or wasn't consulted. - for (final File pathComponent : pathComponents) { - url = getResourceURL(pathComponent, name); - if (url != null) { - log("Resource " + name + " loaded from ant loader", Project.MSG_DEBUG); - break; - } - } + url = getUrl(name); } if (url == null && !isParentFirst(name)) { // this loader was first but it didn't find it - try the parent @@ -917,6 +909,29 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo } /** + * Finds a matching file by iterating through path components. + * + * @param name File to find + * @return A <code>URL</code> object for reading the resource, or <code>null</code> if the + * resource could not be found + */ + private URL getUrl(String name) { + URL url = null; + + // try and load from this loader if the parent either didn't find + // it or wasn't consulted. + for (final File pathComponent : pathComponents) { + url = getResourceURL(pathComponent, name); + if (url != null) { + log("Resource " + name + " loaded from ant loader", Project.MSG_DEBUG); + break; + } + } + + return url; + } + + /** * Finds all the resources with the given name. A resource is some * data (images, audio, text, etc) that can be accessed by class * code in a way that is independent of the location of the code. @@ -936,6 +951,18 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo } /** + * Finds the resource with the given name. + * + * @param name The resource name + * @return A <code>URL</code> object for reading the resource, or <code>null</code> if the + * resource could not be found + */ + @Override + protected URL findResource(final String name) { + return getUrl(name); + } + + /** * Returns an enumeration of URLs representing all the resources with the * given name by searching the class loader's classpath. * |