Search in sources :

Example 6 with NotFoundException

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

the class JettyPlugin method patchWebXmlConfiguration6x.

// same as above for older jetty versions
@OnClassLoadEvent(classNameRegexp = "org.mortbay.jetty.webapp.WebXmlConfiguration")
public static void patchWebXmlConfiguration6x(CtClass ctClass) throws NotFoundException, CannotCompileException, ClassNotFoundException {
    try {
        // after application context initialized, but before processing started
        CtMethod doStart = ctClass.getDeclaredMethod("configureWebApp");
        // init the plugin
        String src = PluginManagerInvoker.buildInitializePlugin(JettyPlugin.class, "getWebAppContext().getClassLoader()");
        src += PluginManagerInvoker.buildCallPluginMethod("getWebAppContext().getClassLoader()", JettyPlugin.class, "init", "getWebAppContext()", "java.lang.Object");
        doStart.insertBefore(src);
    } catch (NotFoundException e) {
        LOGGER.warning("org.mortbay.jetty.webapp.WebXmlConfiguration does not contain startContext method. Jetty plugin will be disabled.\n" + "*** This is Ok, Jetty plugin handles only special properties ***");
        return;
    }
}
Also used : NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 7 with NotFoundException

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

the class ModuleClassLoaderTransformer method patchModuleClassLoader.

/**
 * @param ctClass the ct class
 * @throws NotFoundException the not found exception
 * @throws CannotCompileException the cannot compile exception
 */
@OnClassLoadEvent(classNameRegexp = "org.jboss.modules.ModuleClassLoader")
public static void patchModuleClassLoader(ClassPool classPool, CtClass ctClass) throws CannotCompileException {
    try {
        CtField pathField = ctClass.getDeclaredField("paths");
        CtClass pathsType = pathField.getType();
        String pathsGetter = "";
        CtClass ctHaClassLoader = classPool.get(HotswapAgentClassLoaderExt.class.getName());
        ctClass.addInterface(ctHaClassLoader);
        if ("java.util.concurrent.atomic.AtomicReference".equals(pathsType.getName())) {
            // version>=1.5
            pathsGetter = ".get()";
        }
        CtClass objectClass = classPool.get(Object.class.getName());
        CtField ctField = new CtField(objectClass, "$$ha$prepend", ctClass);
        ctClass.addField(ctField);
        ctClass.addMethod(CtNewMethod.make("private void $$ha$setupPrepend() {" + "       Class clPaths = Class.forName(\"org.jboss.modules.Paths\", true, this.getClass().getClassLoader());" + "       java.lang.reflect.Method spM  = clPaths.getDeclaredMethod(\"$$ha$setPrepend\", new Class[] {java.lang.Object.class});" + "       spM.invoke(this.paths" + pathsGetter + ", new java.lang.Object[] { $$ha$prepend });" + "}", ctClass));
        // Implementation of HotswapAgentClassLoaderExt.setExtraClassPath(...)
        ctClass.addMethod(CtNewMethod.make("public void setExtraClassPath(java.net.URL[] extraClassPath) {" + "   try {" + "       java.util.List resLoaderList = new java.util.ArrayList();" + "       for (int i=0; i<extraClassPath.length; i++) {" + "           try {" + "               java.net.URL url = extraClassPath[i];" + "               java.io.File root = new java.io.File(url.getPath());" + "               org.jboss.modules.ResourceLoader resourceLoader = org.jboss.modules.ResourceLoaders.createFileResourceLoader(url.getPath(), root);" + "               resLoaderList.add(resourceLoader);" + "           } catch (java.lang.Exception e) {" + "           " + ModuleClassLoaderTransformer.class.getName() + ".logSetExtraClassPathException(e);" + "           }" + "       }" + "       this.$$ha$prepend = resLoaderList;" + "       $$ha$setupPrepend();" + "   } catch (java.lang.Exception e) {" + "       " + ModuleClassLoaderTransformer.class.getName() + ".logSetExtraClassPathException(e);" + "   }" + "}", ctClass));
        CtMethod methRecalculate = ctClass.getDeclaredMethod("recalculate");
        methRecalculate.setName("_recalculate");
        ctClass.addMethod(CtNewMethod.make("boolean recalculate() {" + "   boolean ret = _recalculate();" + "   $$ha$setupPrepend();" + "   return ret;" + "}", ctClass));
        CtClass ctResLoadClass = classPool.get("org.jboss.modules.ResourceLoaderSpec[]");
        CtMethod methResourceLoaders = ctClass.getDeclaredMethod("setResourceLoaders", new CtClass[] { ctResLoadClass });
        methResourceLoaders.setBody("{" + "   boolean ret = setResourceLoaders((org.jboss.modules.Paths)this.paths" + pathsGetter + ", $1);" + "   $$ha$setupPrepend();" + "   return ret;" + "}");
    } catch (NotFoundException e) {
        LOGGER.warning("Unable to find field \"paths\" in org.jboss.modules.ModuleClassLoader.", e);
    }
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) CtField(org.hotswap.agent.javassist.CtField) NotFoundException(org.hotswap.agent.javassist.NotFoundException) HotswapAgentClassLoaderExt(org.hotswap.agent.util.classloader.HotswapAgentClassLoaderExt) CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 8 with NotFoundException

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

