Search in sources :

Example 1 with DummyImpl

use of hudson.Plugin.DummyImpl in project hudson-2.x by hudson.

the class ClassicPluginStrategy method load.

public void load(PluginWrapper wrapper) throws IOException {
    // override the context classloader so that XStream activity in plugin.start()
    // will be able to resolve classes in this plugin
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(wrapper.classLoader);
    try {
        String className = wrapper.getPluginClass();
        if (className == null) {
            // use the default dummy instance
            wrapper.setPlugin(new DummyImpl());
        } else {
            try {
                Class clazz = wrapper.classLoader.loadClass(className);
                Object o = clazz.newInstance();
                if (!(o instanceof Plugin)) {
                    throw new IOException(className + " doesn't extend from hudson.Plugin");
                }
                wrapper.setPlugin((Plugin) o);
            } catch (LinkageError e) {
                throw new IOException2("Unable to load " + className + " from " + wrapper.getShortName(), e);
            } catch (ClassNotFoundException e) {
                throw new IOException2("Unable to load " + className + " from " + wrapper.getShortName(), e);
            } catch (IllegalAccessException e) {
                throw new IOException2("Unable to create instance of " + className + " from " + wrapper.getShortName(), e);
            } catch (InstantiationException e) {
                throw new IOException2("Unable to create instance of " + className + " from " + wrapper.getShortName(), e);
            }
        }
        // initialize plugin
        try {
            Plugin plugin = wrapper.getPlugin();
            plugin.setServletContext(pluginManager.context);
            startPlugin(wrapper);
        } catch (Throwable t) {
            // gracefully handle any error in plugin.
            throw new IOException2("Failed to initialize", t);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
Also used : DummyImpl(hudson.Plugin.DummyImpl) IOException(java.io.IOException) MaskingClassLoader(hudson.util.MaskingClassLoader) AntClassLoader(org.apache.tools.ant.AntClassLoader) URLClassLoader(java.net.URLClassLoader) IOException2(hudson.util.IOException2)

Aggregations

DummyImpl (hudson.Plugin.DummyImpl)1 IOException2 (hudson.util.IOException2)1 MaskingClassLoader (hudson.util.MaskingClassLoader)1 IOException (java.io.IOException)1 URLClassLoader (java.net.URLClassLoader)1 AntClassLoader (org.apache.tools.ant.AntClassLoader)1