From 1d36fcff75cfe38639fc1a8a28eefc79e8e7286f Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Thu, 2 May 2019 14:11:30 +0300 Subject: [PATCH] Resolve #296 --- .../app/src/main/java/org/pf4j/demo/Boot.java | 4 +- .../java/org/pf4j/AbstractPluginManager.java | 73 ++++++++----------- .../src/main/java/org/pf4j/PluginManager.java | 4 +- 3 files changed, 35 insertions(+), 46 deletions(-) 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 562f8f8..066a207 100644 --- a/demo/app/src/main/java/org/pf4j/demo/Boot.java +++ b/demo/app/src/main/java/org/pf4j/demo/Boot.java @@ -73,8 +73,8 @@ public class Boot { } System.out.println("Extension classes by classpath:"); - List> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class); - for (Class greeting : greetingsClasses) { + List> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class); + for (Class greeting : greetingsClasses) { System.out.println(" Class: " + greeting.getCanonicalName()); } diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index a7333ca..478149d 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -525,60 +525,25 @@ public abstract class AbstractPluginManager implements PluginManager { return extensionClasses; } - @SuppressWarnings("unchecked") - @Override - public List> getExtensionClasses(Class type) { - List> extensionsWrapper = extensionFinder.find(type); - List> extensionClasses = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper extensionWrapper : extensionsWrapper) { - Class c = (Class) extensionWrapper.getDescriptor().extensionClass; - extensionClasses.add(c); - } - return extensionClasses; + @Override + public List> getExtensionClasses(Class type) { + return getExtensionClasses(extensionFinder.find(type)); } - @SuppressWarnings("unchecked") @Override - public List> getExtensionClasses(Class type, String pluginId) { - List> extensionsWrapper = extensionFinder.find(type, pluginId); - List> extensionClasses = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper extensionWrapper : extensionsWrapper) { - Class c = (Class) extensionWrapper.getDescriptor().extensionClass; - extensionClasses.add(c); - } - - return extensionClasses; + public List> getExtensionClasses(Class type, String pluginId) { + return getExtensionClasses(extensionFinder.find(type, pluginId)); } @Override public List getExtensions(Class type) { - List> extensionsWrapper = extensionFinder.find(type); - List extensions = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper extensionWrapper : extensionsWrapper) { - try { - extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { - log.error("Cannot retrieve extension", e); - } - } - - return extensions; + return getExtensions(extensionFinder.find(type)); } @Override public List getExtensions(Class type, String pluginId) { - List> extensionsWrapper = extensionFinder.find(type, pluginId); - List extensions = new ArrayList<>(extensionsWrapper.size()); - for (ExtensionWrapper extensionWrapper : extensionsWrapper) { - try { - extensions.add(extensionWrapper.getExtension()); - } catch (PluginException e) { - log.error("Cannot retrieve extension", e); - } - } - - return extensions; + return getExtensions(extensionFinder.find(type, pluginId)); } @Override @@ -943,4 +908,28 @@ public abstract class AbstractPluginManager implements PluginManager { return pluginDescriptor.getPluginId() + "@" + pluginDescriptor.getVersion(); } + @SuppressWarnings("unchecked") + private List> getExtensionClasses(List> extensionsWrapper) { + List> extensionClasses = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper extensionWrapper : extensionsWrapper) { + Class c = (Class) extensionWrapper.getDescriptor().extensionClass; + extensionClasses.add(c); + } + + return extensionClasses; + } + + private List getExtensions(List> extensionsWrapper) { + List extensions = new ArrayList<>(extensionsWrapper.size()); + for (ExtensionWrapper extensionWrapper : extensionsWrapper) { + try { + extensions.add(extensionWrapper.getExtension()); + } catch (PluginException e) { + log.error("Cannot retrieve extension", e); + } + } + + return extensions; + } + } diff --git a/pf4j/src/main/java/org/pf4j/PluginManager.java b/pf4j/src/main/java/org/pf4j/PluginManager.java index a283738..badba28 100644 --- a/pf4j/src/main/java/org/pf4j/PluginManager.java +++ b/pf4j/src/main/java/org/pf4j/PluginManager.java @@ -135,9 +135,9 @@ public interface PluginManager { List> getExtensionClasses(String pluginId); - List> getExtensionClasses(Class type); + List> getExtensionClasses(Class type); - List> getExtensionClasses(Class type, String pluginId); + List> getExtensionClasses(Class type, String pluginId); List getExtensions(Class type); -- 2.39.5