From 465001c9844d0792e426e4bf94a9bf758ae45018 Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Tue, 13 Nov 2012 10:54:59 +0200 Subject: [PATCH] added more methods in PluginManager --- demo/plugin1/pom.xml | 1 - .../fortsoft/pf4j/DefaultPluginManager.java | 14 +++++++++++++ .../main/java/ro/fortsoft/pf4j/Plugin.java | 2 +- .../ro/fortsoft/pf4j/PluginClassLoader.java | 2 +- .../ro/fortsoft/pf4j/PluginDescriptor.java | 2 +- .../java/ro/fortsoft/pf4j/PluginManager.java | 15 ++++++++++++++ .../java/ro/fortsoft/pf4j/PluginWrapper.java | 20 +++++++++++++++++++ 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/demo/plugin1/pom.xml b/demo/plugin1/pom.xml index 8d475d5..f6b639f 100644 --- a/demo/plugin1/pom.xml +++ b/demo/plugin1/pom.xml @@ -21,7 +21,6 @@ - welcome-plugin ro.fortsoft.pf4j.demo.welcome.WelcomePlugin diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index 2b36357..34b3987 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java @@ -76,6 +76,11 @@ public class DefaultPluginManager implements PluginManager { */ private List disabledPlugins; + /** + * A list with started plugins. + */ + private List startedPlugins; + private UberClassLoader uberClassLoader; /** @@ -93,15 +98,19 @@ public class DefaultPluginManager implements PluginManager { */ public DefaultPluginManager(File pluginsDirectory) { this.pluginsDirectory = pluginsDirectory; + plugins = new HashMap(); pluginClassLoaders = new HashMap(); pathToIdMap = new HashMap(); unresolvedPlugins = new ArrayList(); resolvedPlugins = new ArrayList(); disabledPlugins = new ArrayList(); + startedPlugins = new ArrayList(); pluginDescriptorFinder = new DefaultPluginDescriptorFinder(); uberClassLoader = new UberClassLoader(); extensionFinder = new DefaultExtensionFinder(uberClassLoader); + + System.setProperty("pf4j.pluginsDir", pluginsDirectory.getAbsolutePath()); } /** @@ -127,6 +136,10 @@ public class DefaultPluginManager implements PluginManager { return disabledPlugins; } + public List getStartedPlugins() { + return startedPlugins; + } + /** * Start all active plugins. */ @@ -136,6 +149,7 @@ public class DefaultPluginManager implements PluginManager { try { LOG.info("Start plugin '" + pluginWrapper.getDescriptor().getPluginId() + "'"); pluginWrapper.getPlugin().start(); + startedPlugins.add(pluginWrapper); } catch (PluginException e) { LOG.error(e.getMessage(), e); } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java b/pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java index 22498d7..80221ac 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java @@ -31,7 +31,7 @@ public abstract class Plugin { /** * Wrapper of the plugin. */ - PluginWrapper wrapper; + protected PluginWrapper wrapper; /** * Constructor to be used by plugin manager for plugin instantiation. diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java index 2f7ce1e..80832bc 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java @@ -21,7 +21,7 @@ import java.util.List; * * @author Decebal Suiu */ -class PluginClassLoader extends URLClassLoader { +public class PluginClassLoader extends URLClassLoader { private static final String JAVA_PACKAGE_PREFIX = "java."; private static final String JAVAX_PACKAGE_PREFIX = "javax."; diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java index aa2c495..a666b7a 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java @@ -27,7 +27,7 @@ import org.apache.commons.lang.builder.ToStringStyle; * * @author Decebal Suiu */ -class PluginDescriptor { +public class PluginDescriptor { private String pluginId; private String pluginClass; diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java index c8e4fe9..5e89b6b 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java @@ -27,6 +27,21 @@ public interface PluginManager { */ public List getPlugins(); + /** + * Retrieves all resolved plugins (with resolved dependency). + */ + public List getResolvedPlugins(); + + /** + * Retrieves all unresolved plugins (with unresolved dependency). + */ + public List getUnresolvedPlugins(); + + /** + * Retrieves all started plugins. + */ + public List getStartedPlugins(); + /** * Load plugins. */ diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java index a1a6368..b3a5a01 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java @@ -15,6 +15,8 @@ package ro.fortsoft.pf4j; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; @@ -91,6 +93,24 @@ public class PluginWrapper { } @Override + public int hashCode() { + return new HashCodeBuilder().append(descriptor.getPluginId()) + .toHashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof PluginWrapper)) { + return false; + } + + PluginWrapper wrapper = (PluginWrapper) obj; + + return new EqualsBuilder().append(descriptor.getPluginId(), wrapper.getDescriptor().getPluginId()) + .isEquals(); + } + + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) .append("descriptor", descriptor)