use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class HotswapWebObjectsPlugin method webObjectsIsStarting.
@OnClassLoadEvent(classNameRegexp = "com.webobjects.appserver.WOApplication")
public static void webObjectsIsStarting(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod init = ctClass.getDeclaredMethod("run");
init.insertBefore(PluginManagerInvoker.buildInitializePlugin(HotswapWebObjectsPlugin.class));
LOGGER.debug("WOApplication.run() enhanced with plugin initialization.");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ProxyFactoryTransformer method patchProxyFactory.
/**
* Patch ProxyFactory class.
* - add factory registration into constructor
* - changes call classLoader.loadClass(...) in getProxyClass() to ProxyClassLoadingDelegate.loadClass(classLoader, ...)
* - changes call ClassFileUtils.toClass() in createProxyClass() to ProxyClassLoadingDelegate.loadClass(...)
*
* @param ctClass the ProxyFactory class
* @param classPool the class pool
* @throws NotFoundException the not found exception
* @throws CannotCompileException the cannot compile exception
*/
@OnClassLoadEvent(classNameRegexp = "org.jboss.weld.bean.proxy.ProxyFactory")
public static void patchProxyFactory(CtClass ctClass, ClassPool classPool) throws NotFoundException, CannotCompileException {
CtClass[] constructorParams = new CtClass[] { classPool.get("java.lang.String"), classPool.get("java.lang.Class"), classPool.get("java.util.Set"), // classPool.get("java.lang.String"),
classPool.get("javax.enterprise.inject.spi.Bean"), classPool.get("boolean") };
CtConstructor declaredConstructor = ctClass.getDeclaredConstructor(constructorParams);
// TODO : we should find constructor without this() call and put registration only into this one
declaredConstructor.insertAfter("if (" + PluginManager.class.getName() + ".getInstance().isPluginInitialized(\"" + WeldPlugin.class.getName() + "\", this.classLoader)) {" + PluginManagerInvoker.buildCallPluginMethod("this.classLoader", WeldPlugin.class, "registerProxyFactory", "this", "java.lang.Object", "bean", "java.lang.Object", "this.classLoader", "java.lang.ClassLoader", "proxiedBeanType", "java.lang.Class") + "}");
CtMethod getProxyClassMethod = ctClass.getDeclaredMethod("getProxyClass");
getProxyClassMethod.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getClassName().equals(ClassLoader.class.getName()) && m.getMethodName().equals("loadClass"))
m.replace("{ $_ = org.hotswap.agent.plugin.weld.command.ProxyClassLoadingDelegate.loadClass(this.classLoader,$1); }");
}
});
CtMethod createProxyClassMethod = ctClass.getDeclaredMethod("createProxyClass");
createProxyClassMethod.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("org.jboss.weld.util.bytecode.ClassFileUtils") && m.getMethodName().equals("toClass"))
m.replace("{ $_ = org.hotswap.agent.plugin.weld.command.ProxyClassLoadingDelegate.toClass($$); }");
}
});
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class DeltaSpikeProxyTransformer method instrumentTryToLoadClassForName.
private static void instrumentTryToLoadClassForName(CtClass ctClass, String methodName) throws CannotCompileException {
try {
CtMethod getProxyClassMethod = ctClass.getDeclaredMethod(methodName);
getProxyClassMethod.instrument(new ExprEditor() {
public void edit(MethodCall m) throws CannotCompileException {
if (m.getClassName().equals("org.apache.deltaspike.core.util.ClassUtils") && m.getMethodName().equals("tryToLoadClassForName"))
m.replace("{ $_ = org.hotswap.agent.plugin.deltaspike.proxy.ProxyClassLoadingDelegate.tryToLoadClassForName($$); }");
}
});
} catch (NotFoundException e) {
LOGGER.debug("Method '{}' not found in '{}'.", methodName, ctClass.getName());
}
}
use of org.hotswap.agent.javassist.CtMethod 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.CtMethod in project HotswapAgent by HotswapProjects.
the class PartialBeanTransformer method patchPartialBeanBindingExtension.
/**
* Patch partial bean binding extension.
*
* @param ctClass
* @throws NotFoundException the not found exception
* @throws CannotCompileException the cannot compile exception
*/
@OnClassLoadEvent(classNameRegexp = "org.apache.deltaspike.partialbean.impl.PartialBeanBindingExtension")
public static void patchPartialBeanBindingExtension(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod init = ctClass.getDeclaredMethod("init");
init.insertAfter(PluginManagerInvoker.buildInitializePlugin(DeltaSpikePlugin.class));
LOGGER.debug("org.apache.deltaspike.partialbean.impl.PartialBeanBindingExtension enhanced with plugin initialization.");
CtMethod createPartialBeanMethod = ctClass.getDeclaredMethod("createPartialBean");
createPartialBeanMethod.insertAfter("if (" + PluginManager.class.getName() + ".getInstance().isPluginInitialized(\"" + DeltaSpikePlugin.class.getName() + "\", beanClass.getClassLoader())) {" + PluginManagerInvoker.buildCallPluginMethod(DeltaSpikePlugin.class, "registerPartialBean", "$_", "java.lang.Object", "beanClass", "java.lang.Class") + "}" + "return $_;");
}
Aggregations