Search in sources :

Example 11 with ClassPool

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

the class framedump method main.

/**
 * Main method.
 *
 * @param args <code>args[0]</code> is the class file name.
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Usage: java javassist.tools.framedump <fully-qualified class name>");
        return;
    }
    ClassPool pool = ClassPool.getDefault();
    CtClass clazz = pool.get(args[0]);
    System.out.println("Frame Dump of " + clazz.getName() + ":");
    FramePrinter.print(clazz, System.out);
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool)

Example 12 with ClassPool

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

the class Compiler method processClasses.

private static void processClasses(CompiledClass[] entries, int n) throws Exception {
    Reflection implementor = new Reflection();
    ClassPool pool = ClassPool.getDefault();
    implementor.start(pool);
    for (int i = 0; i < n; ++i) {
        CtClass c = pool.get(entries[i].classname);
        if (entries[i].metaobject != null || entries[i].classobject != null) {
            String metaobj, classobj;
            if (entries[i].metaobject == null)
                metaobj = "javassist.tools.reflect.Metaobject";
            else
                metaobj = entries[i].metaobject;
            if (entries[i].classobject == null)
                classobj = "javassist.tools.reflect.ClassMetaobject";
            else
                classobj = entries[i].classobject;
            if (!implementor.makeReflective(c, pool.get(metaobj), pool.get(classobj)))
                System.err.println("Warning: " + c.getName() + " is reflective.  It was not changed.");
            System.err.println(c.getName() + ": " + metaobj + ", " + classobj);
        } else
            System.err.println(c.getName() + ": not reflective");
    }
    for (int i = 0; i < n; ++i) {
        implementor.onLoad(pool, entries[i].classname);
        pool.get(entries[i].classname).writeFile();
    }
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool)

Example 13 with ClassPool

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

the class EnhancerProxyCreater method getProxyCreationMethod.

private Method getProxyCreationMethod(Object bean) throws CannotCompileException, NotFoundException {
    if (getCp(loader).find("org.springframework.cglib.proxy.MethodInterceptor") != null) {
        if (createSpringProxy == null) {
            synchronized (springLock) {
                if (createSpringProxy == null) {
                    ClassPool cp = getCp(loader);
                    springCallback = buildProxyCallbackClass(SPRING_PACKAGE, cp);
                    springNamingPolicy = buildNamingPolicyClass(SPRING_PACKAGE, cp);
                    springProxy = buildProxyCreaterClass(SPRING_PACKAGE, springCallback, springNamingPolicy, cp);
                    createSpringProxy = springProxy.getDeclaredMethods()[0];
                }
            }
        }
        return createSpringProxy;
    } else if (getCp(loader).find("net.sf.cglib.proxy.MethodInterceptor") != null) {
        if (createCglibProxy == null) {
            synchronized (cglibLock) {
                if (createCglibProxy == null) {
                    ClassPool cp = getCp(loader);
                    cglibCallback = buildProxyCallbackClass(CGLIB_PACKAGE, cp);
                    cglibNamingPolicy = buildNamingPolicyClass(CGLIB_PACKAGE, cp);
                    cglibProxy = buildProxyCreaterClass(CGLIB_PACKAGE, cglibCallback, cglibNamingPolicy, cp);
                    createCglibProxy = cglibProxy.getDeclaredMethods()[0];
                }
            }
        }
        return createCglibProxy;
    } else {
        LOGGER.error("Unable to determine the location of the Cglib package");
        return null;
    }
}
Also used : ClassPool(org.hotswap.agent.javassist.ClassPool)

Example 14 with ClassPool

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

the class ComponentScanWithWildcardsTest method copyClassFile.

public static File copyClassFile(Class<?> clazz, String newName) throws Exception {
    String directoryName = clazz.getClassLoader().getResource("").getPath();
    ClassPool classPool = new ClassPool();
    classPool.appendClassPath(new LoaderClassPath(clazz.getClassLoader()));
    CtClass ctClass = classPool.getAndRename(clazz.getName(), newName);
    ctClass.writeFile(directoryName);
    File file = new File(directoryName + File.separatorChar + newName.replace('.', File.separatorChar) + ".class");
    assertTrue(file.exists());
    return file;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) ClassPool(org.hotswap.agent.javassist.ClassPool) LoaderClassPath(org.hotswap.agent.javassist.LoaderClassPath) File(java.io.File)

Example 15 with ClassPool

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

the class HotswapWebObjectsPlugin method init.

// We use reflection to get the methods from WebObjects because the jar is not distribuable publicly
// and we want to build witout it.
@Init
@SuppressWarnings({ "rawtypes", "unchecked" })
public void init(PluginConfiguration pluginConfiguration, ClassLoader appClassLoader) {
    try {
        Class kvcDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$DefaultImplementation", false, appClassLoader);
        kvcDefaultImplementation_flushCaches = kvcDefaultImplementationClass.getMethod("_flushCaches");
        Class kvcReflectionKeyBindingCreationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$_ReflectionKeyBindingCreation", false, appClassLoader);
        kvcReflectionKeyBindingCreation_flushCaches = kvcReflectionKeyBindingCreationClass.getMethod("_flushCaches");
        Class kvcValueAccessorClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$ValueAccessor", false, appClassLoader);
        kvcValueAccessor_flushCaches = kvcValueAccessorClass.getMethod("_flushCaches");
        Class nsValidationDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSValidation$DefaultImplementation", false, appClassLoader);
        nsValidationDefaultImplementation_flushCaches = nsValidationDefaultImplementationClass.getMethod("_flushCaches");
        Class woApplicationClass = Class.forName("com.webobjects.appserver.WOApplication", false, appClassLoader);
        woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
        woApplicationObject = woApplicationClass.getMethod("application").invoke(null);
        ClassPool classPool = ClassPool.getDefault();
        woComponentCtClass = classPool.makeClass("com.webobjects.appserver.WOComponent");
        nsValidationCtClass = classPool.makeClass("com.webobjects.foundation.NSValidation");
        woActionCtClass = classPool.makeClass("com.webobjects.appserver.WOAction");
        Class woActionClass = Class.forName("com.webobjects.appserver.WOAction", false, appClassLoader);
        Field actionClassesField = woActionClass.getDeclaredField("_actionClasses");
        actionClassesField.setAccessible(true);
        actionClassesCacheDictionnary = actionClassesField.get(null);
        Class nsThreadsafeMutableDictionaryClass = Class.forName("com.webobjects.foundation._NSThreadsafeMutableDictionary", false, appClassLoader);
        woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
        nsThreadsafeMutableDictionary_removeAllObjects = nsThreadsafeMutableDictionaryClass.getMethod("removeAllObjects");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) ClassPool(org.hotswap.agent.javassist.ClassPool) CtClass(org.hotswap.agent.javassist.CtClass) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotFoundException(org.hotswap.agent.javassist.NotFoundException) Init(org.hotswap.agent.annotation.Init)

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