Search in sources :

Example 6 with ClassInfo

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;
    }
}
Also used : ClassPath(com.google.common.reflect.ClassPath) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 7 with ClassInfo

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;
}
Also used : GWTTestCase(com.google.gwt.junit.client.GWTTestCase) GWTTestSuite(com.google.gwt.junit.tools.GWTTestSuite) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 8 with ClassInfo

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", "");
}
Also used : ClassPath(com.google.common.reflect.ClassPath) TestCase(junit.framework.TestCase) IOException(java.io.IOException) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 9 with ClassInfo

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);
    }
}
Also used : ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 10 with ClassInfo

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++;
    }
}
Also used : GuiProvider(logisticspipes.network.abstractguis.GuiProvider) PopupGuiProvider(logisticspipes.network.abstractguis.PopupGuiProvider) ArrayList(java.util.ArrayList) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo) SneakyThrows(lombok.SneakyThrows)

Aggregations

ClassInfo (com.google.common.reflect.ClassPath.ClassInfo)13 ArrayList (java.util.ArrayList)7 ClassPath (com.google.common.reflect.ClassPath)5 IOException (java.io.IOException)3 SneakyThrows (lombok.SneakyThrows)2 GWTTestCase (com.google.gwt.junit.client.GWTTestCase)1 GWTTestSuite (com.google.gwt.junit.tools.GWTTestSuite)1 Injector (com.google.inject.Injector)1 URLClassLoader (java.net.URLClassLoader)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 OptionSet (joptsimple.OptionSet)1 TestCase (junit.framework.TestCase)1 GuiProvider (logisticspipes.network.abstractguis.GuiProvider)1 PopupGuiProvider (logisticspipes.network.abstractguis.PopupGuiProvider)1 ModernPacket (logisticspipes.network.abstractpackets.ModernPacket)1 Mixin (net.runelite.api.mixins.Mixin)1