Search in sources :

Example 1 with ClassPool

use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.

the class EnhancerProxyCreater method getCp.

private ClassPool getCp(ClassLoader loader) {
    ClassPool cp = new ClassPool();
    cp.appendSystemPath();
    cp.appendClassPath(new LoaderClassPath(loader));
    return cp;
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath)

Example 2 with ClassPool

use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.

the class ProxyTransformationUtils method getClassPool.

/**
 * Creates one ClassPool per ClassLoader and caches it
 *
 * @param classLoader
 * @return
 */
public static ClassPool getClassPool(ClassLoader classLoader) {
    ClassPool classPool = classPoolMap.get(classLoader);
    if (classPool == null) {
        synchronized (classPoolMap) {
            classPool = classPoolMap.get(classLoader);
            if (classPool == null) {
                classPool = createClassPool(classLoader);
                classPoolMap.put(classLoader, classPool);
            }
        }
    }
    return classPool;
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool)

Example 3 with ClassPool

use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.

the class ProxyTransformationUtils method createClassPool.

/**
 * Creates a ClassPool with supplied ClassLoader
 *
 * @param classLoader
 * @return
 */
public static ClassPool createClassPool(final ClassLoader classLoader) {
    ClassPool cp = new ClassPool() {

        @Override
        public ClassLoader getClassLoader() {
            return classLoader;
        }
    };
    cp.appendSystemPath();
    if (classLoader != null) {
        LOGGER.trace("Adding loader classpath " + classLoader);
        cp.appendClassPath(new LoaderClassPath(classLoader));
    }
    return cp;
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath)

Example 4 with ClassPool

use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.

the class Analyzer method buildExceptionInfo.

private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
    ConstPool constPool = method.getConstPool();
    ClassPool classes = clazz.getClassPool();
    ExceptionTable table = method.getCodeAttribute().getExceptionTable();
    ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
    for (int i = 0; i < table.size(); i++) {
        int index = table.catchType(i);
        Type type;
        try {
            type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
        } catch (NotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }
        exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
    }
    return exceptions;
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) ClassPool(org.hotswap.agent.javassist.ClassPool) NotFoundException(org.hotswap.agent.javassist.NotFoundException) ExceptionTable(org.hotswap.agent.javassist.bytecode.ExceptionTable)

Example 5 with ClassPool

use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.

the class WatchEventCommand method createCtClass.

/**
 * Creats javaassist CtClass for bytecode manipulation. Add default classloader.
 *
 * @param uri         uri
 * @param classLoader loader
 * @return created class
 * @throws org.hotswap.agent.javassist.NotFoundException
 */
private CtClass createCtClass(URI uri, ClassLoader classLoader) throws NotFoundException, IOException {
    ClassPool cp = new ClassPool();
    cp.appendClassPath(new LoaderClassPath(classLoader));
    return cp.makeClass(new ByteArrayInputStream(IOUtils.toByteArray(uri)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClassPool(org.hotswap.agent.javassist.ClassPool) 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