in xbean-finder/src/main/java/org/apache/xbean/finder/ClassLoaders.java [40:74]
public static Set<URL> findUrls(final ClassLoader classLoader) throws IOException {
if (classLoader == null || (SYSTEM.getParent() != null && classLoader == SYSTEM.getParent())) {
return Collections.emptySet();
}
final Set<URL> urls = new HashSet<URL>();
if (URLClassLoader.class.isInstance(classLoader) && !DONT_USE_GET_URLS) {
if (!isSurefire(classLoader)) {
for (final Collection<URL> item : Arrays.asList(
Arrays.asList(URLClassLoader.class.cast(classLoader).getURLs()), findUrls(classLoader.getParent()))) {
for (final URL url : item) {
addIfNotSo(urls, url);
}
}
} else { // http://jira.codehaus.org/browse/SUREFIRE-928 - we could reuse findUrlFromResources but this seems faster
urls.addAll(fromClassPath());
}
}
// DONT_USE_GET_URLS || java -jar xxx.jar and use MANIFEST.MF Class-Path?
// here perf is not an issue since we would either miss all the classpath or we have a single jar
if (urls.size() <= 1) {
final Set<URL> urlFromResources = findUrlFromResources(classLoader);
if (!urls.isEmpty()) {
final URL theUrl = urls.iterator().next();
if ("file".equals(theUrl.getProtocol())) { // theUrl can be file:xxxx but it is the same entry actually
urlFromResources.remove(new URL("jar:" + theUrl.toExternalForm() + "!/"));
}
}
urls.addAll(urlFromResources);
}
return urls;
}