/** * Populates the list of {@link URL} that this ClassLoader uses, including all URLs used by the parent of the * given ClassLoader. * * @param classLoader the {@link ClassLoader} for searching urls * @param childFirst if {@code true}, urls gathered from the lower classloader in the hierarchy will be * added before the higher one. * @param urls a {@link Collection} for storing the {@link URL}s * @return the same {@link Collection} passed from the parameter */ public static <T extends Collection<? super URL>> T getClassLoaderURLs(ClassLoader classLoader, boolean childFirst, T urls) { Deque<URLClassLoader> classLoaders = collectURLClassLoaders(classLoader, new LinkedList<URLClassLoader>()); Iterator<URLClassLoader> iterator = childFirst ? classLoaders.iterator() : classLoaders.descendingIterator(); while (iterator.hasNext()) { ClassLoader cl = iterator.next(); for (URL url : ((URLClassLoader) cl).getURLs()) { if (urls.add(url) && (url.getProtocol().equals("file"))) { addClassPathFromJar(url, urls); } } } return urls; }
/** * Populates the list of {@link URL} that this ClassLoader uses, including all URLs used by the parent of the * given ClassLoader. * * @param classLoader the {@link ClassLoader} for searching urls * @param childFirst if {@code true}, urls gathered from the lower classloader in the hierarchy will be * added before the higher one. * @param urls a {@link Collection} for storing the {@link URL}s * @return the same {@link Collection} passed from the parameter */ public static <T extends Collection<? super URL>> T getClassLoaderURLs(ClassLoader classLoader, boolean childFirst, T urls) { Deque<URLClassLoader> classLoaders = collectURLClassLoaders(classLoader, new LinkedList<URLClassLoader>()); Iterator<URLClassLoader> iterator = childFirst ? classLoaders.iterator() : classLoaders.descendingIterator(); while (iterator.hasNext()) { ClassLoader cl = iterator.next(); for (URL url : ((URLClassLoader) cl).getURLs()) { if (urls.add(url) && (url.getProtocol().equals("file"))) { addClassPathFromJar(url, urls); } } } return urls; }