use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ELResolverPlugin method patchJBossEl.
/*
* JBossEL has weak reference cache. Values are stored in ThreadGroupContext cache, that must be flushed from appropriate thread.
* Therefore we must create request for cleanup cache in PURGE_CLASS_CACHE_METHOD and own cleanup is executed indirectly when
* application calls getBeanProperty(...).
*/
private static void patchJBossEl(CtClass ctClass) {
try {
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));
try {
CtMethod mGetBeanProperty = ctClass.getDeclaredMethod("getBeanProperty");
mGetBeanProperty.insertBefore("if($$ha$purgeRequested) {" + "$$ha$purgeRequested=false;" + "java.lang.reflect.Method meth = javax.el.BeanELResolver.SoftConcurrentHashMap.class.getDeclaredMethod(\"$$ha$createNewInstance\", null);" + "properties = (javax.el.BeanELResolver.SoftConcurrentHashMap) meth.invoke(properties, null);" + "}");
} catch (NotFoundException e) {
LOGGER.debug("FIXME : checkJBoss_3_0_EL() 'getBeanProperty(...)' not found in javax.el.BeanELResolver.");
}
} catch (CannotCompileException e) {
LOGGER.error("patchJBossEl() exception {}", e.getMessage());
}
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class AbstractClassBeanTransformer method transformAbstractClassBean.
/**
* @param ctClass
* @param classPool
* @throws NotFoundException
* @throws CannotCompileException
*/
@OnClassLoadEvent(classNameRegexp = "org.jboss.weld.bean.AbstractClassBean")
public static void transformAbstractClassBean(CtClass ctClass, ClassPool classPool) throws NotFoundException, CannotCompileException {
CtMethod method = ctClass.getDeclaredMethod("cleanupAfterBoot");
method.setBody("{ }");
LOGGER.debug("AbstractClassBean.cleanupAfterBoot patched");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class CdiContextsTransformer method transformReloadingWeldContexts.
/**
* Add context reloading functionality to base contexts classes.
*
* @param ctClass the class
* @param classPool the class pool
* @throws NotFoundException the not found exception
* @throws CannotCompileException the cannot compile exception
*/
@OnClassLoadEvent(classNameRegexp = "(org.jboss.weld.context.AbstractManagedContext)|" + "(org.jboss.weld.context.AbstractSharedContext)|" + "(org.jboss.weld.context.unbound.DependentContextImpl)|" + "(org.jboss.weld.util.ForwardingContext)|" + "(org.apache.myfaces.flow.cdi.FlowScopedContextImpl)|" + "(org.apache.myfaces.cdi.view.ViewScopeContextImpl)")
public static void transformReloadingWeldContexts(CtClass ctClass, ClassPool classPool) throws NotFoundException, CannotCompileException {
LOGGER.debug("Adding interface {} to {}.", WeldHotswapContext.class.getName(), ctClass.getName());
ctClass.addInterface(classPool.get(WeldHotswapContext.class.getName()));
CtField toReloadFld = CtField.make("public transient java.util.Set $$ha$toReloadWeld = null;", ctClass);
ctClass.addField(toReloadFld);
CtField reloadingFld = CtField.make("public transient boolean $$ha$reloadingWeld = false;", ctClass);
ctClass.addField(reloadingFld);
CtMethod addBeanToReload = CtMethod.make("public void $$ha$addBeanToReloadWeld(javax.enterprise.context.spi.Contextual bean) {" + "if ($$ha$toReloadWeld == null)" + "$$ha$toReloadWeld = new java.util.HashSet();" + "$$ha$toReloadWeld.add(bean);" + "}", ctClass);
ctClass.addMethod(addBeanToReload);
CtMethod getBeansToReload = CtMethod.make("public java.util.Set $$ha$getBeansToReloadWeld(){return $$ha$toReloadWeld;}", ctClass);
ctClass.addMethod(getBeansToReload);
CtMethod reload = CtMethod.make("public void $$ha$reloadWeld() {" + ContextualReloadHelper.class.getName() + ".reload(this);}", ctClass);
ctClass.addMethod(reload);
CtMethod isActive = ctClass.getDeclaredMethod("isActive");
isActive.insertAfter("{" + "if($_ && !$$ha$reloadingWeld ) { " + "$$ha$reloadingWeld = true;" + "$$ha$reloadWeld();" + "$$ha$reloadingWeld = false;" + "}" + "return $_;" + "}");
LOGGER.debug("Class '{}' patched with hot-swapping support", ctClass.getName());
}
Aggregations