Search in sources :

Example 1 with ClassInfo

use of com.google.common.reflect.ClassPath.ClassInfo in project LogisticsPipes by RS485.

the class PacketHandler method initialize.

/*
	 * enumerates all ModernPackets, sets their IDs and populate packetlist/packetmap
	 */
@SuppressWarnings("unchecked")
@SneakyThrows({ IOException.class, InvocationTargetException.class, IllegalAccessException.class, InstantiationException.class, IllegalArgumentException.class, NoSuchMethodException.class, SecurityException.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(PacketHandler.class.getClassLoader()).getTopLevelClassesRecursive("logisticspipes.network.packets"));
    Collections.sort(classes, (o1, o2) -> o1.getSimpleName().compareTo(o2.getSimpleName()));
    PacketHandler.packetlist = new ArrayList<>(classes.size());
    PacketHandler.packetmap = new HashMap<>(classes.size());
    int currentid = 0;
    for (ClassInfo c : classes) {
        final Class<?> cls = c.load();
        final ModernPacket instance = (ModernPacket) cls.getConstructor(int.class).newInstance(currentid);
        PacketHandler.packetlist.add(instance);
        PacketHandler.packetmap.put((Class<? extends ModernPacket>) cls, instance);
        currentid++;
    }
}
Also used : ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) ArrayList(java.util.ArrayList) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo) SneakyThrows(lombok.SneakyThrows)

Example 2 with ClassInfo

use of com.google.common.reflect.ClassPath.ClassInfo in project accumulo by apache.

the class IteratorTestCaseFinder method findAllTestCases.

/**
 * Instantiates all test cases provided.
 *
 * @return A list of {@link IteratorTestCase}s.
 */
public static List<IteratorTestCase> findAllTestCases() {
    log.info("Searching {}", IteratorTestCase.class.getPackage().getName());
    ClassPath cp;
    try {
        cp = ClassPath.from(IteratorTestCaseFinder.class.getClassLoader());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ImmutableSet<ClassInfo> classes = cp.getTopLevelClasses(IteratorTestCase.class.getPackage().getName());
    final List<IteratorTestCase> testCases = new ArrayList<>();
    // final Set<Class<? extends IteratorTestCase>> classes = reflections.getSubTypesOf(IteratorTestCase.class);
    for (ClassInfo classInfo : classes) {
        Class<?> clz;
        try {
            clz = Class.forName(classInfo.getName());
        } catch (Exception e) {
            log.warn("Could not get class for " + classInfo.getName(), e);
            continue;
        }
        if (clz.isInterface() || Modifier.isAbstract(clz.getModifiers()) || !IteratorTestCase.class.isAssignableFrom(clz)) {
            log.debug("Skipping " + clz);
            continue;
        }
        try {
            testCases.add((IteratorTestCase) clz.newInstance());
        } catch (IllegalAccessException | InstantiationException e) {
            log.warn("Could not instantiate {}", clz, e);
        }
    }
    return testCases;
}
Also used : ClassPath(com.google.common.reflect.ClassPath) IteratorTestCase(org.apache.accumulo.iteratortest.testcases.IteratorTestCase) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

Example 3 with ClassInfo

use of com.google.common.reflect.ClassPath.ClassInfo in project closure-templates by google.

the class CopyPolicyTest method testCopy.

@Test
public void testCopy() throws IOException {
    // We use top level classes to ignore node types defined as inner classes for tests.
    ImmutableSet<ClassInfo> topLevelClasses = ClassPath.from(ClassLoader.getSystemClassLoader()).getTopLevelClasses();
    Set<String> errors = new LinkedHashSet<>();
    for (ClassInfo clazz : topLevelClasses) {
        if (clazz.getPackageName().startsWith("com.google.template.soy")) {
            Class<?> cls = clazz.load();
            if (Node.class.isAssignableFrom(cls)) {
                if (cls.isInterface()) {
                    continue;
                }
                if (Modifier.isAbstract(cls.getModifiers())) {
                    checkAbstractNode(cls, errors);
                } else {
                    checkConcreteNode(cls, errors);
                }
            }
        }
    }
    if (!errors.isEmpty()) {
        fail("Copy policy failure:\n" + Joiner.on('\n').join(errors));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo) Test(org.junit.Test)

Example 4 with ClassInfo

use of com.google.common.reflect.ClassPath.ClassInfo in project runelite by runelite.

the class PluginManagerTest method before.

@Before
public void before() throws IOException {
    RuneLite.setOptions(mock(OptionSet.class));
    Injector injector = Guice.createInjector(new RuneLiteModule(), BoundFieldModule.of(this));
    RuneLite.setInjector(injector);
    runelite = injector.getInstance(RuneLite.class);
    // Find plugins we expect to have
    pluginClasses = new HashSet<>();
    Set<ClassInfo> classes = ClassPath.from(getClass().getClassLoader()).getTopLevelClassesRecursive(PLUGIN_PACKAGE);
    for (ClassInfo classInfo : classes) {
        Class<?> clazz = classInfo.load();
        PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
        if (pluginDescriptor != null) {
            pluginClasses.add(clazz);
        }
    }
}
Also used : Injector(com.google.inject.Injector) RuneLite(net.runelite.client.RuneLite) OptionSet(joptsimple.OptionSet) RuneLiteModule(net.runelite.client.RuneLiteModule) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo) Before(org.junit.Before)

Example 5 with ClassInfo

use of com.google.common.reflect.ClassPath.ClassInfo in project runelite by runelite.

the class MixinInjector method inject.

public void inject() throws InjectionException {
    ClassPath classPath;
    try {
        classPath = ClassPath.from(this.getClass().getClassLoader());
    } catch (IOException ex) {
        throw new InjectionException(ex);
    }
    // key: mixin class
    // value: mixin targets
    Map<Class<?>, List<ClassFile>> mixinClasses = new HashMap<>();
    // Find mixins and populate mixinClasses
    for (ClassInfo classInfo : classPath.getTopLevelClasses(MIXIN_BASE)) {
        Class<?> mixinClass = classInfo.load();
        List<ClassFile> mixinTargets = new ArrayList<>();
        for (Mixin mixin : mixinClass.getAnnotationsByType(Mixin.class)) {
            Class<?> implementInto = mixin.value();
            ClassFile targetCf = inject.findVanillaForInterface(implementInto);
            if (targetCf == null) {
                throw new InjectionException("No class implements " + implementInto + " for mixin " + mixinClass);
            }
            mixinTargets.add(targetCf);
        }
        mixinClasses.put(mixinClass, mixinTargets);
    }
    inject(mixinClasses);
}
Also used : ClassPath(com.google.common.reflect.ClassPath) ClassFile(net.runelite.asm.ClassFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Mixin(net.runelite.api.mixins.Mixin) ArrayList(java.util.ArrayList) List(java.util.List) ClassInfo(com.google.common.reflect.ClassPath.ClassInfo)

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