use of org.reflections.Reflections in project perun by CESNET.
the class PerunCLI method run.
@Override
public void run(String... args) throws Exception {
// find all classes implementing commands and put them into the "commands" variable
log.debug("finding available commands...");
Reflections reflections = new Reflections("cz.metacentrum.perun.cli.commands");
List<Class<? extends PerunCommand>> classes = new ArrayList<>(reflections.getSubTypesOf(PerunCommand.class));
List<PerunCommand> commands = new ArrayList<>(classes.size());
for (Class<? extends PerunCommand> aClass : classes) {
commands.add(aClass.getDeclaredConstructor().newInstance());
}
commands.sort(Comparator.comparing(PerunCommand::getName));
// if no arguments specified, print list of available commands
if (args.length == 0) {
System.err.println();
System.err.println("Usage: <command> <options>");
System.err.println();
System.err.println("run a command with -h or --help to see a list of its available options");
System.err.println();
System.err.println("available commands:");
for (PerunCommand command : commands) {
System.err.println(" " + command.getName() + " ... " + command.getCommandDescription());
}
System.exit(1);
}
// call the command from class specified as first argument
String[] options = args.length == 1 ? new String[] {} : Arrays.copyOfRange(args, 1, args.length);
for (PerunCommand command : commands) {
if (command.getName().equals(args[0])) {
call(command, options);
return;
}
}
System.err.println("Command not recognized: " + args[0]);
}
use of org.reflections.Reflections in project druid by druid-io.
the class SubclassesMustOverrideEqualsAndHashCodeTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() throws NoSuchMethodException {
// Exclude test classes
Set<URL> urls = ClasspathHelper.forPackage("org.apache.druid").stream().filter(url -> !url.toString().contains("/target/test-classes")).collect(Collectors.toSet());
Reflections reflections = new Reflections(urls);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(SubclassesMustOverrideEqualsAndHashCode.class);
Set<String> failed = new HashSet<>();
for (Class<?> clazz : classes) {
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
continue;
}
Method m = clazz.getMethod("hashCode");
String className = clazz.getName();
try {
Assert.assertNotSame(className + " does not implment hashCode", Object.class, m.getDeclaringClass());
} catch (AssertionError e) {
failed.add(className);
}
}
if (!failed.isEmpty()) {
System.err.println("failed classes [" + failed.size() + "] : ");
failed.forEach(c -> System.err.println("\t" + c));
Assert.fail();
}
}
use of org.reflections.Reflections in project hazelcast by hazelcast.
the class AbstractYamlSchemaTest method buildTestcases.
protected static List<Object[]> buildTestcases(String rootDir) {
ConfigurationBuilder configuration = new ConfigurationBuilder().setUrls(ClasspathHelper.forJavaClassPath()).setScanners(new ResourcesScanner());
Reflections reflections = new Reflections(configuration);
return reflections.getResources(Pattern.compile(".*\\.json")).stream().filter(e -> e.startsWith(rootDir)).map(path -> buildArgs(rootDir, path)).collect(toList());
}
use of org.reflections.Reflections in project hazelcast by hazelcast.
the class XmlConfigSchemaLocationTest method testSchemaLocationsExist.
@Test
public void testSchemaLocationsExist() throws Exception {
assumeTls12Available();
ResourcesScanner scanner = new ResourcesScanner();
Reflections reflections = new Reflections(scanner);
Set<String> resources = reflections.getResources(Pattern.compile(".*\\.xml"));
ClassLoader classLoader = getClass().getClassLoader();
for (String resource : resources) {
System.out.println(resource);
URL resourceUrl = classLoader.getResource(resource);
String protocol = resourceUrl.getProtocol();
// do not validate schemas from JARs (libraries). we are interested in local project files only.
if (protocol.startsWith("jar")) {
continue;
}
InputStream stream = null;
try {
stream = classLoader.getResourceAsStream(resource);
validateSchemaLocationUrl(stream, resource);
} finally {
IOUtil.closeResource(stream);
}
}
}
use of org.reflections.Reflections in project hazelcast by hazelcast.
the class ReflectionUtils method getReflectionsForTestPackage.
public static Reflections getReflectionsForTestPackage(String forPackage) {
try {
URL testClassesURL = new File("target/test-classes").toURI().toURL();
URLClassLoader classLoader = newInstance(new URL[] { testClassesURL }, ClasspathHelper.staticClassLoader());
return new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(forPackage, classLoader)).addClassLoader(classLoader).filterInputsBy(new FilterBuilder().includePackage(forPackage)).setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner(), new MethodAnnotationsScanner()));
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
Aggregations