Index: api2/test/java/javax/jdo/JDOConfigTestClassLoader.java =================================================================== --- api2/test/java/javax/jdo/JDOConfigTestClassLoader.java (revision 702301) +++ api2/test/java/javax/jdo/JDOConfigTestClassLoader.java (working copy) @@ -11,51 +11,96 @@ import java.util.Iterator; /** - * A class loader used to ensure that classpath URLs added in JUnit tests - * aren't included in subsequent JUnit tests. + * + * A class loader that automatically builds up its class path from another + * class loader (a parent class loader), and supports filtering out of + * specific class path elements. Only the class path elements from + * the parent that do not contain specific strings are used to build up the + * new class path of this loader. + * + *

In practice, this class loader is used + * to ensure that classpath URLs added in JUnit tests aren't included in + * subsequent JUnit tests. Every time this class loader is instantiated, + * the class path it uses excludes class path elements that contain text + * passed to the constructor. + * */ public class JDOConfigTestClassLoader extends URLClassLoader { + /** + * Instantiates a class loader with a filtered class path of a different + * loader. The class path of this loader will consist of all of the class + * path elements from the other loader, except for the elements that + * contain a specific substring. + * + * @param partialPathToIgnore any class path element with this string in it + * will not be copied from parent to this loader. + * @param parent The loader from which the class path of this class will + * be created. + */ public JDOConfigTestClassLoader( String partialPathToIgnore, - ClassLoader unparent + ClassLoader parent ) { - this(new String[]{partialPathToIgnore}, unparent); + this(new String[]{partialPathToIgnore}, parent); } + /** + * Instantiates a class loader with a filtered class path of a different + * loader. The class path of this loader will consist of all of the class + * path elements from the other loader, except for the elements that + * contain any substring specified in the given array of strings. + * + * @param partialPathsToIgnore any path element with a string in this array + * will not be copied from parent to this loader. + * @param parent The loader from which the class path of this class will + * be created. + * + */ public JDOConfigTestClassLoader( String[] partialPathsToIgnore, - ClassLoader unparent + ClassLoader parent ) { super(new URL[]{}, null); - if (unparent instanceof URLClassLoader) { + if (parent instanceof URLClassLoader) { addNonTestURLs( partialPathsToIgnore == null ? new String[]{} : partialPathsToIgnore, - (URLClassLoader) unparent); + (URLClassLoader) parent); } - else if (unparent instanceof AntClassLoader) { + else if (parent instanceof AntClassLoader) { addNonTestURLs( partialPathsToIgnore == null ? new String[]{} : partialPathsToIgnore, - (AntClassLoader) unparent); + (AntClassLoader) parent); } else { throw new RuntimeException( "unknown ClassLoader type: " - + unparent.getClass().getName()); + + parent.getClass().getName()); } } // HACK: need to identify a better way of controlling test classpath + /** + * Adds class path elements from the parent loader to this loader. + * Any class path elements in parent that contain any string + * found in the specified array of strings will not be copied to this + * loader. + * + * @param partialPathsToIgnore the array of strings used to filter out class + * path elements. + * @param parent the loader from which the class path of this class will + * be created. + */ protected void addNonTestURLs( String[] partialPathsToIgnore, - URLClassLoader unparent + URLClassLoader parent ) { - URL[] urls = unparent.getURLs(); + URL[] urls = parent.getURLs(); for (int i = 0; i < urls.length; i++) { URL url = urls[i]; String urlString = url.toString(); @@ -67,6 +112,17 @@ } } + /** + * Identical in function to + * addNonTextURLs(String[], URLClassLoader), except that this + * method accepts an {@link org.apache.tools.ant.AntClassLoader + * AntClassLoader}. + * + * @param partialPathsToIgnore the array of strings used to filter out class + * path elements. + * @param parent the loader from which the class path of this class will + * be created. + */ protected void addNonTestURLs( String[] partialPathsToIgnore, AntClassLoader unparent