diff --git a/src/test/org/apache/commons/logging/PathableClassLoader.java b/src/test/org/apache/commons/logging/PathableClassLoader.java index 94de5fa..17c5886 100644 --- a/src/test/org/apache/commons/logging/PathableClassLoader.java +++ b/src/test/org/apache/commons/logging/PathableClassLoader.java @@ -135,6 +135,9 @@ public class PathableClassLoader extends URLClassLoader { *
      * useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
      * 
+ *

+ * Of course, this assumes that the classes of interest are already + * in the classpath of the system classloader. */ public void useSystemLoader(String prefix) { useExplicitLoader(prefix, ClassLoader.getSystemClassLoader()); @@ -192,6 +195,12 @@ public class PathableClassLoader extends URLClassLoader { * be found. Typically this is the name of a jar file, or a directory * containing class files. *

+ * If there is no system property, but the classloader that loaded + * this class is a URLClassLoader then the set of URLs that the + * classloader uses for its classpath is scanned; any jar in the + * URL set whose name starts with the specified string is added to + * the classpath managed by this instance. + *

* Using logical library names allows the calling code to specify its * desired classpath without knowing the exact location of the necessary * classes. @@ -223,6 +232,20 @@ public class PathableClassLoader extends URLClassLoader { + " as a System property."); } + /** + * If the classloader that loaded this class has this logical lib in its + * path, then return the matching URL otherwise return null. + *

+ * This only works when the classloader loading this class is an instance + * of URLClassLoader and thus has a getURLs method that returns the classpath + * it uses when loading classes. However in practice, the vast majority of the + * time this type is the classloader used. + *

+ * The classpath of the classloader for this instance is scanned, and any + * jarfile in the path whose name starts with the logicalLib string is + * considered a match. For example, passing "foo" will match a url + * of file:///some/where/foo-2.7.jar. + */ private URL libFromClasspath(String logicalLib) { ClassLoader cl = this.getClass().getClassLoader(); if (cl instanceof URLClassLoader == false) {