Search in sources :

Example 1 with Init

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));
}
Also used : PluginManager(org.hotswap.agent.config.PluginManager) Init(org.hotswap.agent.annotation.Init) SimplePlugin(org.hotswap.agent.testData.SimplePlugin) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with Init

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();
    }
}
Also used : Field(java.lang.reflect.Field) ClassPool(org.hotswap.agent.javassist.ClassPool) CtClass(org.hotswap.agent.javassist.CtClass) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotFoundException(org.hotswap.agent.javassist.NotFoundException) Init(org.hotswap.agent.annotation.Init)

Aggregations

Init (org.hotswap.agent.annotation.Init)2 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 PluginManager (org.hotswap.agent.config.PluginManager)1 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)1 ClassPool (org.hotswap.agent.javassist.ClassPool)1 CtClass (org.hotswap.agent.javassist.CtClass)1 NotFoundException (org.hotswap.agent.javassist.NotFoundException)1 SimplePlugin (org.hotswap.agent.testData.SimplePlugin)1 Test (org.junit.Test)1