use of org.reflections.Reflections in project charts by vaadin.
the class TListUi method listTestClasses.
private void listTestClasses(Container indexedContainer, String subpackage) {
String packageName = "com.vaadin.addon.charts.examples";
if (subpackage != null) {
packageName += "." + subpackage;
}
Reflections reflections = new Reflections(packageName);
Set<Class<? extends AbstractVaadinChartExample>> subTypes = reflections.getSubTypesOf(AbstractVaadinChartExample.class);
for (Class<? extends AbstractVaadinChartExample> subType : subTypes) {
try {
addTest(indexedContainer, subType.getSimpleName(), subType, subpackage);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of org.reflections.Reflections 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.Reflections in project connect-utils by jcustenborder.
the class TestDataUtils method loadJsonResourceFiles.
public static <T extends NamedTest> List<T> loadJsonResourceFiles(String packageName, Class<T> cls) throws IOException {
Preconditions.checkNotNull(packageName, "packageName cannot be null");
Reflections reflections = new Reflections(packageName, new ResourcesScanner());
Set<String> resources = reflections.getResources(new FilterBuilder.Include(".*"));
List<T> datas = new ArrayList<>(resources.size());
Path packagePath = Paths.get("/" + packageName.replace(".", "/"));
for (String resource : resources) {
log.trace("Loading resource {}", resource);
Path resourcePath = Paths.get("/" + resource);
Path relativePath = packagePath.relativize(resourcePath);
File resourceFile = new File("/" + resource);
T data;
try (InputStream inputStream = cls.getResourceAsStream(resourceFile.getAbsolutePath())) {
data = ObjectMapperFactory.INSTANCE.readValue(inputStream, cls);
} catch (IOException ex) {
if (log.isErrorEnabled()) {
log.error("Exception thrown while loading {}", resourcePath, ex);
}
throw ex;
}
String nameWithoutExtension = Files.getNameWithoutExtension(resource);
if (null != relativePath.getParent()) {
String parentName = relativePath.getParent().getFileName().toString();
data.testName(parentName + "/" + nameWithoutExtension);
} else {
data.testName(nameWithoutExtension);
}
datas.add(data);
}
return datas;
}
use of org.reflections.Reflections in project TheLighterBot by PhotonBursted.
the class CommandParser method registerCommands.
public void registerCommands() {
StringBuilder status = new StringBuilder("Registered the following commands:");
int commandCount, activatedCommandCount = 0;
Reflections r = new Reflections(Command.class.getPackage().getName());
Set<Class<?>> commandObjects = r.getTypesAnnotatedWith(AvailableCommand.class);
commandCount = commandObjects.size();
for (Class<?> cmdClass : commandObjects) {
try {
addCommand((Command) cmdClass.newInstance());
activatedCommandCount++;
status.append("\n - ").append(cmdClass.getSimpleName());
} catch (InstantiationException | IllegalAccessException ex) {
log.warn(String.format("Something went wrong adding command %s:", cmdClass.getSimpleName()), ex);
}
}
log.info(status.append(String.format("\n\nActivated %s/%s commands succesfully.", activatedCommandCount, commandCount)).toString());
}
use of org.reflections.Reflections in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConfigurationService method getAvailableLocalConnectors.
/**
* Return available local connectors for this IC implementation
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public Set<IcConnectorInfo> getAvailableLocalConnectors() {
if (connectorInfos == null) {
connectorInfos = new HashSet<>();
connectorsConfigurations = new HashMap<>();
connectorsClass = new HashMap<>();
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(IcConnectorClass.class));
});
LOG.info(MessageFormat.format("Found annotated classes with IcConnectorClass [{0}]", annotated));
for (Class<?> clazz : annotated) {
IcConnectorClass connectorAnnotation = clazz.getAnnotation(IcConnectorClass.class);
if (!this.getFramework().equals(connectorAnnotation.framework())) {
continue;
}
if (!IcConnector.class.isAssignableFrom(clazz)) {
throw new IcException(MessageFormat.format("Cannot create instance of CzechIdM connector [{0}]! Connector class must be child of [{0}]!", IcConnector.class.getSimpleName()));
}
IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) clazz);
Class<? extends ConfigurationClass> configurationClass = connectorAnnotation.configurationClass();
connectorInfos.add(info);
IcConnectorConfiguration configuration = initDefaultConfiguration(configurationClass);
// Put default configuration to cache
connectorsConfigurations.put(info.getConnectorKey().getFullName(), configuration);
// Put connector class to cache
connectorsClass.put(info.getConnectorKey().getFullName(), ((Class<? extends IcConnector>) clazz));
}
LOG.info(MessageFormat.format("Found all local connector connectorInfos [{0}]", connectorInfos.toString()));
}
return connectorInfos;
}
Aggregations