Search in sources :

Example 26 with OnClassLoadEvent

use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.

the class ELResolverPlugin method patchJBossReflectionUtil.

@OnClassLoadEvent(classNameRegexp = "org.jboss.el.util.ReflectionUtil")
public static void patchJBossReflectionUtil(CtClass ctClass) throws NotFoundException, CannotCompileException {
    CtField ctField = new CtField(CtClass.booleanType, "$$ha$haInitialized", ctClass);
    ctField.setModifiers(org.hotswap.agent.javassist.Modifier.PRIVATE | org.hotswap.agent.javassist.Modifier.STATIC);
    ctClass.addField(ctField, CtField.Initializer.constant(false));
    String buildInitializePlugin = PluginManagerInvoker.buildInitializePlugin(ELResolverPlugin.class, "base.getClass().getClassLoader()");
    String registerJBossReflectionUtil = PluginManagerInvoker.buildCallPluginMethod("base.getClass().getClassLoader()", ELResolverPlugin.class, "registerJBossReflectionUtil");
    CtMethod mFindMethod = ctClass.getDeclaredMethod("findMethod");
    mFindMethod.insertAfter("if(!$$ha$haInitialized) {" + "$$ha$haInitialized=true;" + buildInitializePlugin + registerJBossReflectionUtil + "}");
    LOGGER.debug("org.jboss.el.util.ReflectionUtil enhanced with resource bundles registration.");
}
Also used : CtField(org.hotswap.agent.javassist.CtField) CtMethod(org.hotswap.agent.javassist.CtMethod) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 27 with OnClassLoadEvent

use of org.hotswap.agent.annotation.OnClassLoadEvent 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 28 with OnClassLoadEvent

use of org.hotswap.agent.annotation.OnClassLoadEvent 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 29 with OnClassLoadEvent

use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.

the class OnClassLoadedHandler method initMethod.

@Override
public boolean initMethod(final PluginAnnotation<OnClassLoadEvent> pluginAnnotation) {
    LOGGER.debug("Init for method " + pluginAnnotation.getMethod());
    if (hotswapTransformer == null) {
        LOGGER.error("Error in init for method " + pluginAnnotation.getMethod() + ". Hotswap transformer is missing.");
        return false;
    }
    final OnClassLoadEvent annot = pluginAnnotation.getAnnotation();
    if (annot == null) {
        LOGGER.error("Error in init for method " + pluginAnnotation.getMethod() + ". Annotation missing.");
        return false;
    }
    ClassLoader appClassLoader = null;
    if (pluginAnnotation.getPlugin() != null) {
        appClassLoader = pluginManager.getPluginRegistry().getAppClassLoader(pluginAnnotation.getPlugin());
    }
    hotswapTransformer.registerTransformer(appClassLoader, annot.classNameRegexp(), new PluginClassFileTransformer(pluginManager, pluginAnnotation));
    return true;
}
Also used : OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Example 30 with OnClassLoadEvent

use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.

the class JdkPlugin method flushObjectStreamCaches.

@OnClassLoadEvent(classNameRegexp = ".*", events = LoadEvent.REDEFINE, skipSynthetic = false)
public static void flushObjectStreamCaches(ClassLoader classLoader, CtClass ctClass) {
    try {
        LOGGER.debug("Flushing {} from ObjectStreamClass caches", ctClass.getName());
        Class<?> clazz = classLoader.loadClass(ctClass.getName());
        Class<?> objectStreamClassCache = classLoader.loadClass("java.io.ObjectStreamClass$Caches");
        Map localDescs = (Map) ReflectionHelper.get(null, objectStreamClassCache, "localDescs");
        if (localDescs != null) {
            localDescs.clear();
        }
        Map reflectors = (Map) ReflectionHelper.get(null, objectStreamClassCache, "reflectors");
        if (reflectors != null) {
            reflectors.clear();
        }
    } catch (Exception e) {
        LOGGER.error("classReload() exception {}.", e.getMessage());
    } finally {
        reloadFlag = false;
    }
}
Also used : Map(java.util.Map) OnClassLoadEvent(org.hotswap.agent.annotation.OnClassLoadEvent)

Aggregations

OnClassLoadEvent (org.hotswap.agent.annotation.OnClassLoadEvent)50 CtMethod (org.hotswap.agent.javassist.CtMethod)29 CtConstructor (org.hotswap.agent.javassist.CtConstructor)16 CtClass (org.hotswap.agent.javassist.CtClass)13 CtField (org.hotswap.agent.javassist.CtField)10 NotFoundException (org.hotswap.agent.javassist.NotFoundException)10 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)9 ExprEditor (org.hotswap.agent.javassist.expr.ExprEditor)5 IOException (java.io.IOException)4 WeldPlugin (org.hotswap.agent.plugin.weld.WeldPlugin)4 Method (java.lang.reflect.Method)3 MalformedURLException (java.net.MalformedURLException)3 URISyntaxException (java.net.URISyntaxException)3 MethodCall (org.hotswap.agent.javassist.expr.MethodCall)3 URL (java.net.URL)2 Set (java.util.Set)2 DeltaSpikePlugin (org.hotswap.agent.plugin.deltaspike.DeltaSpikePlugin)2 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1