use of co.cask.cdap.common.internal.guava.ClassPath.ResourceInfo in project cdap by caskdata.
the class ClassPathResources method findClassDependencies.
/**
* Finds all resource names that the given set of classes depends on.
*
* @param classLoader class loader for looking up .class resources
* @param classes set of class names that need to trace dependencies from
* @param result collection to store the resulting resource names
* @param <T> type of the result collection
* @throws IOException if fails to load class bytecode during tracing
*/
private static <T extends Collection<String>> T findClassDependencies(final ClassLoader classLoader, Iterable<String> classes, final T result) throws IOException {
final Set<String> bootstrapClassPaths = getBootstrapClassPaths();
final Set<URL> classPathSeen = Sets.newHashSet();
Dependencies.findClassDependencies(classLoader, new ClassAcceptor() {
@Override
public boolean accept(String className, URL classUrl, URL classPathUrl) {
// Ignore bootstrap classes
if (bootstrapClassPaths.contains(classPathUrl.getFile())) {
return false;
}
// visible through the program classloader.
if (className.startsWith("org.slf4j.impl.")) {
return false;
}
if (!classPathSeen.add(classPathUrl)) {
return true;
}
// Add all resources in the given class path
try {
ClassPath classPath = ClassPath.from(classPathUrl.toURI(), classLoader);
for (ClassPath.ResourceInfo resourceInfo : classPath.getResources()) {
result.add(resourceInfo.getResourceName());
}
} catch (Exception e) {
// If fail to get classes/resources from the classpath, ignore this classpath.
}
return true;
}
}, classes);
return result;
}
Aggregations