use of org.reflections.scanners.MethodAnnotationsScanner in project Alpha by alpha-asp.
the class Externals method scan.
public static Map<String, PredicateInterpretation> scan(Package basePackage) {
Reflections reflections = new Reflections(basePackage.getName(), new MethodAnnotationsScanner());
Set<Method> methods = reflections.getMethodsAnnotatedWith(Predicate.class);
return Externals.scanMethods(methods);
}
use of org.reflections.scanners.MethodAnnotationsScanner 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.MethodAnnotationsScanner in project graylog2-server by Graylog2.
the class AuditCoverageTest method testAuditCoverage.
@Test
public void testAuditCoverage() throws Exception {
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.graylog2")).setScanners(new MethodAnnotationsScanner());
// TODO: Dynamically discover event types?
final Set<String> auditEventTypes = ImmutableSet.<String>builder().addAll(new AuditEventTypes().auditEventTypes()).addAll(new PipelineProcessorAuditEventTypes().auditEventTypes()).addAll(new SidecarAuditEventTypes().auditEventTypes()).addAll(new ViewsAuditEventTypes().auditEventTypes()).addAll(new JobSchedulerAuditEventTypes().auditEventTypes()).addAll(new EventsAuditEventTypes().auditEventTypes()).addAll(new SecurityAuditEventTypes().auditEventTypes()).build();
final Reflections reflections = new Reflections(configurationBuilder);
final ImmutableSet.Builder<Method> methods = ImmutableSet.builder();
final ImmutableSet.Builder<Method> missing = ImmutableSet.builder();
final ImmutableSet.Builder<Method> unregisteredAction = ImmutableSet.builder();
methods.addAll(reflections.getMethodsAnnotatedWith(POST.class));
methods.addAll(reflections.getMethodsAnnotatedWith(PUT.class));
methods.addAll(reflections.getMethodsAnnotatedWith(DELETE.class));
for (Method method : methods.build()) {
if (!method.isAnnotationPresent(AuditEvent.class) && !method.isAnnotationPresent(NoAuditEvent.class)) {
missing.add(method);
} else {
if (method.isAnnotationPresent(AuditEvent.class)) {
final AuditEvent annotation = method.getAnnotation(AuditEvent.class);
if (!auditEventTypes.contains(annotation.type())) {
unregisteredAction.add(method);
}
}
}
}
assertThat(missing.build()).describedAs("Check that there are no POST, PUT and DELETE resources which do not have the @AuditEvent annotation").isEmpty();
assertThat(unregisteredAction.build()).describedAs("Check that there are no @AuditEvent annotations with unregistered event types").isEmpty();
}
use of org.reflections.scanners.MethodAnnotationsScanner 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;
}
use of org.reflections.scanners.MethodAnnotationsScanner in project ninja by ninjaframework.
the class JaxyRoutes method configureReflections.
private void configureReflections() {
ConfigurationBuilder builder = new ConfigurationBuilder();
Set<URL> packagesToScan = getPackagesToScanForRoutes();
builder.addUrls(packagesToScan);
builder.addScanners(new MethodAnnotationsScanner());
reflections = new Reflections(builder);
}
Aggregations