Browse Source

Resolve #296

pull/320/head
Decebal Suiu 6 years ago
parent
commit
1d36fcff75
  1. 4
      demo/app/src/main/java/org/pf4j/demo/Boot.java
  2. 73
      pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
  3. 4
      pf4j/src/main/java/org/pf4j/PluginManager.java

4
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());
}

73
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;
}
}

4
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);

Loading…
Cancel
Save