Search in sources :

Example 21 with CtConstructor

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

the class BeanDeploymentArchiveTransformer method transform.

/**
 * Basic WeldBeanDeploymentArchive transformation.
 *
 * @param clazz
 * @param classPool
 * @throws NotFoundException
 * @throws CannotCompileException
 */
@OnClassLoadEvent(classNameRegexp = "org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive")
public static void transform(CtClass clazz, ClassPool classPool) throws NotFoundException, CannotCompileException {
    CtClass[] constructorParams = new CtClass[] { classPool.get("java.lang.String"), classPool.get("java.util.Collection"), classPool.get("org.jboss.weld.bootstrap.spi.BeansXml"), classPool.get("java.util.Set") };
    StringBuilder src = new StringBuilder("{");
    src.append(PluginManagerInvoker.buildInitializePlugin(WeldPlugin.class));
    src.append(PluginManagerInvoker.buildCallPluginMethod(WeldPlugin.class, "init"));
    src.append("org.hotswap.agent.plugin.weld.command.BeanClassRefreshAgent.registerArchive(getClass().getClassLoader(), this, null);");
    src.append("}");
    CtConstructor declaredConstructor = clazz.getDeclaredConstructor(constructorParams);
    declaredConstructor.insertAfter(src.toString());
    LOGGER.debug("Class '{}' patched with BDA registration.", clazz.getName());
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) WeldPlugin(org.hotswap.agent.plugin.weld.WeldPlugin) CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Aggregations

CtConstructor (org.hotswap.agent.javassist.CtConstructor)21 OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)16 CtClass (org.hotswap.agent.javassist.CtClass)8 CtMethod (org.hotswap.agent.javassist.CtMethod)6 NotFoundException (org.hotswap.agent.javassist.NotFoundException)5 WeldPlugin (org.hotswap.agent.plugin.weld.WeldPlugin)4 CtField (org.hotswap.agent.javassist.CtField)3 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)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 ArrayList (java.util.ArrayList)1 Command (org.hotswap.agent.command.Command)1 PluginManager (org.hotswap.agent.config.PluginManager)1 CtBehavior (org.hotswap.agent.javassist.CtBehavior)1 MethodInfo (org.hotswap.agent.javassist.bytecode.MethodInfo)1 FieldAccess (org.hotswap.agent.javassist.expr.FieldAccess)1 MethodCall (org.hotswap.agent.javassist.expr.MethodCall)1 DeltaSpikePlugin (org.hotswap.agent.plugin.deltaspike.DeltaSpikePlugin)1