use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class PluginCache method scanPlugins.
public Set<CtClass> scanPlugins(ClassLoader classLoader) throws IOException {
if (!pluginDefs.containsKey(classLoader)) {
synchronized (pluginDefs) {
if (!pluginDefs.containsKey(classLoader)) {
final Set<CtClass> plugins = new HashSet<CtClass>();
final ClassPool classPool = ClassPool.getDefault();
scanner.scan(getClass().getClassLoader(), PLUGIN_PATH, new ScannerVisitor() {
@Override
public void visit(InputStream file) throws IOException {
plugins.add(classPool.makeClass(file));
}
});
}
}
}
return pluginDefs.get(classLoader);
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class AnnotationHelperTest method testHasAnnotationJavassist.
@Test
public void testHasAnnotationJavassist() throws Exception {
ClassPool ctPool = ClassPool.getDefault();
CtClass ctClass = ctPool.getCtClass(AnonymousClassPatchPlugin.class.getName());
assertTrue(AnnotationHelper.hasAnnotation(ctClass, "org.hotswap.agent.annotation.Plugin"));
assertFalse(AnnotationHelper.hasAnnotation(ctClass, "xxxx"));
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class PluginManagerInvokerTest method testBuildCallPluginMethod.
@Test
public void testBuildCallPluginMethod() throws Exception {
SimplePlugin plugin = new SimplePlugin();
registerPlugin(plugin);
// plugin.init(PluginManager.getInstance());
String s = PluginManagerInvoker.buildCallPluginMethod(plugin.getClass(), "callPluginMethod", "Boolean.TRUE", "java.lang.Boolean");
ClassPool classPool = ClassPool.getDefault();
classPool.appendSystemPath();
CtClass clazz = classPool.makeClass("Test");
clazz.addMethod(CtNewMethod.make("public void test() {" + s + "}", clazz));
Class<?> testClass = clazz.toClass();
Method testMethod = testClass.getDeclaredMethod("test");
testMethod.invoke(testClass.newInstance());
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class AnonymousClassInfoTest method getAnonymousCtClassInfo.
public AnonymousClassInfo getAnonymousCtClassInfo() throws NotFoundException, ClassNotFoundException, IOException, CannotCompileException {
Class clazz = getClass().getClassLoader().loadClass(AnonymousTestClass1.class.getName() + "$1");
ClassPool classPool = new ClassPool();
classPool.appendClassPath(new LoaderClassPath(getClass().getClassLoader()));
return new AnonymousClassInfo(classPool.get(clazz.getName()));
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class AnonymousClassInfosTest method getClassPoolInfos.
private AnonymousClassInfos getClassPoolInfos(Class clazz) throws ClassNotFoundException {
ClassPool classPool = new ClassPool();
classPool.insertClassPath(new LoaderClassPath(getClass().getClassLoader()));
return new AnonymousClassInfos(classPool, clazz.getName());
}
Aggregations