use of org.hotswap.agent.annotation.Init in project HotswapAgent by HotswapProjects.
the class InitHandlerTest method testInitMethod.
@Test
public void testInitMethod() throws Exception {
PluginManager pluginManager = PluginManager.getInstance();
SimplePlugin simplePlugin = new SimplePlugin();
// register the plugin
pluginManager.getPluginRegistry().getRegisteredPlugins().put(SimplePlugin.class, Collections.<ClassLoader, Object>singletonMap(getClass().getClassLoader(), simplePlugin));
InitHandler initHandler = new InitHandler(pluginManager);
Method method = SimplePlugin.class.getMethod("initPlugin", PluginManager.class);
PluginAnnotation<Init> pluginAnnotation = new PluginAnnotation<Init>(SimplePlugin.class, simplePlugin, method.getAnnotation(Init.class), method);
assertTrue("Init successful", initHandler.initMethod(pluginAnnotation));
}
use of org.hotswap.agent.annotation.Init in project HotswapAgent by HotswapProjects.
the class HotswapWebObjectsPlugin method init.
// We use reflection to get the methods from WebObjects because the jar is not distribuable publicly
// and we want to build witout it.
@Init
@SuppressWarnings({ "rawtypes", "unchecked" })
public void init(PluginConfiguration pluginConfiguration, ClassLoader appClassLoader) {
try {
Class kvcDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$DefaultImplementation", false, appClassLoader);
kvcDefaultImplementation_flushCaches = kvcDefaultImplementationClass.getMethod("_flushCaches");
Class kvcReflectionKeyBindingCreationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$_ReflectionKeyBindingCreation", false, appClassLoader);
kvcReflectionKeyBindingCreation_flushCaches = kvcReflectionKeyBindingCreationClass.getMethod("_flushCaches");
Class kvcValueAccessorClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$ValueAccessor", false, appClassLoader);
kvcValueAccessor_flushCaches = kvcValueAccessorClass.getMethod("_flushCaches");
Class nsValidationDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSValidation$DefaultImplementation", false, appClassLoader);
nsValidationDefaultImplementation_flushCaches = nsValidationDefaultImplementationClass.getMethod("_flushCaches");
Class woApplicationClass = Class.forName("com.webobjects.appserver.WOApplication", false, appClassLoader);
woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
woApplicationObject = woApplicationClass.getMethod("application").invoke(null);
ClassPool classPool = ClassPool.getDefault();
woComponentCtClass = classPool.makeClass("com.webobjects.appserver.WOComponent");
nsValidationCtClass = classPool.makeClass("com.webobjects.foundation.NSValidation");
woActionCtClass = classPool.makeClass("com.webobjects.appserver.WOAction");
Class woActionClass = Class.forName("com.webobjects.appserver.WOAction", false, appClassLoader);
Field actionClassesField = woActionClass.getDeclaredField("_actionClasses");
actionClassesField.setAccessible(true);
actionClassesCacheDictionnary = actionClassesField.get(null);
Class nsThreadsafeMutableDictionaryClass = Class.forName("com.webobjects.foundation._NSThreadsafeMutableDictionary", false, appClassLoader);
woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
nsThreadsafeMutableDictionary_removeAllObjects = nsThreadsafeMutableDictionaryClass.getMethod("removeAllObjects");
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations