use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class ViewConfigTransformer method patchViewConfigExtension.
/**
* Register DeltaspikePlugin and add reinitialization method to RepositoryComponent
*
* @param ctClass
* @param classPool the class pool
* @throws CannotCompileException the cannot compile exception
* @throws NotFoundException the not found exception
*/
@OnClassLoadEvent(classNameRegexp = "org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension")
public static void patchViewConfigExtension(CtClass ctClass, ClassPool classPool) throws CannotCompileException, NotFoundException {
CtMethod init = ctClass.getDeclaredMethod("init");
init.insertAfter("{" + "if (this.isActivated) {" + PluginManagerInvoker.buildInitializePlugin(DeltaSpikePlugin.class) + "}" + "}");
LOGGER.debug("org.apache.deltaspike.jsf.impl.config.view.ViewConfigExtension enhanced with plugin initialization.");
CtClass viewConfigResProxyClass = classPool.get("org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverProxy");
CtField viewConfigResProxyField = new CtField(viewConfigResProxyClass, VIEW_CONFIG_RESOLVER_PROXY_FIELD, ctClass);
ctClass.addField(viewConfigResProxyField);
CtMethod generateProxyClassMethod = ctClass.getDeclaredMethod("transformMetaDataTree");
generateProxyClassMethod.instrument(new ExprEditor() {
public void edit(NewExpr e) throws CannotCompileException {
if (e.getClassName().equals("org.apache.deltaspike.jsf.impl.config.view.DefaultViewConfigResolver"))
e.replace("{ " + "java.lang.Object _resolver = new org.apache.deltaspike.jsf.impl.config.view.DefaultViewConfigResolver($$); " + "if (this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + "==null) {" + "this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + "=new org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverProxy();" + "}" + "this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + ".setViewConfigResolver(_resolver);" + "java.util.List _list = org.hotswap.agent.plugin.deltaspike.jsf.ViewConfigResolverUtils.findViewConfigRootClasses(this.rootViewConfigNode);" + PluginManagerInvoker.buildCallPluginMethod(DeltaSpikePlugin.class, "registerViewConfigRootClasses", "this", "java.lang.Object", "_list", "java.util.List") + " $_ = this." + VIEW_CONFIG_RESOLVER_PROXY_FIELD + ";" + "}");
}
});
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method jerseyServletCallInitialized.
/**
* Initialize the plugin when Jersey's ServletContainer.init(WebConfig config) is called. This is called from both init() for a servlet
* and init(Config) for a filter.
*
* Also, add the ServletContainer to a list of registeredJerseyContainers so that we can call reload on it later when classes change
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.servlet.ServletContainer")
public static void jerseyServletCallInitialized(CtClass ctClass, ClassPool classPool) throws NotFoundException, CannotCompileException {
CtMethod init = ctClass.getDeclaredMethod("init", new CtClass[] { classPool.get("org.glassfish.jersey.servlet.WebConfig") });
init.insertBefore(PluginManagerInvoker.buildInitializePlugin(Jersey2Plugin.class));
LOGGER.info("org.glassfish.jersey.servlet.ServletContainer enhanced with plugin initialization.");
String registerThis = PluginManagerInvoker.buildCallPluginMethod(Jersey2Plugin.class, "registerJerseyContainer", "this", "java.lang.Object", "getConfiguration()", "java.lang.Object");
init.insertAfter(registerThis);
// Workaround a Jersey issue where ServletContainer cannot be reloaded since it is in an immutable state
CtMethod reload = ctClass.getDeclaredMethod("reload", new CtClass[] { classPool.get("org.glassfish.jersey.server.ResourceConfig") });
reload.insertBefore("$1 = new org.glassfish.jersey.server.ResourceConfig($1);");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method fixAnnoationAcceptingListener.
/**
* Fix a scanning issue with jersey pre-2.4 versions. https://java.net/jira/browse/JERSEY-1936
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener")
public static void fixAnnoationAcceptingListener(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod process = ctClass.getDeclaredMethod("process");
process.insertAfter("try { $2.close(); } catch (Exception e) {}");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class Jersey2Plugin method fixSingleHk2LocatorManager.
/**
* Fix CDI CDI_MULTIPLE_LOCATORS_INTO_SIMPLE_APP exception on class redefinition
*/
@OnClassLoadEvent(classNameRegexp = "org.glassfish.jersey.ext.cdi1x.internal.SingleHk2LocatorManager")
public static void fixSingleHk2LocatorManager(CtClass ctClass) throws NotFoundException, CannotCompileException {
CtMethod process = ctClass.getDeclaredMethod("registerLocator");
process.insertBefore("if (this.locator != null) return;");
LOGGER.debug("SingleHk2LocatorManager : patched()");
}
use of org.hotswap.agent.javassist.CtMethod in project HotswapAgent by HotswapProjects.
the class JettyPlugin method patchWebXmlConfiguration6x.
// same as above for older jetty versions
@OnClassLoadEvent(classNameRegexp = "org.mortbay.jetty.webapp.WebXmlConfiguration")
public static void patchWebXmlConfiguration6x(CtClass ctClass) throws NotFoundException, CannotCompileException, ClassNotFoundException {
try {
// after application context initialized, but before processing started
CtMethod doStart = ctClass.getDeclaredMethod("configureWebApp");
// init the plugin
String src = PluginManagerInvoker.buildInitializePlugin(JettyPlugin.class, "getWebAppContext().getClassLoader()");
src += PluginManagerInvoker.buildCallPluginMethod("getWebAppContext().getClassLoader()", JettyPlugin.class, "init", "getWebAppContext()", "java.lang.Object");
doStart.insertBefore(src);
} catch (NotFoundException e) {
LOGGER.warning("org.mortbay.jetty.webapp.WebXmlConfiguration does not contain startContext method. Jetty plugin will be disabled.\n" + "*** This is Ok, Jetty plugin handles only special properties ***");
return;
}
}
Aggregations