Returns a {@code ClassPath} representing all classes and resources loadable from {@code classloader} and its ancestor class loaders. <p><b>Warning:</b> {@code ClassPath} can find classes and resources only from: <ul> <li>{@link URLClassLoader} instances' {@code file:} URLs <li>the {@linkplain
(ClassLoader classloader)
| 121 | * failed. |
| 122 | */ |
| 123 | public static ClassPath from(ClassLoader classloader) throws IOException { |
| 124 | ImmutableSet<LocationInfo> locations = locationsFrom(classloader); |
| 125 | |
| 126 | // Add all locations to the scanned set so that in a classpath [jar1, jar2], where jar1 has a |
| 127 | // manifest with Class-Path pointing to jar2, we won't scan jar2 twice. |
| 128 | Set<File> scanned = new HashSet<>(); |
| 129 | for (LocationInfo location : locations) { |
| 130 | scanned.add(location.file()); |
| 131 | } |
| 132 | |
| 133 | // Scan all locations |
| 134 | ImmutableSet.Builder<ResourceInfo> builder = ImmutableSet.builder(); |
| 135 | for (LocationInfo location : locations) { |
| 136 | builder.addAll(location.scanResources(scanned)); |
| 137 | } |
| 138 | return new ClassPath(builder.build()); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns all resources loadable from the current class path, including the class files of all |