use of com.google.common.reflect.ClassPath.ClassInfo in project calcite-avatica by apache.
the class TestRunner method getAllTestClasses.
/**
* Finds all tests to run for the TCK.
*
* @return A list of test classes to run.
*/
List<Class<?>> getAllTestClasses() {
try {
ClassPath cp = ClassPath.from(getClass().getClassLoader());
ImmutableSet<ClassInfo> classes = cp.getTopLevelClasses("org.apache.calcite.avatica.tck.tests");
List<Class<?>> testClasses = new ArrayList<>(classes.size());
for (ClassInfo classInfo : classes) {
if (classInfo.getSimpleName().equals("package-info")) {
continue;
}
Class<?> clz = Class.forName(classInfo.getName());
if (Modifier.isAbstract(clz.getModifiers())) {
// Ignore abstract classes
continue;
}
testClasses.add(clz);
}
return testClasses;
} catch (Exception e) {
LOG.error("Failed to instantiate test classes", e);
Unsafe.systemExit(TestRunnerExitCodes.TEST_CASE_INSTANTIATION.ordinal());
// Unreachable..
return null;
}
}
use of com.google.common.reflect.ClassPath.ClassInfo in project guava by google.
the class GwtTestSuite method suite.
public static Test suite() throws IOException {
GWTTestSuite suite = new GWTTestSuite();
for (ClassInfo info : ClassPath.from(GwtTestSuite.class.getClassLoader()).getTopLevelClasses()) {
if (info.getName().endsWith("_gwt")) {
Class<?> clazz = info.load();
// TODO(cpovirk): why does asSubclass() throw? Is it something about ClassLoaders?
@SuppressWarnings("unchecked") Class<? extends GWTTestCase> cast = (Class<? extends GWTTestCase>) clazz;
suite.addTestSuite(cast);
}
}
return suite;
}
use of com.google.common.reflect.ClassPath.ClassInfo in project j2objc by google.
the class ASTClassInfoPrinter method main.
public static void main(String... args) {
// Clear saved state for new calls.
tree = TreeMultimap.create();
astLookup = Sets.newHashSet();
ClassPath cp = null;
try {
cp = ClassPath.from(ClassLoader.getSystemClassLoader());
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
System.exit(1);
}
for (ClassInfo c : cp.getTopLevelClasses("org.eclipse.jdt.core.dom")) {
astLookup.add(c.getSimpleName());
}
for (ClassInfo ci : cp.getTopLevelClasses("com.google.devtools.j2objc.ast")) {
// Ignore package-info and JUnit tests.
if (ci.getSimpleName().equals("package-info") || TestCase.class.isAssignableFrom(ci.load())) {
continue;
}
walkSuperclassHierarchy(ci.load());
}
// Print hierarchy descending from Object.
printClassHierarchy("Object", "");
}
use of com.google.common.reflect.ClassPath.ClassInfo in project syncany by syncany.
the class Plugins method loadPlugins.
/**
* Loads all plugins in the classpath.
*
* <p>First loads all classes in the 'org.syncany.plugins' package.
* For all classes ending with the 'Plugin' suffix, it tries to load
* them, checks whether they inherit from {@link Plugin} and whether
* they can be instantiated.
*/
private static void loadPlugins() {
try {
ImmutableSet<ClassInfo> pluginPackageSubclasses = ClassPath.from(Thread.currentThread().getContextClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE_NAME);
for (ClassInfo classInfo : pluginPackageSubclasses) {
boolean classNameEndWithPluginSuffix = classInfo.getName().endsWith(PLUGIN_CLASS_SUFFIX);
if (classNameEndWithPluginSuffix) {
Class<?> pluginClass = classInfo.load();
String camelCasePluginId = pluginClass.getSimpleName().replace(Plugin.class.getSimpleName(), "");
String pluginId = StringUtil.toSnakeCase(camelCasePluginId);
boolean isSubclassOfPlugin = Plugin.class.isAssignableFrom(pluginClass);
boolean canInstantiate = !Modifier.isAbstract(pluginClass.getModifiers());
boolean pluginAlreadyLoaded = plugins.containsKey(pluginId);
if (isSubclassOfPlugin && canInstantiate && !pluginAlreadyLoaded) {
logger.log(Level.INFO, "- " + pluginClass.getName());
try {
Plugin plugin = (Plugin) pluginClass.newInstance();
plugins.put(plugin.getId(), plugin);
} catch (Exception e) {
logger.log(Level.WARNING, "Could not load plugin (2): " + pluginClass.getName(), e);
}
}
}
}
} catch (Exception e) {
throw new RuntimeException("Unable to load plugins.", e);
}
}
use of com.google.common.reflect.ClassPath.ClassInfo in project LogisticsPipes by RS485.
the class NewGuiHandler method initialize.
@SuppressWarnings("unchecked")
@SneakyThrows({ IOException.class, InvocationTargetException.class, IllegalAccessException.class, InstantiationException.class })
public static final // Suppression+sneakiness because these shouldn't ever fail, and if they do, it needs to fail.
void initialize() {
final List<ClassInfo> classes = new ArrayList<>(ClassPath.from(NewGuiHandler.class.getClassLoader()).getTopLevelClassesRecursive("logisticspipes.network.guis"));
Collections.sort(classes, (o1, o2) -> o1.getSimpleName().compareTo(o2.getSimpleName()));
NewGuiHandler.guilist = new ArrayList<>(classes.size());
NewGuiHandler.guimap = new HashMap<>(classes.size());
int currentid = 0;
for (ClassInfo c : classes) {
final Class<?> cls = c.load();
final GuiProvider instance = (GuiProvider) cls.getConstructors()[0].newInstance(currentid);
NewGuiHandler.guilist.add(instance);
NewGuiHandler.guimap.put((Class<? extends GuiProvider>) cls, instance);
currentid++;
}
}
Aggregations