Search in sources :

Example 6 with CtConstructor

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

the class MyFacesPlugin method facesApplicationAssociateInitialized.

@OnClassLoadEvent(classNameRegexp = "org.apache.myfaces.config.RuntimeConfig")
public static void facesApplicationAssociateInitialized(CtClass ctClass) throws NotFoundException, CannotCompileException {
    String buildInitializePlugin = PluginManagerInvoker.buildInitializePlugin(MyFacesPlugin.class);
    for (CtConstructor constructor : ctClass.getDeclaredConstructors()) {
        constructor.insertAfter(buildInitializePlugin);
    }
    LOGGER.debug("org.apache.myfaces.config.RuntimeConfig with plugin initialization.");
}
Also used : CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 7 with CtConstructor

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

the class OsgiEquinoxPlugin method patchEquinox.

@OnClassLoadEvent(classNameRegexp = "org.eclipse.osgi.launch.Equinox")
public static void patchEquinox(CtClass ctClass) throws CannotCompileException {
    String initializePlugin = PluginManagerInvoker.buildInitializePlugin(OsgiEquinoxPlugin.class);
    String initializeThis = PluginManagerInvoker.buildCallPluginMethod(OsgiEquinoxPlugin.class, "initOsgiEquinox");
    for (CtConstructor constructor : ctClass.getDeclaredConstructors()) {
        constructor.insertAfter(initializePlugin);
        constructor.insertAfter(initializeThis);
    }
}
Also used : CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 8 with CtConstructor

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

the class GlassFishPlugin method transformFelix.

@OnClassLoadEvent(classNameRegexp = "org.apache.felix.framework.Felix")
public static void transformFelix(ClassPool classPool, CtClass ctClass) throws NotFoundException, CannotCompileException {
    CtClass[] constructorParams = new CtClass[] { classPool.get("java.util.Map") };
    CtConstructor declaredConstructor = ctClass.getDeclaredConstructor(constructorParams);
    declaredConstructor.insertBefore("{" + "if ($1 == null) { " + "$1 = new java.util.HashMap();" + "}" + "String __bootDeleg = (String) $1.get(\"" + FRAMEWORK_BOOTDELEGATION + "\");" + "if (__bootDeleg == null) {" + "__bootDeleg = \"\";" + "}" + "if (__bootDeleg.indexOf(\"org.hotswap.agent\") == -1) {" + "__bootDeleg = __bootDeleg.trim();" + "if (!__bootDeleg.isEmpty()) {" + "__bootDeleg = __bootDeleg + \", \";" + "}" + "__bootDeleg = __bootDeleg + \"" + BOOTDELEGATION_PACKAGES + "\";" + "$1.put(\"" + FRAMEWORK_BOOTDELEGATION + "\", __bootDeleg);" + "}" + "}");
    // declaredConstructor.insertAfter(PluginManagerInvoker.buildInitializePlugin(GlassFishPlugin.class));
    LOGGER.debug("Class 'org.apache.felix.framework.Felix' patched in classLoader {}.");
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 9 with CtConstructor

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

the class Hibernate3JPATransformers method annotationMetaDataProviderRegisterVariable.

/**
 * Annotation meta data provider register variable.
 *
 * @param ctClass the ct class
 * @throws CannotCompileException the cannot compile exception
 */
@OnClassLoadEvent(classNameRegexp = "org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider")
public static void annotationMetaDataProviderRegisterVariable(CtClass ctClass) throws CannotCompileException {
    StringBuilder src = new StringBuilder("{");
    src.append(PluginManagerInvoker.buildInitializePlugin(Hibernate3JPAPlugin.class));
    src.append(PluginManagerInvoker.buildCallPluginMethod(Hibernate3JPAPlugin.class, "registerAnnotationMetaDataProvider", "this", "java.lang.Object"));
    src.append("}");
    for (CtConstructor constructor : ctClass.getDeclaredConstructors()) {
        constructor.insertAfter(src.toString());
    }
    ctClass.addMethod(CtNewMethod.make("public void __resetCache() {" + "   this.configuredBeans.clear(); " + "}", ctClass));
    LOGGER.debug("org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider - added method __resetCache().");
}
Also used : CtConstructor(org.hotswap.agent.javassist.CtConstructor) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 10 with CtConstructor

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

the class Javac method compileMethod.

private CtBehavior compileMethod(Parser p, MethodDecl md) throws CompileError {
    int mod = MemberResolver.getModifiers(md.getModifiers());
    CtClass[] plist = gen.makeParamList(md);
    CtClass[] tlist = gen.makeThrowsList(md);
    recordParams(plist, Modifier.isStatic(mod));
    md = p.parseMethod2(stable, md);
    try {
        if (md.isConstructor()) {
            CtConstructor cons = new CtConstructor(plist, gen.getThisClass());
            cons.setModifiers(mod);
            md.accept(gen);
            cons.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
            cons.setExceptionTypes(tlist);
            return cons;
        } else {
            Declarator r = md.getReturn();
            CtClass rtype = gen.resolver.lookupClass(r);
            recordReturnType(rtype, false);
            CtMethod method = new CtMethod(rtype, r.getVariable().get(), plist, gen.getThisClass());
            method.setModifiers(mod);
            gen.setThisMethod(method);
            md.accept(gen);
            if (md.getBody() != null)
                method.getMethodInfo().setCodeAttribute(bytecode.toCodeAttribute());
            else
                method.setModifiers(mod | Modifier.ABSTRACT);
            method.setExceptionTypes(tlist);
            return method;
        }
    } catch (NotFoundException e) {
        throw new CompileError(e.toString());
    }
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) NotFoundException(org.hotswap.agent.javassist.NotFoundException) CtMethod(org.hotswap.agent.javassist.CtMethod) CtConstructor(org.hotswap.agent.javassist.CtConstructor)

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