Browse Source

added more methods in PluginManager

pull/3/head
Decebal Suiu 12 years ago
parent
commit
465001c984
  1. 1
      demo/plugin1/pom.xml
  2. 14
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  3. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java
  4. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java
  5. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java
  6. 15
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java
  7. 20
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java

1
demo/plugin1/pom.xml

@ -21,7 +21,6 @@
</license> </license>
</licenses> </licenses>
<properties> <properties>
<plugin.id>welcome-plugin</plugin.id> <plugin.id>welcome-plugin</plugin.id>
<plugin.class>ro.fortsoft.pf4j.demo.welcome.WelcomePlugin</plugin.class> <plugin.class>ro.fortsoft.pf4j.demo.welcome.WelcomePlugin</plugin.class>

14
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -76,6 +76,11 @@ public class DefaultPluginManager implements PluginManager {
*/ */
private List<PluginWrapper> disabledPlugins; private List<PluginWrapper> disabledPlugins;
/**
* A list with started plugins.
*/
private List<PluginWrapper> startedPlugins;
private UberClassLoader uberClassLoader; private UberClassLoader uberClassLoader;
/** /**
@ -93,15 +98,19 @@ public class DefaultPluginManager implements PluginManager {
*/ */
public DefaultPluginManager(File pluginsDirectory) { public DefaultPluginManager(File pluginsDirectory) {
this.pluginsDirectory = pluginsDirectory; this.pluginsDirectory = pluginsDirectory;
plugins = new HashMap<String, PluginWrapper>(); plugins = new HashMap<String, PluginWrapper>();
pluginClassLoaders = new HashMap<String, PluginClassLoader>(); pluginClassLoaders = new HashMap<String, PluginClassLoader>();
pathToIdMap = new HashMap<String, String>(); pathToIdMap = new HashMap<String, String>();
unresolvedPlugins = new ArrayList<PluginWrapper>(); unresolvedPlugins = new ArrayList<PluginWrapper>();
resolvedPlugins = new ArrayList<PluginWrapper>(); resolvedPlugins = new ArrayList<PluginWrapper>();
disabledPlugins = new ArrayList<PluginWrapper>(); disabledPlugins = new ArrayList<PluginWrapper>();
startedPlugins = new ArrayList<PluginWrapper>();
pluginDescriptorFinder = new DefaultPluginDescriptorFinder(); pluginDescriptorFinder = new DefaultPluginDescriptorFinder();
uberClassLoader = new UberClassLoader(); uberClassLoader = new UberClassLoader();
extensionFinder = new DefaultExtensionFinder(uberClassLoader); extensionFinder = new DefaultExtensionFinder(uberClassLoader);
System.setProperty("pf4j.pluginsDir", pluginsDirectory.getAbsolutePath());
} }
/** /**
@ -127,6 +136,10 @@ public class DefaultPluginManager implements PluginManager {
return disabledPlugins; return disabledPlugins;
} }
public List<PluginWrapper> getStartedPlugins() {
return startedPlugins;
}
/** /**
* Start all active plugins. * Start all active plugins.
*/ */
@ -136,6 +149,7 @@ public class DefaultPluginManager implements PluginManager {
try { try {
LOG.info("Start plugin '" + pluginWrapper.getDescriptor().getPluginId() + "'"); LOG.info("Start plugin '" + pluginWrapper.getDescriptor().getPluginId() + "'");
pluginWrapper.getPlugin().start(); pluginWrapper.getPlugin().start();
startedPlugins.add(pluginWrapper);
} catch (PluginException e) { } catch (PluginException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
} }

2
pf4j/src/main/java/ro/fortsoft/pf4j/Plugin.java

@ -31,7 +31,7 @@ public abstract class Plugin {
/** /**
* Wrapper of the plugin. * Wrapper of the plugin.
*/ */
PluginWrapper wrapper; protected PluginWrapper wrapper;
/** /**
* Constructor to be used by plugin manager for plugin instantiation. * Constructor to be used by plugin manager for plugin instantiation.

2
pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

@ -21,7 +21,7 @@ import java.util.List;
* *
* @author Decebal Suiu * @author Decebal Suiu
*/ */
class PluginClassLoader extends URLClassLoader { public class PluginClassLoader extends URLClassLoader {
private static final String JAVA_PACKAGE_PREFIX = "java."; private static final String JAVA_PACKAGE_PREFIX = "java.";
private static final String JAVAX_PACKAGE_PREFIX = "javax."; private static final String JAVAX_PACKAGE_PREFIX = "javax.";

2
pf4j/src/main/java/ro/fortsoft/pf4j/PluginDescriptor.java

@ -27,7 +27,7 @@ import org.apache.commons.lang.builder.ToStringStyle;
* *
* @author Decebal Suiu * @author Decebal Suiu
*/ */
class PluginDescriptor { public class PluginDescriptor {
private String pluginId; private String pluginId;
private String pluginClass; private String pluginClass;

15
pf4j/src/main/java/ro/fortsoft/pf4j/PluginManager.java

@ -27,6 +27,21 @@ public interface PluginManager {
*/ */
public List<PluginWrapper> getPlugins(); public List<PluginWrapper> getPlugins();
/**
* Retrieves all resolved plugins (with resolved dependency).
*/
public List<PluginWrapper> getResolvedPlugins();
/**
* Retrieves all unresolved plugins (with unresolved dependency).
*/
public List<PluginWrapper> getUnresolvedPlugins();
/**
* Retrieves all started plugins.
*/
public List<PluginWrapper> getStartedPlugins();
/** /**
* Load plugins. * Load plugins.
*/ */

20
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.Constructor;
import java.lang.reflect.Modifier; 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.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle; import org.apache.commons.lang.builder.ToStringStyle;
@ -91,6 +93,24 @@ public class PluginWrapper {
} }
@Override @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() { public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("descriptor", descriptor) .append("descriptor", descriptor)

Loading…
Cancel
Save