use of org.reflections.scanners.SubTypesScanner in project cosmic by MissionCriticalCloud.
the class ReflectUtil method getClassesWithAnnotation.
// Gets all classes with some annotation from a package
public static Set<Class<?>> getClassesWithAnnotation(final Class<? extends Annotation> annotation, final String[] packageNames) {
final Reflections reflections;
final Set<Class<?>> classes = new HashSet<>();
final ConfigurationBuilder builder = new ConfigurationBuilder();
for (final String packageName : packageNames) {
builder.addUrls(ClasspathHelper.forPackage(packageName));
}
builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
reflections = new Reflections(builder);
classes.addAll(reflections.getTypesAnnotatedWith(annotation));
return classes;
}
use of org.reflections.scanners.SubTypesScanner in project Shadbot by Shadorc.
the class CommandManager method init.
public static boolean init() {
LogUtils.infof("Initializing commands...");
Reflections reflections = new Reflections(Shadbot.class.getPackage().getName(), new SubTypesScanner(), new TypeAnnotationsScanner());
for (Class<?> cmdClass : reflections.getTypesAnnotatedWith(Command.class)) {
if (!AbstractCommand.class.isAssignableFrom(cmdClass)) {
LogUtils.error(String.format("An error occurred while generating command, %s cannot be cast to AbstractCommand.", cmdClass.getSimpleName()));
continue;
}
try {
AbstractCommand cmd = (AbstractCommand) cmdClass.getConstructor().newInstance();
List<String> names = cmd.getNames();
if (!cmd.getAlias().isEmpty()) {
names.add(cmd.getAlias());
}
for (String name : names) {
if (COMMANDS_MAP.putIfAbsent(name, cmd) != null) {
LogUtils.error(String.format("Command name collision between %s and %s", cmdClass.getSimpleName(), COMMANDS_MAP.get(name).getClass().getSimpleName()));
continue;
}
}
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException err) {
LogUtils.error(err, String.format("An error occurred while initializing command %s.", cmdClass.getDeclaringClass().getSimpleName()));
return false;
}
}
LogUtils.infof("%s initialized.", StringUtils.pluralOf((int) COMMANDS_MAP.values().stream().distinct().count(), "command"));
return true;
}
use of org.reflections.scanners.SubTypesScanner in project Smartcity-Smarthouse by TechnionYP5777.
the class Entry method main.
public static void main(final String[] args) {
SensorsSimulator simulator = new SensorsSimulator().setGeneralStreamingInteval(TimeUnit.SECONDS.toMillis(5));
SystemPresenterFactory factory = new SystemPresenterFactory().initMode(SystemMode.USER_MODE).enableModePopup(false).setUseCloudServer(false).enableLocalDatabase(false);
new Reflections("il.ac.technion.cs.smarthouse.applications", new SubTypesScanner(false)).getSubTypesOf(SmarthouseApplication.class).forEach(cls -> {
factory.addApplicationToInstall(new ApplicationPath(PathType.CLASS, cls));
if (Simulatable.class.isAssignableFrom(cls))
try {
simulator.addAllSensor(((Simulatable) cls.newInstance()).getSimulatedSensors());
} catch (InstantiationException | IllegalAccessException e) {
// Ignoring
}
});
factory.build();
new Thread() {
@Override
public void interrupt() {
simulator.stopSendingMsgsInAllSensors();
super.interrupt();
}
@Override
public void run() {
simulator.startSendingMsgsInAllSensors();
JavaFxHelper.startGui(new DeveloperSimulatorGui().setSimulator(simulator));
super.run();
}
}.start();
}
use of org.reflections.scanners.SubTypesScanner in project cloudstack by apache.
the class ReflectUtil method getClassesWithAnnotation.
// Gets all classes with some annotation from a package
public static Set<Class<?>> getClassesWithAnnotation(Class<? extends Annotation> annotation, String[] packageNames) {
Reflections reflections;
Set<Class<?>> classes = new HashSet<Class<?>>();
ConfigurationBuilder builder = new ConfigurationBuilder();
for (String packageName : packageNames) {
builder.addUrls(ClasspathHelper.forPackage(packageName));
}
builder.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
reflections = new Reflections(builder);
classes.addAll(reflections.getTypesAnnotatedWith(annotation));
return classes;
}
use of org.reflections.scanners.SubTypesScanner in project Smack by igniterealtime.
the class ExtensionElementQNameDeclaredTest method qnameOrElementNamespaceDeclaredTest.
@Test
public void qnameOrElementNamespaceDeclaredTest() {
String[] smackPackages = new String[] { "org.jivesoftware.smack", "org.igniterealtime.smack" };
Reflections reflections = new Reflections(smackPackages, new SubTypesScanner());
Set<Class<? extends ExtensionElement>> extensionElementClasses = reflections.getSubTypesOf(ExtensionElement.class);
Map<Class<? extends ExtensionElement>, IllegalArgumentException> exceptions = new HashMap<>();
for (Class<? extends ExtensionElement> extensionElementClass : extensionElementClasses) {
if (Modifier.isAbstract(extensionElementClass.getModifiers())) {
continue;
}
try {
XmppElementUtil.getQNameFor(extensionElementClass);
} catch (IllegalArgumentException e) {
exceptions.put(extensionElementClass, e);
}
}
Set<Class<? extends ExtensionElement>> failedClasses = exceptions.keySet();
assertThat(failedClasses).withFailMessage("The following " + failedClasses.size() + " classes are missing QNAME declaration: " + failedClasses).isEmpty();
}
Aggregations