Search in sources :

Example 16 with ClassPool

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);
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) InputStream(java.io.InputStream) ClassPool(org.hotswap.agent.javassist.ClassPool) IOException(java.io.IOException)

Example 17 with ClassPool

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"));
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool) AnonymousClassPatchPlugin(org.hotswap.agent.plugin.jvm.AnonymousClassPatchPlugin) Test(org.junit.Test)

Example 18 with ClassPool

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());
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool) SimplePlugin(org.hotswap.agent.testData.SimplePlugin) CtNewMethod(org.hotswap.agent.javassist.CtNewMethod) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 19 with ClassPool

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()));
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath) AnonymousClassInfo(org.hotswap.agent.plugin.jvm.AnonymousClassInfo)

Example 20 with ClassPool

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());
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool) AnonymousClassInfos(org.hotswap.agent.plugin.jvm.AnonymousClassInfos) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath)

Aggregations

ClassPool (org.hotswap.agent.javassist.ClassPool)23 CtClass (org.hotswap.agent.javassist.CtClass)14 LoaderClassPath (org.hotswap.agent.javassist.LoaderClassPath)12 NotFoundException (org.hotswap.agent.javassist.NotFoundException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)2 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)2 Test (org.junit.Test)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ProtectionDomain (java.security.ProtectionDomain)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Init (org.hotswap.agent.annotation.Init)1 LoadEvent (org.hotswap.agent.annotation.LoadEvent)1