use of org.reflections.util.ConfigurationBuilder in project deeplearning4j by deeplearning4j.
the class DefaultI18N method loadLanguageResources.
private synchronized void loadLanguageResources(String languageCode) {
if (loadedLanguages.contains(languageCode))
return;
//Scan classpath for resources in the /dl4j_i18n/ directory...
URL url = this.getClass().getResource("/" + DEFAULT_I8N_RESOURCES_DIR + "/");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(url));
String pattern = ".*" + languageCode;
Set<String> resources = reflections.getResources(Pattern.compile(pattern));
Map<String, String> messages = new HashMap<>();
for (String s : resources) {
if (!s.endsWith(languageCode))
continue;
log.trace("Attempting to parse file: {}", s);
parseFile(s, messages);
}
messagesByLanguage.put(languageCode, messages);
loadedLanguages.add(languageCode);
}
use of org.reflections.util.ConfigurationBuilder 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());
final Set<String> auditEventTypes = new AuditEventTypes().auditEventTypes();
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.util.ConfigurationBuilder in project reflections by ronmamo.
the class ReflectionsExpandSupertypesTest method testExpandSupertypes.
@Test
public void testExpandSupertypes() throws Exception {
Reflections refExpand = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forClass(TestModel.ScannedScope.C.class)).filterInputsBy(inputsFilter));
Assert.assertTrue(refExpand.getConfiguration().shouldExpandSuperTypes());
Set<Class<? extends TestModel.A>> subTypesOf = refExpand.getSubTypesOf(TestModel.A.class);
Assert.assertTrue("expanded", subTypesOf.contains(TestModel.B.class));
Assert.assertTrue("transitivity", subTypesOf.containsAll(refExpand.getSubTypesOf(TestModel.B.class)));
}
use of org.reflections.util.ConfigurationBuilder in project drill by apache.
the class ClassPathScanner method scan.
/**
*
* @param pathsToScan the locations to scan for .class files
* @param packagePrefixes the whitelist of package prefixes to scan
* @param parentResult if there was a prescan, its result
* @return the merged scan
*/
static ScanResult scan(Collection<URL> pathsToScan, Collection<String> packagePrefixes, Collection<String> scannedClasses, Collection<String> scannedAnnotations, ScanResult parentResult) {
Stopwatch watch = Stopwatch.createStarted();
try {
AnnotationScanner annotationScanner = new AnnotationScanner(scannedAnnotations);
SubTypesScanner subTypesScanner = new SubTypesScanner(parentResult.getImplementations());
if (packagePrefixes.size() > 0) {
final FilterBuilder filter = new FilterBuilder();
for (String prefix : packagePrefixes) {
filter.include(FilterBuilder.prefix(prefix));
}
ConfigurationBuilder conf = new ConfigurationBuilder().setUrls(pathsToScan).setMetadataAdapter(// Scanners depend on this
METADATA_ADAPTER).filterInputsBy(filter).setScanners(annotationScanner, subTypesScanner);
// scans stuff, but don't use the funky storage layer
new Reflections(conf);
}
List<ParentClassDescriptor> implementations = new ArrayList<>();
for (String baseTypeName : scannedClasses) {
implementations.add(new ParentClassDescriptor(baseTypeName, new ArrayList<>(subTypesScanner.getChildrenOf(baseTypeName))));
}
List<AnnotatedClassDescriptor> annotated = annotationScanner.getAnnotatedClasses();
verifyClassUnicity(annotated, pathsToScan);
return new ScanResult(packagePrefixes, scannedClasses, scannedAnnotations, annotated, implementations);
} finally {
logger.info(format("Scanning packages %s in locations %s took %dms", packagePrefixes, pathsToScan, watch.elapsed(MILLISECONDS)));
}
}
use of org.reflections.util.ConfigurationBuilder in project ocvn by devgateway.
the class ReflectionsConfiguration method reflections.
@Bean
public Reflections reflections() {
logger.debug("Starting reflections scanners...");
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.devgateway.ocds.persistence.mongo")).setScanners(new SubTypesScanner(), new FieldAnnotationsScanner(), new MethodParameterScanner()));
logger.debug("Configured reflections bean.");
return reflections;
}
Aggregations