From 29697efdfa5a2d5c3f48dd584f6d9a41ade925f0 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 28 Feb 2009 20:25:44 +0000 Subject: [PATCH] Plugin is now optional git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15898 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/ClassicPluginStrategy.java | 35 ++++++++++--------- core/src/main/java/hudson/Plugin.java | 8 +++++ core/src/main/java/hudson/PluginWrapper.java | 1 - 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/hudson/ClassicPluginStrategy.java b/core/src/main/java/hudson/ClassicPluginStrategy.java index 0017168700..4375798691 100644 --- a/core/src/main/java/hudson/ClassicPluginStrategy.java +++ b/core/src/main/java/hudson/ClassicPluginStrategy.java @@ -169,11 +169,6 @@ public class ClassicPluginStrategy implements PluginStrategy { } public void load(PluginWrapper wrapper) throws IOException { - String className = wrapper.getPluginClass(); - if(className ==null) { - throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+wrapper.getShortName()); - } - loadPluginDependencies(wrapper.getDependencies(), wrapper.getOptionalDependencies()); @@ -185,19 +180,25 @@ public class ClassicPluginStrategy implements PluginStrategy { ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(wrapper.classLoader); try { - 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"); + String className = wrapper.getPluginClass(); + if(className==null) { + // use the default dummy instance + wrapper.setPlugin(Plugin.NONE); + } 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 (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); } - wrapper.setPlugin((Plugin) o); - } 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 diff --git a/core/src/main/java/hudson/Plugin.java b/core/src/main/java/hudson/Plugin.java index fb0cbd48ce..c281fe9477 100644 --- a/core/src/main/java/hudson/Plugin.java +++ b/core/src/main/java/hudson/Plugin.java @@ -229,4 +229,12 @@ public abstract class Plugin implements Saveable { return new XmlFile(Hudson.XSTREAM, new File(Hudson.getInstance().getRootDir(),wrapper.getShortName()+".xml")); } + + /** + * Dummy instance of {@link Plugin} to be used when a plugin didn't + * supply one on its own. + * + * @since 1.288 + */ + public static final Plugin NONE = new Plugin() {}; } diff --git a/core/src/main/java/hudson/PluginWrapper.java b/core/src/main/java/hudson/PluginWrapper.java index 6e3274ccb2..6e45587c3f 100644 --- a/core/src/main/java/hudson/PluginWrapper.java +++ b/core/src/main/java/hudson/PluginWrapper.java @@ -31,7 +31,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; -import java.util.ArrayList; import java.util.List; import java.util.jar.Manifest; import java.util.logging.Logger; -- GitLab