use of org.reflections.scanners.SubTypesScanner in project pwm by pwm-project.
the class RestServletTest method getClasses.
private Set<Class<? extends RestServlet>> getClasses() {
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("password.pwm")).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
Set<Class<? extends RestServlet>> classes = reflections.getSubTypesOf(RestServlet.class);
return Collections.unmodifiableSet(classes);
}
use of org.reflections.scanners.SubTypesScanner in project xian by happyyangyuan.
the class TraverseClasspath method getNonAbstractSubClasses.
/**
* reflection is not thread-safe scanning the jars files in the classpath,
* must be synchronized otherwise a "java.lang.IllegalStateException: zip file closed" is thrown.
* by happyyangyuan at 2017-01-22
*/
public static synchronized <T> Set<Class<? extends T>> getNonAbstractSubClasses(Class<T> parentClass, String... packages) {
try {
Reflections reflections = new Reflections(new ConfigurationBuilder().forPackages(packages).setScanners(new SubTypesScanner()));
Set<Class<? extends T>> subClasses = reflections.getSubTypesOf(parentClass);
Iterator<Class<? extends T>> it = subClasses.iterator();
while (it.hasNext()) {
Class subClass = it.next();
if (!Reflection.canInitiate(subClass)) {
// here is in danger of class loading deadlock if you use LOG.java to print the log.
SystemOutLogger.singleton.warn(subClass + " can not be initiated, ignored!", null, TraverseClasspath.class.getSimpleName());
it.remove();
}
}
return subClasses;
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
use of org.reflections.scanners.SubTypesScanner in project newton by muoncore.
the class MuonLookupUtils method init.
static void init(String[] packages) {
List<URL> urls = new ArrayList<>();
urls.addAll(ClasspathHelper.forPackage("io.muoncore.newton", MuonLookupUtils.class.getClassLoader()));
for (String aPackage : packages) {
log.info("Adding package {}", aPackage);
Collection<URL> urls1 = ClasspathHelper.forPackage(aPackage, MuonLookupUtils.class.getClassLoader());
log.info("Got {}", urls1);
urls.addAll(urls1);
}
log.info("Booting Reflections with urls {}", urls);
Reflections reflections = new Reflections(new ConfigurationBuilder().addScanners(new SubTypesScanner()).addScanners(new TypeAnnotationsScanner()).setUrls(urls));
final Set<Class<? extends NewtonEvent>> eventTypes = reflections.getSubTypesOf(NewtonEvent.class);
eventTypeMappings = new HashMap<>();
for (Class<? extends NewtonEvent> newtonEvent : eventTypes) {
eventTypeMappings.put(newtonEvent.getSimpleName(), newtonEvent);
}
final Set<Class<? extends AggregateRoot>> aggregateRootTypes = reflections.getSubTypesOf(AggregateRoot.class);
aggregateRootMappings = new HashMap<>();
for (Class<? extends AggregateRoot> root : aggregateRootTypes) {
aggregateRootMappings.put(root.getSimpleName(), root);
}
final Set<Class<? extends Saga>> sagaTypes = reflections.getSubTypesOf(Saga.class);
sagaTypeMappings = new HashMap<>();
for (Class<? extends Saga> root : sagaTypes) {
sagaTypeMappings.put(root.getSimpleName(), root);
}
ready.countDown();
}
use of org.reflections.scanners.SubTypesScanner in project nd4j by deeplearning4j.
the class OpsMappingTests method getOperations.
protected List<Operation> getOperations(@NonNull Op.Type type) {
val list = new ArrayList<Operation>();
Reflections f = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j.*")).exclude("^(?!.*\\.class$).*$")).setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner()));
switch(type) {
case SUMMARYSTATS:
{
Set<Class<? extends Variance>> clazzes = f.getSubTypesOf(Variance.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case RANDOM:
{
Set<Class<? extends BaseRandomOp>> clazzes = f.getSubTypesOf(BaseRandomOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case INDEXREDUCE:
{
Set<Class<? extends BaseIndexAccumulation>> clazzes = f.getSubTypesOf(BaseIndexAccumulation.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case REDUCE3:
case REDUCE:
{
Set<Class<? extends BaseAccumulation>> clazzes = f.getSubTypesOf(BaseAccumulation.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case BROADCAST:
{
Set<Class<? extends BaseBroadcastOp>> clazzes = f.getSubTypesOf(BaseBroadcastOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case SCALAR:
{
Set<Class<? extends BaseScalarOp>> clazzes = f.getSubTypesOf(BaseScalarOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case PAIRWISE:
case TRANSFORM:
{
Set<Class<? extends BaseTransformOp>> clazzes = f.getSubTypesOf(BaseTransformOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case CUSTOM:
{
Set<Class<? extends DynamicCustomOp>> clazzes = f.getSubTypesOf(DynamicCustomOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) {
if (clazz.getSimpleName().equalsIgnoreCase("dynamiccustomop"))
continue;
addOperation(clazz, list);
}
}
break;
}
log.info("Group: {}; List size: {}", type, list.size());
return list;
}
use of org.reflections.scanners.SubTypesScanner in project drill by apache.
the class TestforBaseTestInheritance method verifyInheritance.
@Test
@Category(UnlikelyTest.class)
public void verifyInheritance() {
// Get all BaseTest inheritors
Reflections reflections = new Reflections("org.apache.drill", new SubTypesScanner(false));
Set<Class<? extends BaseTest>> baseTestInheritors = reflections.getSubTypesOf(BaseTest.class);
// Get all tests that are not inherited from BaseTest
Set<String> testClasses = reflections.getSubTypesOf(Object.class).stream().filter(c -> !c.isInterface()).filter(c -> c.getSimpleName().toLowerCase().contains("test")).filter(c -> Arrays.stream(c.getDeclaredMethods()).anyMatch(m -> m.getAnnotation(Test.class) != null)).filter(c -> !baseTestInheritors.contains(c)).map(Class::getName).collect(Collectors.toSet());
Assert.assertEquals("Found test classes that are not inherited from BaseTest:", Collections.emptySet(), testClasses);
}
Aggregations