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.");
}
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 {}.");
}
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().");
}
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;
}
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;
}
}
Aggregations