use of io.github.classgraph.ScanResult 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.ScanResult 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());
}
}
use of io.github.classgraph.ScanResult in project hazelcast by hazelcast.
the class ReflectionUtils method resourcesOf.
@Nonnull
@SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", justification = "False positive on try-with-resources as of JDK11")
public static Resources resourcesOf(String... packages) {
String[] paths = stream(packages).map(ReflectionUtils::toPath).toArray(String[]::new);
ClassGraph classGraph = new ClassGraph().whitelistPackages(packages).whitelistPaths(paths).ignoreClassVisibility();
try (ScanResult scanResult = classGraph.scan()) {
Collection<ClassResource> classes = scanResult.getAllClasses().stream().map(ClassResource::new).collect(toList());
Collection<URL> nonClasses = scanResult.getAllResources().nonClassFilesOnly().getURLs();
return new Resources(classes, nonClasses);
}
}
use of io.github.classgraph.ScanResult in project morphia by mongodb.
the class Mapper method getClasses.
private List<Class> getClasses(ClassLoader loader, String packageName, boolean mapSubPackages) throws ClassNotFoundException {
final Set<Class> classes = new HashSet<>();
ClassGraph classGraph = new ClassGraph().addClassLoader(loader).enableAllInfo();
if (mapSubPackages) {
classGraph.acceptPackages(packageName);
classGraph.acceptPackages(packageName + ".*");
} else {
classGraph.acceptPackagesNonRecursive(packageName);
}
try (ScanResult scanResult = classGraph.scan()) {
for (ClassInfo classInfo : scanResult.getAllClasses()) {
classes.add(Class.forName(classInfo.getName(), true, loader));
}
}
return new ArrayList<>(classes);
}
use of io.github.classgraph.ScanResult in project dhis2-core by dhis2.
the class PreheatStrategyScanner method scanSupplierStrategies.
public Map<String, String> scanSupplierStrategies() {
Map<String, String> classMap = new HashMap<>();
final String pkg = getCurrentPackage();
final String annotation = StrategyFor.class.getName();
try (ScanResult scanResult = new ClassGraph().enableClassInfo().acceptPackages(pkg).enableAnnotationInfo().scan()) {
for (ClassInfo classInfo : scanResult.getClassesWithAnnotation(annotation)) {
classMap.put(getTargetClass(classInfo, annotation), classInfo.getSimpleName());
}
}
return classMap;
}
Aggregations