From 44acc380810180593c8c6e85f80f5274d71540a2 Mon Sep 17 00:00:00 2001 From: Tyler Hawkes Date: Sun, 14 Jan 2018 02:51:34 -0700 Subject: [PATCH] Can now just get Extension classes (#191) --- .../app/src/main/java/org/pf4j/demo/Boot.java | 6 +++++ .../java/org/pf4j/AbstractPluginManager.java | 26 ++++++++++++++++++- .../src/main/java/org/pf4j/PluginManager.java | 4 +++ 3 files changed, 35 insertions(+), 1 deletion(-) 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); -- 2.39.5