use of org.reflections.Reflections 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.Reflections 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;
}
use of org.reflections.Reflections in project Dempsy by Dempsy.
the class Manager method makeInstance.
public T makeInstance(final String typeId) {
// There's an issue opened on Reflections where multi-threaded access to the zip file is broken.
// see: https://github.com/ronmamo/reflections/issues/81
final Reflections reflections;
final Set<Class<? extends T>> senderFactoryClasses;
synchronized (Reflections.class) {
// try something stupid like assume it's a package name and the sender factory is in that package
reflections = new Reflections(typeId + ".");
senderFactoryClasses = reflections.getSubTypesOf(clazz);
}
T ret = null;
if (senderFactoryClasses != null && senderFactoryClasses.size() > 0) {
final Class<? extends T> sfClass = senderFactoryClasses.iterator().next();
if (senderFactoryClasses.size() > 1)
LOGGER.warn("Multiple " + clazz.getSimpleName() + " implementations in the package \"{}\". Going with {}", typeId, sfClass.getName());
try {
ret = sfClass.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
throw new DempsyException("Failed to create an instance of the " + clazz.getSimpleName() + " \"" + sfClass.getName() + "\". Is there a default constructor?", e, false);
}
}
if (ret == null)
throw new DempsyException("Couldn't find a " + clazz.getSimpleName() + " registered with transport type id \"" + typeId + "\" and couldn't find an implementing class assuming the transport type id is a package name");
return ret;
}
use of org.reflections.Reflections in project CzechIdMng by bcvsolutions.
the class ConnIdIcConfigurationService method findAllLocalConnectorManagers.
private List<ConnectorInfoManager> findAllLocalConnectorManagers() {
if (managers == null) {
managers = new ArrayList<>();
List<Class<?>> annotated = new ArrayList<>();
// Find all class with annotation IcConnectorClass under specific
// packages
localConnectorsPackages.forEach(packageWithConnectors -> {
Reflections reflections = new Reflections(packageWithConnectors);
annotated.addAll(reflections.getTypesAnnotatedWith(ConnectorClass.class));
});
LOG.info(MessageFormat.format("Found annotated classes with IcConnectorClass [{0}]", annotated));
for (Class<?> clazz : annotated) {
URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
ConnectorInfoManagerFactory fact = ConnectorInfoManagerFactory.getInstance();
ConnectorInfoManager manager = fact.getLocalManager(url);
managers.add(manager);
}
LOG.info(MessageFormat.format("Found all local connector managers [{0}]", managers.toString()));
}
return managers;
}
use of org.reflections.Reflections in project cas by apereo.
the class JpaTicketRegistryConfiguration method ticketPackagesToScan.
@Bean
public List<String> ticketPackagesToScan() {
final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(CentralAuthenticationService.NAMESPACE)).setScanners(new SubTypesScanner(false)));
final Set<Class<?>> subTypes = (Set) reflections.getSubTypesOf(AbstractTicket.class);
final List<String> packages = subTypes.stream().map(t -> t.getPackage().getName()).collect(Collectors.toList());
return packages;
}
Aggregations