use of org.hotswap.agent.javassist.CannotCompileException in project HotswapAgent by HotswapProjects.
the class DeltaSpikeProxyTransformer method patchAsmProxyClassGenerator.
/**
* Delegates loadClass to org.hotswap.agent.plugin.deltaspike.proxy.ProxyClassLoadingDelegate::loadClass
*
* @param ctClass
* @throws NotFoundException the not found exception
* @throws CannotCompileException the cannot compile exception
*/
@OnClassLoadEvent(classNameRegexp = "org.apache.deltaspike.proxy.impl.AsmProxyClassGenerator")
public static void patchAsmProxyClassGenerator(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod generateProxyClassMethod = ctClass.getDeclaredMethod("generateProxyClass");
generateProxyClassMethod.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("org.apache.deltaspike.proxy.impl.AsmProxyClassGenerator") && m.getMethodName().equals("loadClass"))
m.replace("{ $_ = org.hotswap.agent.plugin.deltaspike.proxy.ProxyClassLoadingDelegate.loadClass($$); }");
}
});
}
use of org.hotswap.agent.javassist.CannotCompileException in project HotswapAgent by HotswapProjects.
the class ViewConfigTransformer method patchViewConfigExtension.
/**
* Register DeltaspikePlugin and add reinitialization method to RepositoryComponent
*
* @param ctClass
* @param classPool the class pool
* @throws CannotCompileException the cannot compile exception
* @throws NotFoundException the not found exception
*/
@OnClassLoadEvent(classNameRegexp = "org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension")
public static void patchViewConfigExtension(CtClass ctClass, ClassPool classPool) throws CannotCompileException, NotFoundException {
CtMethod init = ctClass.getDeclaredMethod("init");
init.insertAfter("{" + "if (this.isActivated) {" + PluginManagerInvoker.buildInitializePlugin(DeltaSpikePlugin.class) + "}" + "}");
LOGGER.debug("org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension enhanced with plugin initialization.");
CtClass viewConfigResProxyClass = classPool.get("org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverProxy");
CtField viewConfigResProxyField = new CtField(viewConfigResProxyClass, VIEW_CONFIG_RESOLVER_PROXY_FIELD, ctClass);
ctClass.addField(viewConfigResProxyField);
CtMethod generateProxyClassMethod = ctClass.getDeclaredMethod("transformMetaDataTree");
generateProxyClassMethod.instrument(new ExprEditor() {
public void edit(NewExpr e) throws CannotCompileException {
if (e.getClassName().equals("org.apache.deltaspike.jsf.impl.config.view.DefaultViewConfigResolver"))
e.replace("{ " + "java.lang.Object _resolver = new org.apache.deltaspike.jsf.impl.config.view.DefaultViewConfigResolver($$); " + "if (this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + "==null) {" + "this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + "=new org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverProxy();" + "}" + "this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + ".setViewConfigResolver(_resolver);" + "java.util.List _list = org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverUtils.findViewConfigRootClasses(this.rootViewConfigNode);" + PluginManagerInvoker.buildCallPluginMethod(DeltaSpikePlugin.class, "registerViewConfigRootClasses", "this", "java.lang.Object", "_list", "java.util.List") + " $_ = this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + ";" + "}");
}
});
}
use of org.hotswap.agent.javassist.CannotCompileException 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.CannotCompileException 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;
}
use of org.hotswap.agent.javassist.CannotCompileException in project HotswapAgent by HotswapProjects.
the class ClassFile method setSuperclass.
/**
* Sets the super class.
*
* <p>
* The new super class should inherit from the old super class.
* This method modifies constructors so that they call constructors declared
* in the new super class.
*/
public void setSuperclass(String superclass) throws CannotCompileException {
if (superclass == null)
superclass = "java.lang.Object";
try {
this.superClass = constPool.addClassInfo(superclass);
ArrayList list = methods;
int n = list.size();
for (int i = 0; i < n; ++i) {
MethodInfo minfo = (MethodInfo) list.get(i);
minfo.setSuperclass(superclass);
}
} catch (BadBytecode e) {
throw new CannotCompileException(e);
}
cachedSuperclass = superclass;
}
Aggregations