use of org.reflections.util.FilterBuilder in project oap by oaplatform.
the class Resources method urls.
public static List<URL> urls(String atPackage, String ext) {
final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat("reflections-%d").build());
try {
final ConfigurationBuilder configuration = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(atPackage)).setScanners(new ResourcesScanner()).filterInputsBy(new FilterBuilder().includePackage(atPackage)).setExecutorService(executorService);
final Reflections reflections = new Reflections(configuration);
final Set<String> resources = reflections.getResources(in -> in.endsWith("." + ext));
return new ArrayList<>(Sets.map(resources, r -> Thread.currentThread().getContextClassLoader().getResource(r)));
} finally {
executorService.shutdown();
}
}
use of org.reflections.util.FilterBuilder in project startup-os by google.
the class ClassScanner method scanPackage.
public void scanPackage(String packagePrefix, Map<String, FlagData> flags) {
// TODO - figure out configuration builder.
Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packagePrefix))).setUrls(ClasspathHelper.forPackage(packagePrefix)).setScanners(new FieldAnnotationsScanner()));
Set<Field> fields = reflections.getFieldsAnnotatedWith(FlagDesc.class);
for (Field field : fields) {
Class<?> clazz = field.getType();
if (!Flag.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException("Annotation '" + field + "' does not annotate a flag.");
}
if ((field.getModifiers() & Modifier.STATIC) == 0) {
throw new IllegalArgumentException("Flag '" + field + "' should be static but is not.");
}
Class<?> declaringClass = field.getDeclaringClass();
Flag<?> flag = getFlagMember(declaringClass, field);
FlagData flagData = createFlagData(declaringClass, field, flag);
if (flags.containsKey(flagData.getName())) {
throw new IllegalArgumentException(String.format("Flag '%s' is already defined here:\n%s", field, flags.get(flagData.getName())));
}
flags.put(flagData.getName(), flagData);
flag.setName(flagData.getName());
}
}
use of org.reflections.util.FilterBuilder in project drill by axbaretto.
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.FilterBuilder in project nd4j by deeplearning4j.
the class BasicNDArrayCompressor method loadCompressors.
protected void loadCompressors() {
/*
We scan classpath for NDArrayCompressor implementations and add them one by one to codecs map
*/
codecs = new ConcurrentHashMap<>();
Set<Class<? extends NDArrayCompressor>> classes = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j")).exclude(// Consider only .class files (to avoid debug messages etc. on .dlls, etc
"^(?!.*\\.class$).*$")).setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner())).getSubTypesOf(NDArrayCompressor.class);
for (Class<? extends NDArrayCompressor> impl : classes) {
if (Modifier.isAbstract(impl.getModifiers()) || impl.isInterface())
continue;
try {
NDArrayCompressor compressor = impl.newInstance();
codecs.put(compressor.getDescriptor().toUpperCase(), compressor);
} catch (InstantiationException i) {
// we need catch there, to avoid exceptions at abstract classes
;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
use of org.reflections.util.FilterBuilder in project cas by apereo.
the class OidcProfileScopeToAttributesFilter method configureAttributeReleasePoliciesByScope.
/**
* Configure attribute release policies by scope.
*/
protected void configureAttributeReleasePoliciesByScope() {
val oidc = casProperties.getAuthn().getOidc();
val packageName = BaseOidcScopeAttributeReleasePolicy.class.getPackage().getName();
val reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().includePackage(packageName)).setUrls(ClasspathHelper.forPackage(packageName)));
val subTypes = reflections.getSubTypesOf(BaseOidcScopeAttributeReleasePolicy.class);
subTypes.forEach(Unchecked.consumer(t -> {
if (ClassUtils.hasConstructor(t)) {
val ex = t.getDeclaredConstructor().newInstance();
if (oidc.getDiscovery().getScopes().contains(ex.getScopeType())) {
LOGGER.trace("Found standard OpenID Connect scope [{}] to filter attributes", ex.getScopeType());
this.attributeReleasePolicies.put(ex.getScopeType(), ex);
} else {
LOGGER.debug("OpenID Connect scope [{}] is not configured for use and will be ignored", ex.getScopeType());
}
}
}));
if (!userScopes.isEmpty()) {
LOGGER.debug("Configuring attributes release policies for user-defined scopes [{}]", userScopes);
userScopes.forEach(t -> attributeReleasePolicies.put(t.getScopeName(), t));
}
}
Aggregations