use of org.reflections.Reflections 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.Reflections 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.Reflections in project disconf by knightliao.
the class ReflectionScanStatic method scanBasicInfo.
/**
* 扫描基本信息
*/
private ScanStaticModel scanBasicInfo(List<String> packNameList) {
ScanStaticModel scanModel = new ScanStaticModel();
//
// 扫描对象
//
Reflections reflections = getReflection(packNameList);
scanModel.setReflections(reflections);
//
// 获取DisconfFile class
//
Set<Class<?>> classdata = reflections.getTypesAnnotatedWith(DisconfFile.class);
scanModel.setDisconfFileClassSet(classdata);
//
// 获取DisconfFileItem method
//
Set<Method> af1 = reflections.getMethodsAnnotatedWith(DisconfFileItem.class);
scanModel.setDisconfFileItemMethodSet(af1);
//
// 获取DisconfItem method
//
af1 = reflections.getMethodsAnnotatedWith(DisconfItem.class);
scanModel.setDisconfItemMethodSet(af1);
//
// 获取DisconfActiveBackupService
//
classdata = reflections.getTypesAnnotatedWith(DisconfActiveBackupService.class);
scanModel.setDisconfActiveBackupServiceClassSet(classdata);
//
// 获取DisconfUpdateService
//
classdata = reflections.getTypesAnnotatedWith(DisconfUpdateService.class);
scanModel.setDisconfUpdateService(classdata);
// update pipeline
Set<Class<? extends IDisconfUpdatePipeline>> iDisconfUpdatePipeline = reflections.getSubTypesOf(IDisconfUpdatePipeline.class);
if (iDisconfUpdatePipeline != null && iDisconfUpdatePipeline.size() != 0) {
scanModel.setiDisconfUpdatePipeline((Class<IDisconfUpdatePipeline>) iDisconfUpdatePipeline.toArray()[0]);
}
return scanModel;
}
use of org.reflections.Reflections 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.Reflections in project Gaffer by gchq.
the class ExampleGeneratorTest method instancesToTest.
public static Collection<Object[]> instancesToTest() {
final Reflections reflections = new Reflections("uk.gov.gchq");
final Set<Class<? extends Operation>> clazzes = reflections.getSubTypesOf(Operation.class);
return clazzes.stream().filter(clazz -> !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())).map(clazz -> new Object[] { clazz }).collect(Collectors.toList());
}
Aggregations