Search in sources :

Example 1 with LoaderClassPath

use of org.hotswap.agent.javassist.LoaderClassPath 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 LoaderClassPath

use of org.hotswap.agent.javassist.LoaderClassPath 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 3 with LoaderClassPath

use of org.hotswap.agent.javassist.LoaderClassPath 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)

Example 4 with LoaderClassPath

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

the class HotSwapperJpda method swapClasses.

/**
 * Swap class definition from another class file.
 * <p/>
 * This is mainly useful for unit testing - declare multiple version of a class and then
 * hotswap definition and do the tests.
 *
 * @param original original class currently in use
 * @param swap     fully qualified class name of class to swap
 * @throws Exception swap exception
 */
public void swapClasses(Class original, String swap) throws Exception {
    // need to recreate classpool on each swap to avoid stale class definition
    ClassPool classPool = new ClassPool();
    classPool.appendClassPath(new LoaderClassPath(original.getClassLoader()));
    CtClass ctClass = classPool.getAndRename(swap, original.getName());
    reload(original.getName(), ctClass.toBytecode());
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath)

Example 5 with LoaderClassPath

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

the class HotSwapper method swapClasses.

/**
 * Swap class definition from another class file.
 * <p/>
 * This is mainly useful for unit testing - declare multiple version of a class and then
 * hotswap definition and do the tests.
 *
 * @param original original class currently in use
 * @param swap     fully qualified class name of class to swap
 * @throws Exception swap exception
 */
public static void swapClasses(Class original, String swap) throws Exception {
    // need to recreate classpool on each swap to avoid stale class definition
    ClassPool classPool = new ClassPool();
    classPool.appendClassPath(new LoaderClassPath(original.getClassLoader()));
    CtClass ctClass = classPool.getAndRename(swap, original.getName());
    reload(original, ctClass.toBytecode());
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath)

Aggregations

ClassPool (org.hotswap.agent.javassist.ClassPool)12 LoaderClassPath (org.hotswap.agent.javassist.LoaderClassPath)12 CtClass (org.hotswap.agent.javassist.CtClass)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ProtectionDomain (java.security.ProtectionDomain)1 ArrayList (java.util.ArrayList)1 LoadEvent (org.hotswap.agent.annotation.LoadEvent)1 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)1 AnonymousClassInfo (org.hotswap.agent.plugin.jvm.AnonymousClassInfo)1 AnonymousClassInfos (org.hotswap.agent.plugin.jvm.AnonymousClassInfos)1 AppClassLoaderExecutor (org.hotswap.agent.util.AppClassLoaderExecutor)1