use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class ProxyPlugin method transformCglibProxy.
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic = false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassPool cp, final CtClass cc) throws IllegalClassFormatException, IOException, RuntimeException {
// try {
// return JavassistProxyTransformer.transform(classBeingRedefined, classfileBuffer, cc, cp);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
// alternative method of redefining Java proxies, uses a new classlaoder instance
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic =
// false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassLoader loader) throws IllegalClassFormatException, IOException, RuntimeException {
// try {
// return NewClassLoaderJavaProxyTransformer.transform(classBeingRedefined, classfileBuffer, loader);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
//
// // alternative method of redefining Java proxies, uses a 2 step process. Crashed with jvm8
// @OnClassLoadEvent(classNameRegexp = "com/sun/proxy/\\$Proxy.*", events = LoadEvent.REDEFINE, skipSynthetic =
// false)
// public static byte[] transformJavaProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer,
// final ClassPool cp) {
// try {
// return JavaProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer);
// } catch (Exception e) {
// LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
// }
// return classfileBuffer;
// }
@OnClassLoadEvent(classNameRegexp = ".*", events = LoadEvent.REDEFINE, skipSynthetic = false)
public static byte[] transformCglibProxy(final Class<?> classBeingRedefined, final byte[] classfileBuffer, final ClassLoader loader, final ClassPool cp) throws Exception {
GeneratorParams generatorParams = GeneratorParametersTransformer.getGeneratorParams(loader, classBeingRedefined.getName());
if (!ClassLoaderHelper.isClassLoderStarted(loader)) {
return classfileBuffer;
}
if (generatorParams == null) {
return classfileBuffer;
}
// flush standard java beans caches
loader.loadClass("java.beans.Introspector").getMethod("flushCaches").invoke(null);
if (generatorParams.getParam().getClass().getName().endsWith(".Enhancer")) {
try {
return CglibEnhancerProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer, loader, generatorParams);
} catch (Exception e) {
LOGGER.error("Error redifining Cglib Enhancer proxy {}", e, classBeingRedefined.getName());
}
}
// Multistep transformation crashed jvm in java8 u05
if (!isJava8OrNewer)
try {
return CglibProxyTransformer.transform(classBeingRedefined, cp, classfileBuffer, generatorParams);
} catch (Exception e) {
LOGGER.error("Error redifining Cglib proxy {}", e, classBeingRedefined.getName());
}
return classfileBuffer;
}
use of org.hotswap.agent.annotation.OnClassLoadEvent 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.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class WeldPlugin method classReload.
/**
* If bda archive is defined for given class than new BeanClassRefreshCommand is created
*
* @param classLoader
* @param ctClass
* @param original
*/
@OnClassLoadEvent(classNameRegexp = ".*", events = LoadEvent.REDEFINE)
public void classReload(ClassLoader classLoader, CtClass ctClass, Class<?> original) {
if (original != null && !isSyntheticCdiClass(ctClass.getName()) && !isInnerNonPublicStaticClass(ctClass)) {
try {
String archivePath = getArchivePath(classLoader, ctClass, original.getName());
LOGGER.debug("Class '{}' redefined for archive {} ", original.getName(), archivePath);
if (isBdaRegistered(classLoader, archivePath)) {
String oldSignatureForProxyCheck = WeldClassSignatureHelper.getSignatureForProxyClass(original);
String oldSignatureByStrategy = WeldClassSignatureHelper.getSignatureByStrategy(beanReloadStrategy, original);
scheduler.scheduleCommand(new BeanClassRefreshCommand(classLoader, archivePath, registeredProxiedBeans, original.getName(), oldSignatureForProxyCheck, oldSignatureByStrategy, beanReloadStrategy), WAIT_ON_REDEFINE);
}
} catch (Exception e) {
LOGGER.error("classReload() exception {}.", e, e.getMessage());
}
}
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class BeanDeploymentArchiveTransformer method transformGlassFishBda.
/**
* GlassFish BeanDeploymentArchiveImpl transformation.
*
* @param clazz
* @param classPool
* @throws NotFoundException
* @throws CannotCompileException
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.weld.BeanDeploymentArchiveImpl")
public static void transformGlassFishBda(CtClass clazz, ClassPool classPool) throws NotFoundException, CannotCompileException {
StringBuilder src = new StringBuilder("{");
src.append(PluginManagerInvoker.buildInitializePlugin(WeldPlugin.class, "this.moduleClassLoaderForBDA"));
src.append(PluginManagerInvoker.buildCallPluginMethod("this.moduleClassLoaderForBDA", WeldPlugin.class, "initInGlassFish"));
src.append(" Class agC = Class.forName(\"org.hotswap.agent.plugin.weld.command.BeanClassRefreshAgent\", true, this.moduleClassLoaderForBDA);");
src.append(" java.lang.reflect.Method agM = agC.getDeclaredMethod(\"registerArchive\", new Class[] {java.lang.ClassLoader.class, org.jboss.weld.bootstrap.spi.BeanDeploymentArchive.class, java.lang.String.class});");
src.append(" agM.invoke(null, new Object[] { this.moduleClassLoaderForBDA, this, null});");
src.append("}");
for (CtConstructor constructor : clazz.getDeclaredConstructors()) {
constructor.insertAfter(src.toString());
}
LOGGER.debug("Class 'org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl' patched with BDA registration.");
}
use of org.hotswap.agent.annotation.OnClassLoadEvent in project HotswapAgent by HotswapProjects.
the class BeanDeploymentArchiveTransformer method transformJbossBda.
/**
* JbossAS (Wildfly) BeanDeploymentArchiveImpl transformation.
*
* @param clazz
* @param classPool
* @throws NotFoundException
* @throws CannotCompileException
*/
@OnClassLoadEvent(classNameRegexp = "org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl")
public static void transformJbossBda(CtClass clazz, ClassPool classPool) throws NotFoundException, CannotCompileException {
StringBuilder src = new StringBuilder("{");
src.append("if (beansXml!=null && beanArchiveType!=null && (\"EXPLICIT\".equals(beanArchiveType.toString()) || \"IMPLICIT\".equals(beanArchiveType.toString()))){");
src.append(PluginManagerInvoker.buildInitializePlugin(WeldPlugin.class, "module.getClassLoader()"));
src.append(PluginManagerInvoker.buildCallPluginMethod("module.getClassLoader()", WeldPlugin.class, "initInJBossAS"));
src.append(" Class agC = Class.forName(\"org.hotswap.agent.plugin.weld.command.BeanClassRefreshAgent\", true, module.getClassLoader());");
src.append(" java.lang.reflect.Method agM = agC.getDeclaredMethod(\"registerArchive\", new Class[] {java.lang.ClassLoader.class, org.jboss.weld.bootstrap.spi.BeanDeploymentArchive.class, java.lang.String.class});");
src.append(" agM.invoke(null, new Object[] { module.getClassLoader(),this, beanArchiveType.toString()});");
src.append("}}");
for (CtConstructor constructor : clazz.getDeclaredConstructors()) {
constructor.insertAfter(src.toString());
}
LOGGER.debug("Class 'org.jboss.as.weld.deployment.BeanDeploymentArchiveImpl' patched with BDA registration.");
}
Aggregations