use of org.reflections.Reflections 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);
}
use of org.reflections.Reflections in project EventHub by Codecademy.
the class Module method getEventHubHandler.
@Provides
private EventHubHandler getEventHubHandler(Injector injector, EventHub eventHub) throws ClassNotFoundException {
Map<String, Provider<Command>> commandsMap = Maps.newHashMap();
Reflections reflections = new Reflections(PACKAGE_NAME);
Set<Class<? extends Command>> commandClasses = reflections.getSubTypesOf(Command.class);
for (Class<? extends Command> commandClass : commandClasses) {
String path = commandClass.getAnnotation(Path.class).value();
// noinspection unchecked
commandsMap.put(path, (Provider<Command>) injector.getProvider(commandClass));
}
return new EventHubHandler(eventHub, commandsMap);
}
use of org.reflections.Reflections in project ninja by ninjaframework.
the class JaxyRoutes method findControllerMethods.
/**
* Searches for Methods that have either a Path Annotation or a HTTP-Method Annotation
*/
@SuppressWarnings("unchecked")
private Set<Method> findControllerMethods() {
Set<Method> methods = Sets.newLinkedHashSet();
methods.addAll(reflections.getMethodsAnnotatedWith(Path.class));
boolean enableCustomHttpMethods = ninjaProperties.getBooleanWithDefault(NINJA_CUSTOM_HTTP_METHODS, false);
if (enableCustomHttpMethods) {
Reflections annotationReflections = new Reflections("", new TypeAnnotationsScanner(), new SubTypesScanner());
for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) {
if (httpMethod.isAnnotation()) {
methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod));
}
}
} else {
// Only look for standard HTTP methods annotations
Reflections annotationReflections = new Reflections("ninja.jaxy", new TypeAnnotationsScanner(), new SubTypesScanner());
for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) {
if (httpMethod.isAnnotation()) {
methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod));
}
}
}
return methods;
}
use of org.reflections.Reflections in project kafka by apache.
the class DelegatingClassLoader method scanPluginPath.
private PluginScanResult scanPluginPath(ClassLoader loader, URL[] urls) throws ReflectiveOperationException {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setClassLoaders(new ClassLoader[] { loader });
builder.addUrls(urls);
builder.setScanners(new SubTypesScanner());
builder.useParallelExecutor();
Reflections reflections = new InternalReflections(builder);
return new PluginScanResult(getPluginDesc(reflections, Connector.class, loader), getPluginDesc(reflections, Converter.class, loader), getPluginDesc(reflections, HeaderConverter.class, loader), getTransformationPluginDesc(loader, reflections), getPredicatePluginDesc(loader, reflections), getServiceLoaderPluginDesc(ConfigProvider.class, loader), getServiceLoaderPluginDesc(ConnectRestExtension.class, loader), getServiceLoaderPluginDesc(ConnectorClientConfigOverridePolicy.class, loader));
}
use of org.reflections.Reflections in project alluxio by Alluxio.
the class CommandUtils method loadCommands.
/**
* Get instances of all subclasses of {@link Command} in a sub-package called "command" the given
* package.
*
* @param pkgName package prefix to look in
* @param classArgs type of args to instantiate the class
* @param objectArgs args to instantiate the class
* @return a mapping from command name to command instance
*/
public static Map<String, Command> loadCommands(String pkgName, Class[] classArgs, Object[] objectArgs) {
Map<String, Command> commandsMap = new HashMap<>();
Reflections reflections = new Reflections(Command.class.getPackage().getName());
for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
// Add commands from <pkgName>.command.*
if (cls.getPackage().getName().equals(pkgName + ".command") && !Modifier.isAbstract(cls.getModifiers())) {
// Only instantiate a concrete class
Command cmd = CommonUtils.createNewClassInstance(cls, classArgs, objectArgs);
commandsMap.put(cmd.getCommandName(), cmd);
}
}
return commandsMap;
}
Aggregations