use of org.reflections.scanners.TypeAnnotationsScanner 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.TypeAnnotationsScanner 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.scanners.TypeAnnotationsScanner in project hazelcast by hazelcast.
the class ReflectionUtils method getReflectionsForTestPackage.
public static Reflections getReflectionsForTestPackage(String forPackage) {
try {
URL testClassesURL = new File("target/test-classes").toURI().toURL();
URLClassLoader classLoader = newInstance(new URL[] { testClassesURL }, ClasspathHelper.staticClassLoader());
return new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(forPackage, classLoader)).addClassLoader(classLoader).filterInputsBy(new FilterBuilder().includePackage(forPackage)).setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner(), new MethodAnnotationsScanner()));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
use of org.reflections.scanners.TypeAnnotationsScanner in project disconf by knightliao.
the class ReflectionScanStatic method getReflection.
/**
* 通过扫描,获取反射对象
*/
private Reflections getReflection(List<String> packNameList) {
//
// filter
//
FilterBuilder filterBuilder = new FilterBuilder().includePackage(Constants.DISCONF_PACK_NAME);
for (String packName : packNameList) {
filterBuilder = filterBuilder.includePackage(packName);
}
Predicate<String> filter = filterBuilder;
//
// urls
//
Collection<URL> urlTotals = new ArrayList<URL>();
for (String packName : packNameList) {
Set<URL> urls = ClasspathHelper.forPackage(packName);
urlTotals.addAll(urls);
}
//
Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter).setScanners(new SubTypesScanner().filterResultsBy(filter), new TypeAnnotationsScanner().filterResultsBy(filter), new FieldAnnotationsScanner().filterResultsBy(filter), new MethodAnnotationsScanner().filterResultsBy(filter), new MethodParameterScanner()).setUrls(urlTotals));
return reflections;
}
use of org.reflections.scanners.TypeAnnotationsScanner in project Smack by igniterealtime.
the class SmackIntegrationTestFramework method run.
public synchronized TestRunResult run() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// it is a global setting, but we treat it like a per sinttest run setting.
switch(config.dnsResolver) {
case minidns:
MiniDnsResolver.setup();
break;
case javax:
JavaxResolver.setup();
break;
case dnsjava:
DNSJavaResolver.setup();
break;
}
testRunResult = new TestRunResult();
// Create a connection manager *after* we created the testRunId (in testRunResult).
this.connectionManager = new XmppConnectionManager(this);
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion());
if (config.debugger != Configuration.Debugger.none) {
// JUL Debugger will not print any information until configured to print log messages of
// level FINE
// TODO configure JUL for log?
SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.debugger.JulDebugger");
SmackConfiguration.DEBUG = true;
}
if (config.replyTimeout > 0) {
SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
}
if (config.securityMode != SecurityMode.required && config.accountRegistration == AccountRegistration.inBandRegistration) {
AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);
}
// TODO print effective configuration
String[] testPackages;
if (config.testPackages == null || config.testPackages.isEmpty()) {
testPackages = new String[] { "org.jivesoftware.smackx", "org.jivesoftware.smack" };
} else {
testPackages = config.testPackages.toArray(new String[config.testPackages.size()]);
}
Reflections reflections = new Reflections(testPackages, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterScanner());
Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);
final int builtInTestCount = inttestClasses.size() + lowLevelInttestClasses.size();
Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(builtInTestCount);
classes.addAll(inttestClasses);
classes.addAll(lowLevelInttestClasses);
{
// Remove all abstract classes.
// TODO: This may be a good candidate for Java stream filtering once Smack is Android API 24 or higher.
Iterator<Class<? extends AbstractSmackIntTest>> it = classes.iterator();
while (it.hasNext()) {
Class<? extends AbstractSmackIntTest> clazz = it.next();
if (Modifier.isAbstract(clazz.getModifiers())) {
it.remove();
}
}
}
if (classes.isEmpty()) {
throw new IllegalStateException("No test classes in " + Arrays.toString(testPackages) + " found");
}
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + "]: Finished scanning for tests, preparing environment");
environment = prepareEnvironment();
try {
runTests(classes);
} catch (Throwable t) {
// Log the thrown Throwable to prevent it being shadowed in case the finally block below also throws.
LOGGER.log(Level.SEVERE, "Unexpected abort because runTests() threw throwable", t);
throw t;
} finally {
// Ensure that the accounts are deleted and disconnected before we continue
connectionManager.disconnectAndCleanup();
}
return testRunResult;
}
Aggregations