From: Decebal Suiu Date: Thu, 2 May 2019 11:11:30 +0000 (+0300) Subject: Resolve #296 X-Git-Tag: release-3.0.0~2^2~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1d36fcff75cfe38639fc1a8a28eefc79e8e7286f;p=pf4j.git Resolve #296 --- 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);