From: Tyler Hawkes Date: Sun, 14 Jan 2018 09:51:34 +0000 (-0700) Subject: Can now just get Extension classes (#191) X-Git-Tag: release-2.2.0~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=44acc380810180593c8c6e85f80f5274d71540a2;p=pf4j.git Can now just get Extension classes (#191) --- diff --git a/demo/app/src/main/java/org/pf4j/demo/Boot.java b/demo/app/src/main/java/org/pf4j/demo/Boot.java index ba5396e..a4e32dd 100644 --- a/demo/app/src/main/java/org/pf4j/demo/Boot.java +++ b/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 classes by classpath:"); + List> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class); + for (Class greeting : greetingsClasses) { + System.out.println(" Class: " + greeting.getCanonicalName()); + } + // print extensions ids for each started plugin List startedPlugins = pluginManager.getStartedPlugins(); for (PluginWrapper plugin : startedPlugins) { diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 21df9c0..711d764 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -45,7 +45,7 @@ public abstract class AbstractPluginManager implements PluginManager { private Path pluginsRoot; - private ExtensionFinder extensionFinder; + protected ExtensionFinder extensionFinder; private PluginDescriptorFinder pluginDescriptorFinder; @@ -525,6 +525,30 @@ public abstract class AbstractPluginManager implements PluginManager { return pluginClassLoaders.get(pluginId); } + @Override + public List> getExtensionClasses(Class type) { + List> extensionsWrapper = extensionFinder.find(type); + List> extensionClasses = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper extensionWrapper : extensionsWrapper) { + @SuppressWarnings("unchecked") + Class c = (Class)extensionWrapper.getDescriptor().extensionClass; + extensionClasses.add(c); + } + return extensionClasses; + } + + @Override + public List> getExtensionClasses(Class type, String pluginId) { + List> extensionsWrapper = extensionFinder.find(type, pluginId); + List> extensionClasses = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper extensionWrapper : extensionsWrapper) { + @SuppressWarnings("unchecked") + Class c = (Class)extensionWrapper.getDescriptor().extensionClass; + extensionClasses.add(c); + } + return extensionClasses; + } + @Override public List getExtensions(Class type) { List> extensionsWrapper = extensionFinder.find(type); diff --git a/pf4j/src/main/java/org/pf4j/PluginManager.java b/pf4j/src/main/java/org/pf4j/PluginManager.java index 06fc68e..2523870 100644 --- a/pf4j/src/main/java/org/pf4j/PluginManager.java +++ b/pf4j/src/main/java/org/pf4j/PluginManager.java @@ -131,6 +131,10 @@ public interface PluginManager { ClassLoader getPluginClassLoader(String pluginId); + List> getExtensionClasses(Class type); + + List> getExtensionClasses(Class type, String pluginId); + List getExtensions(Class type); List getExtensions(Class type, String pluginId);