use of com.google.common.reflect.ClassPath.ClassInfo in project runelite by runelite.
the class PluginManager method scanAndInstantiate.
List<Plugin> scanAndInstantiate(ClassLoader classLoader, String packageName) throws IOException {
boolean developerPlugins = RuneLite.getOptions().has("developer-mode");
MutableGraph<Class<? extends Plugin>> graph = GraphBuilder.directed().build();
List<Plugin> scannedPlugins = new ArrayList<>();
ClassPath classPath = ClassPath.from(classLoader);
ImmutableSet<ClassInfo> classes = packageName == null ? classPath.getAllClasses() : classPath.getTopLevelClassesRecursive(packageName);
for (ClassInfo classInfo : classes) {
Class<?> clazz = classInfo.load();
PluginDescriptor pluginDescriptor = clazz.getAnnotation(PluginDescriptor.class);
if (pluginDescriptor == null) {
if (clazz.getSuperclass() == Plugin.class) {
log.warn("Class {} is a plugin, but has no plugin descriptor", clazz);
}
continue;
}
if (clazz.getSuperclass() != Plugin.class) {
log.warn("Class {} has plugin descriptor, but is not a plugin", clazz);
continue;
}
if (!pluginDescriptor.loadWhenOutdated() && isOutdated) {
continue;
}
if (pluginDescriptor.developerPlugin() && !developerPlugins) {
continue;
}
Class<Plugin> pluginClass = (Class<Plugin>) clazz;
graph.addNode(pluginClass);
}
// Build plugin graph
for (Class<? extends Plugin> pluginClazz : graph.nodes()) {
PluginDependency[] pluginDependencies = pluginClazz.getAnnotationsByType(PluginDependency.class);
for (PluginDependency pluginDependency : pluginDependencies) {
graph.putEdge(pluginClazz, pluginDependency.value());
}
}
if (Graphs.hasCycle(graph)) {
throw new RuntimeException("Plugin dependency graph contains a cycle!");
}
List<Class<? extends Plugin>> sortedPlugins = topologicalSort(graph);
sortedPlugins = Lists.reverse(sortedPlugins);
for (Class<? extends Plugin> pluginClazz : sortedPlugins) {
Plugin plugin;
try {
plugin = instantiate(scannedPlugins, (Class<Plugin>) pluginClazz);
} catch (PluginInstantiationException ex) {
log.warn("Error instantiating plugin!", ex);
continue;
}
scannedPlugins.add(plugin);
}
return scannedPlugins;
}
use of com.google.common.reflect.ClassPath.ClassInfo in project guava by google.
the class ClassPathTest method testGetSimpleName.
public void testGetSimpleName() {
ClassLoader classLoader = getClass().getClassLoader();
assertEquals("Foo", new ClassInfo(FILE, "Foo.class", classLoader).getSimpleName());
assertEquals("Foo", new ClassInfo(FILE, "a/b/Foo.class", classLoader).getSimpleName());
assertEquals("Foo", new ClassInfo(FILE, "a/b/Bar$Foo.class", classLoader).getSimpleName());
assertEquals("", new ClassInfo(FILE, "a/b/Bar$1.class", classLoader).getSimpleName());
assertEquals("Foo", new ClassInfo(FILE, "a/b/Bar$Foo.class", classLoader).getSimpleName());
assertEquals("", new ClassInfo(FILE, "a/b/Bar$1.class", classLoader).getSimpleName());
assertEquals("Local", new ClassInfo(FILE, "a/b/Bar$1Local.class", classLoader).getSimpleName());
}
use of com.google.common.reflect.ClassPath.ClassInfo in project grpc-java by grpc.
the class ChannelAndServerBuilderTest method params.
/**
* Javadoc.
*/
@Parameters(name = "class={0}")
public static Collection<Object[]> params() throws Exception {
ClassLoader loader = ChannelAndServerBuilderTest.class.getClassLoader();
Collection<ClassInfo> classInfos = ClassPath.from(loader).getTopLevelClassesRecursive("io.grpc");
// Java 9 doesn't expose the URLClassLoader, which breaks searching through the classpath
if (classInfos.isEmpty()) {
return new ArrayList<>();
}
List<Object[]> classes = new ArrayList<>();
for (ClassInfo classInfo : classInfos) {
String className = classInfo.getName();
if (className.contains("io.grpc.netty.shaded.io.netty")) {
continue;
}
Class<?> clazz = Class.forName(className, false, /*initialize*/
loader);
if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) {
classes.add(new Object[] { clazz });
} else if (ManagedChannelBuilder.class.isAssignableFrom(clazz) && clazz != ManagedChannelBuilder.class) {
classes.add(new Object[] { clazz });
}
}
Truth.assertWithMessage("Unable to find any builder classes").that(classes).isNotEmpty();
return classes;
}
Aggregations