From 1d36fcff75cfe38639fc1a8a28eefc79e8e7286f Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Thu, 2 May 2019 14:11:30 +0300 Subject: Resolve #296 --- .../main/java/org/pf4j/AbstractPluginManager.java | 73 +++++++++------------- pf4j/src/main/java/org/pf4j/PluginManager.java | 4 +- 2 files changed, 33 insertions(+), 44 deletions(-) (limited to 'pf4j/src/main/java/org') 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); -- cgit v1.2.3