Browse Source

Can now just get Extension classes (#191)

pull/194/head
Tyler Hawkes 7 years ago committed by Decebal Suiu
parent
commit
44acc38081
  1. 6
      demo/app/src/main/java/org/pf4j/demo/Boot.java
  2. 26
      pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
  3. 4
      pf4j/src/main/java/org/pf4j/PluginManager.java

6
demo/app/src/main/java/org/pf4j/demo/Boot.java

@ -61,6 +61,12 @@ public class Boot {
System.out.println(" " + extension); System.out.println(" " + extension);
} }
System.out.println("Extension classes by classpath:");
List<Class<Greeting>> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class);
for (Class<Greeting> greeting : greetingsClasses) {
System.out.println(" Class: " + greeting.getCanonicalName());
}
// print extensions ids for each started plugin // print extensions ids for each started plugin
List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins(); List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
for (PluginWrapper plugin : startedPlugins) { for (PluginWrapper plugin : startedPlugins) {

26
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java

@ -45,7 +45,7 @@ public abstract class AbstractPluginManager implements PluginManager {
private Path pluginsRoot; private Path pluginsRoot;
private ExtensionFinder extensionFinder; protected ExtensionFinder extensionFinder;
private PluginDescriptorFinder pluginDescriptorFinder; private PluginDescriptorFinder pluginDescriptorFinder;
@ -525,6 +525,30 @@ public abstract class AbstractPluginManager implements PluginManager {
return pluginClassLoaders.get(pluginId); return pluginClassLoaders.get(pluginId);
} }
@Override
public <T> List<Class<T>> getExtensionClasses(Class<T> type) {
List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type);
List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size());
for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) {
@SuppressWarnings("unchecked")
Class<T> c = (Class<T>)extensionWrapper.getDescriptor().extensionClass;
extensionClasses.add(c);
}
return extensionClasses;
}
@Override
public <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId) {
List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type, pluginId);
List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size());
for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) {
@SuppressWarnings("unchecked")
Class<T> c = (Class<T>)extensionWrapper.getDescriptor().extensionClass;
extensionClasses.add(c);
}
return extensionClasses;
}
@Override @Override
public <T> List<T> getExtensions(Class<T> type) { public <T> List<T> getExtensions(Class<T> type) {
List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type); List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type);

4
pf4j/src/main/java/org/pf4j/PluginManager.java

@ -131,6 +131,10 @@ public interface PluginManager {
ClassLoader getPluginClassLoader(String pluginId); ClassLoader getPluginClassLoader(String pluginId);
<T> List<Class<T>> getExtensionClasses(Class<T> type);
<T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId);
<T> List<T> getExtensions(Class<T> type); <T> List<T> getExtensions(Class<T> type);
<T> List<T> getExtensions(Class<T> type, String pluginId); <T> List<T> getExtensions(Class<T> type, String pluginId);

Loading…
Cancel
Save