use of org.reflections.scanners.SubTypesScanner in project che by eclipse.
the class DynaProviderGenerator method findDynaObjects.
private void findDynaObjects() throws IOException {
ConfigurationBuilder configuration = new ConfigurationBuilder();
List<URL> urls = new ArrayList<>();
for (String element : classpath) {
urls.add(new File(element).toURI().toURL());
}
ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(contextClassLoader);
configuration.setUrls(ClasspathHelper.forClassLoader(contextClassLoader));
configuration.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
Reflections reflection = new Reflections(configuration);
Set<Class<?>> classes = reflection.getTypesAnnotatedWith(DynaObject.class);
for (Class clazz : classes) {
//accept only classes
if (clazz.isEnum() || clazz.isInterface() || clazz.isAnnotation()) {
continue;
}
dynaClasses.add(new ClassModel(clazz));
System.out.println(String.format("New Dyna Object Found: %s", clazz.getCanonicalName()));
}
System.out.println(String.format("Found: %d Dyna Objects", dynaClasses.size()));
}
use of org.reflections.scanners.SubTypesScanner in project swagger-core by swagger-api.
the class BeanConfig method classes.
@Override
public Set<Class<?>> classes() {
ConfigurationBuilder config = new ConfigurationBuilder();
Set<String> acceptablePackages = new HashSet<String>();
boolean allowAllPackages = false;
if (resourcePackage != null && !"".equals(resourcePackage)) {
String[] parts = resourcePackage.split(",");
for (String pkg : parts) {
if (!"".equals(pkg)) {
acceptablePackages.add(pkg);
config.addUrls(ClasspathHelper.forPackage(pkg));
}
}
} else {
allowAllPackages = true;
}
config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
final Reflections reflections = new Reflections(config);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class);
Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(SwaggerDefinition.class);
classes.addAll(typesAnnotatedWith);
/*
* Find concrete types annotated with @Api, but with a supertype annotated with @Path.
* This would handle split resources where the interface has jax-rs annotations
* and the implementing class has Swagger annotations
*/
for (Class<?> cls : reflections.getTypesAnnotatedWith(Api.class)) {
for (Class<?> intfc : TypeToken.of(cls).getTypes().interfaces().rawTypes()) {
Annotation ann = intfc.getAnnotation(javax.ws.rs.Path.class);
if (ann != null) {
classes.add(cls);
break;
}
}
}
Set<Class<?>> output = new HashSet<Class<?>>();
for (Class<?> cls : classes) {
if (allowAllPackages) {
output.add(cls);
} else {
for (String pkg : acceptablePackages) {
if (cls.getPackage().getName().startsWith(pkg)) {
output.add(cls);
}
}
}
}
return output;
}
use of org.reflections.scanners.SubTypesScanner 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.scanners.SubTypesScanner 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;
}
use of org.reflections.scanners.SubTypesScanner in project sldeditor by robward-scisys.
the class RegisterClasses method registerLabelRenderers.
/**
* Register label converters.
*
* @param classLoadersList the class loaders list
* @param data the data
*/
private static void registerLabelRenderers(List<ClassLoader> classLoadersList, ConversionData data) {
logger.info("Label Renderers supported:");
Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.label"))));
Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
for (Class<? extends Object> claszz : allClasses) {
try {
if (validClass(claszz, EsriLabelRendererInterface.class)) {
EsriLabelRendererInterface rendererObj = (EsriLabelRendererInterface) claszz.newInstance();
logger.info(rendererObj.getRendererClass().getName());
data.addLabelRenderer(rendererObj);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Aggregations