the class ModuleClassLoaderTransformer method patchModulesPaths.

/**
 * @param classPool the class pool
 * @param ctClass the ct class
 * @throws NotFoundException the not found exception
 * @throws CannotCompileException the cannot compile exception
 */
@OnClassLoadEvent(classNameRegexp = "org.jboss.modules.Paths")
public static void patchModulesPaths(ClassPool classPool, CtClass ctClass) throws NotFoundException, CannotCompileException {
    CtClass objectClass = classPool.get(Object.class.getName());
    CtField ctField = new CtField(objectClass, "$$ha$prepend", ctClass);
    ctClass.addField(ctField);
    try {
        CtMethod methGetAllPaths = ctClass.getDeclaredMethod("getAllPaths");
        methGetAllPaths.setBody("{" + "   if (this.$$ha$prepend != null) {" + "       java.util.Map result = new org.hotswap.agent.plugin.jbossmodules.PrependingMap(this.allPaths, this.$$ha$prepend);" + "       return result;" + "   }" + "   return this.allPaths;" + "}");
        ctClass.addMethod(CtNewMethod.make("public void $$ha$setPrepend(java.lang.Object prepend) {" + "   this.$$ha$prepend = prepend; " + "}", ctClass));
    } catch (NotFoundException e) {
        LOGGER.warning("Unable to find method \"getAllPaths()\" in org.jboss.modules.Paths.", e);
    }
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) CtField(org.hotswap.agent.javassist.CtField) NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 9 with NotFoundException

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

the class ELResolverPlugin method checkApacheEL.

private static boolean checkApacheEL(CtClass ctClass) {
    try {
        // ApacheEL has field cache
        CtField field = ctClass.getField("cache");
        // Apache BeanELResolver (has cache property)
        ctClass.addField(new CtField(CtClass.booleanType, "$$ha$purgeRequested", ctClass), CtField.Initializer.constant(false));
        ctClass.addMethod(CtNewMethod.make("public void " + PURGE_CLASS_CACHE_METHOD_NAME + "(java.lang.ClassLoader classLoader) {" + "$$ha$purgeRequested=true;" + "}", ctClass));
        CtMethod mGetBeanProperty = ctClass.getDeclaredMethod("property");
        mGetBeanProperty.insertBefore("if($$ha$purgeRequested) {" + "$$ha$purgeRequested=false;" + "this.cache = new javax.el.BeanELResolver.ConcurrentCache(CACHE_SIZE); " + "}");
        return true;
    } catch (NotFoundException e1) {
    } catch (CannotCompileException e2) {
    }
    return false;
}
Also used : CtField(org.hotswap.agent.javassist.CtField) NotFoundException(org.hotswap.agent.javassist.NotFoundException) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) CtMethod(org.hotswap.agent.javassist.CtMethod)

Example 10 with NotFoundException

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

the class ELResolverPlugin method checkJuelEL.

private static boolean checkJuelEL(CtClass ctClass) {
    try {
        // JUEL, (JSF BeanELResolver[s])
        // check if we have purgeBeanClasses method
        CtMethod purgeMeth = ctClass.getDeclaredMethod("purgeBeanClasses");
        ctClass.addMethod(CtNewMethod.make("public void " + PURGE_CLASS_CACHE_METHOD_NAME + "(java.lang.ClassLoader classLoader) {" + "purgeBeanClasses(classLoader);" + "}", ctClass));
        return true;
    } catch (NotFoundException | CannotCompileException e) {
    // purgeBeanClasses method not found -do nothing
    }
    return false;
}
Also used : NotFoundException(org.hotswap.agent.javassist.NotFoundException) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) CtMethod(org.hotswap.agent.javassist.CtMethod)

Aggregations

NotFoundException (org.hotswap.agent.javassist.NotFoundException)33 CtClass (org.hotswap.agent.javassist.CtClass)19 CtMethod (org.hotswap.agent.javassist.CtMethod)15 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)8 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)8 CtField (org.hotswap.agent.javassist.CtField)7 CtConstructor (org.hotswap.agent.javassist.CtConstructor)5 ClassPool (org.hotswap.agent.javassist.ClassPool)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)2 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)2 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)2 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1