use of io.github.classgraph.ClassGraph in project symja_android_library by axkr.
the class Table method autoRegisterReadersAndWriters.
private static void autoRegisterReadersAndWriters() {
try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages("tech.tablesaw.io").scan()) {
List<String> classes = new ArrayList<>();
classes.addAll(scanResult.getClassesImplementing(DataWriter.class.getName()).getNames());
classes.addAll(scanResult.getClassesImplementing(DataReader.class.getName()).getNames());
for (String clazz : classes) {
try {
Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
}
}
}
use of io.github.classgraph.ClassGraph in project beam by apache.
the class ClasspathScanningResourcesDetectorTest method shouldNotDetectClassPathResourceThatIsNotAFile.
@Test
public void shouldNotDetectClassPathResourceThatIsNotAFile() throws Exception {
String url = "http://www.google.com/all-the-secrets.jar";
ClassLoader classLoader = new URLClassLoader(new URL[] { new URL(url) });
ClasspathScanningResourcesDetector detector = new ClasspathScanningResourcesDetector(new ClassGraph());
List<String> result = detector.detect(classLoader);
assertThat(result, not(hasItem(containsString(url))));
}
use of io.github.classgraph.ClassGraph in project beam by apache.
the class ClasspathScanningResourcesDetectorTest method shouldDetectClassPathResourceFromJavaClassPathEnvVariable.
@Test
public void shouldDetectClassPathResourceFromJavaClassPathEnvVariable() throws IOException {
String path = tmpFolder.newFolder("folder").getAbsolutePath();
System.setProperty("java.class.path", path);
ClasspathScanningResourcesDetector detector = new ClasspathScanningResourcesDetector(new ClassGraph());
List<String> resources = detector.detect(null);
assertThat(resources, hasItems(containsString(path)));
}
use of io.github.classgraph.ClassGraph in project beam by apache.
the class ClasspathScanningResourcesDetectorTest method shouldDetectDirectories.
@Test
public void shouldDetectDirectories() throws Exception {
File folder = tmpFolder.newFolder("folder1");
ClassLoader classLoader = new URLClassLoader(new URL[] { folder.toURI().toURL() });
ClasspathScanningResourcesDetector detector = new ClasspathScanningResourcesDetector(new ClassGraph());
List<String> result = detector.detect(classLoader);
assertThat(result, hasItem(containsString(folder.getAbsolutePath())));
}
use of io.github.classgraph.ClassGraph in project hazelcast by hazelcast.
the class ReflectionUtils method nestedClassesOf.
@Nonnull
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "False positive on try-with-resources as of JDK11")
public static Collection<Class<?>> nestedClassesOf(Class<?>... classes) {
ClassGraph classGraph = new ClassGraph().enableClassInfo().ignoreClassVisibility();
stream(classes).map(Class::getClassLoader).distinct().forEach(classGraph::addClassLoader);
stream(classes).map(ReflectionUtils::toPackageName).distinct().forEach(classGraph::whitelistPackages);
try (ScanResult scanResult = classGraph.scan()) {
Set<String> classNames = stream(classes).map(Class::getName).collect(toSet());
return concat(stream(classes), scanResult.getAllClasses().stream().filter(classInfo -> classNames.contains(classInfo.getName())).flatMap(classInfo -> classInfo.getInnerClasses().stream()).map(ClassInfo::loadClass)).collect(toList());
}
}
Aggregations