MCPcopy
hub / github.com/google/guava / from

Method from

guava/src/com/google/common/reflect/ClassPath.java:123–139  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

testJarFileWithSpacesMethod · 0.95
testNullsMethod · 0.95
suiteMethod · 0.95
loadClassesInPackageMethod · 0.95

Calls 7

locationsFromMethod · 0.95
builderMethod · 0.95
addMethod · 0.65
addAllMethod · 0.65
fileMethod · 0.45
scanResourcesMethod · 0.45
buildMethod · 0.45

Tested by 5

testJarFileWithSpacesMethod · 0.76
testNullsMethod · 0.76
suiteMethod · 0.76
loadClassesInPackageMethod · 0.76