summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2019-05-02 14:11:30 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2019-05-02 14:11:30 +0300
commit1d36fcff75cfe38639fc1a8a28eefc79e8e7286f (patch)
tree8eb09080a052f54537632dd25ecb2b3b5b985698
parenta6ce0a6ace6c03a7369236350b5f8e4a61e4c381 (diff)
downloadpf4j-1d36fcff75cfe38639fc1a8a28eefc79e8e7286f.tar.gz
pf4j-1d36fcff75cfe38639fc1a8a28eefc79e8e7286f.zip
Resolve #296
-rw-r--r--demo/app/src/main/java/org/pf4j/demo/Boot.java4
-rw-r--r--pf4j/src/main/java/org/pf4j/AbstractPluginManager.java73
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginManager.java4
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<Class<Greeting>> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class);
- for (Class<Greeting> greeting : greetingsClasses) {
+ List<Class<? extends Greeting>> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class);
+ for (Class<? extends Greeting> 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 <T> List<Class<T>> getExtensionClasses(Class<T> type) {
- List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type);
- List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size());
- for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) {
- Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass;
- extensionClasses.add(c);
- }
- return extensionClasses;
+ @Override
+ public <T> List<Class<? extends T>> getExtensionClasses(Class<T> type) {
+ return getExtensionClasses(extensionFinder.find(type));
}
- @SuppressWarnings("unchecked")
@Override
- public <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId) {
- List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type, pluginId);
- List<Class<T>> extensionClasses = new ArrayList<>(extensionsWrapper.size());
- for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) {
- Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass;
- extensionClasses.add(c);
- }
-
- return extensionClasses;
+ public <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId) {
+ return getExtensionClasses(extensionFinder.find(type, pluginId));
}
@Override
public <T> List<T> getExtensions(Class<T> type) {
- List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type);
- List<T> extensions = new ArrayList<>(extensionsWrapper.size());
- for (ExtensionWrapper<T> 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 <T> List<T> getExtensions(Class<T> type, String pluginId) {
- List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type, pluginId);
- List<T> extensions = new ArrayList<>(extensionsWrapper.size());
- for (ExtensionWrapper<T> 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 <T> List<Class<? extends T>> getExtensionClasses(List<ExtensionWrapper<T>> extensionsWrapper) {
+ List<Class<? extends T>> extensionClasses = new ArrayList<>(extensionsWrapper.size());
+ for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) {
+ Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass;
+ extensionClasses.add(c);
+ }
+
+ return extensionClasses;
+ }
+
+ private <T> List<T> getExtensions(List<ExtensionWrapper<T>> extensionsWrapper) {
+ List<T> extensions = new ArrayList<>(extensionsWrapper.size());
+ for (ExtensionWrapper<T> 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<Class<?>> getExtensionClasses(String pluginId);
- <T> List<Class<T>> getExtensionClasses(Class<T> type);
+ <T> List<Class<? extends T>> getExtensionClasses(Class<T> type);
- <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId);
+ <T> List<Class<? extends T>> getExtensionClasses(Class<T> type, String pluginId);
<T> List<T> getExtensions(Class<T> type);