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;
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations