]> source.dussan.org Git - pf4j.git/commitdiff
Can now just get Extension classes (#191)
authorTyler Hawkes <tylerhawkes@users.noreply.github.com>
Sun, 14 Jan 2018 09:51:34 +0000 (02:51 -0700)
committerDecebal Suiu <decebal.suiu@gmail.com>
Sun, 14 Jan 2018 09:51:34 +0000 (11:51 +0200)
demo/app/src/main/java/org/pf4j/demo/Boot.java
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/main/java/org/pf4j/PluginManager.java

index ba5396e651e44e79c4c9c6d4e192c801b7c32934..a4e32dd8920cf4ecb03c4f16b94c8b475d98a7a8 100644 (file)
@@ -61,6 +61,12 @@ public class Boot {
             System.out.println("   " + extension);
         }
 
+        System.out.println("Extension classes by classpath:");
+        List<Class<Greeting>> greetingsClasses = pluginManager.getExtensionClasses(Greeting.class);
+        for (Class<Greeting> greeting : greetingsClasses) {
+            System.out.println("   Class: " + greeting.getCanonicalName());
+        }
+
         // print extensions ids for each started plugin
         List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
         for (PluginWrapper plugin : startedPlugins) {
index 21df9c00be47500b86d9425c246183e77cf34b3f..711d764ac3d24fa4b9ddb36a010865fa925d106e 100644 (file)
@@ -45,7 +45,7 @@ public abstract class AbstractPluginManager implements PluginManager {
 
     private Path pluginsRoot;
 
-    private ExtensionFinder extensionFinder;
+    protected ExtensionFinder extensionFinder;
 
     private PluginDescriptorFinder pluginDescriptorFinder;
 
@@ -525,6 +525,30 @@ public abstract class AbstractPluginManager implements PluginManager {
         return pluginClassLoaders.get(pluginId);
     }
 
+    @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) {
+            @SuppressWarnings("unchecked")
+            Class<T> c = (Class<T>)extensionWrapper.getDescriptor().extensionClass;
+            extensionClasses.add(c);
+        }
+        return extensionClasses;
+    }
+
+    @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) {
+            @SuppressWarnings("unchecked")
+            Class<T> c = (Class<T>)extensionWrapper.getDescriptor().extensionClass;
+            extensionClasses.add(c);
+        }
+        return extensionClasses;
+    }
+
     @Override
     public <T> List<T> getExtensions(Class<T> type) {
         List<ExtensionWrapper<T>> extensionsWrapper = extensionFinder.find(type);
index 06fc68efa1d62262c2b11bbfdd05e1fd094ee1dd..25238702ec822d31762efc04b068d091de6b4f8b 100644 (file)
@@ -131,6 +131,10 @@ public interface PluginManager {
 
        ClassLoader getPluginClassLoader(String pluginId);
 
+    <T> List<Class<T>> getExtensionClasses(Class<T> type);
+
+    <T> List<Class<T>> getExtensionClasses(Class<T> type, String pluginId);
+
        <T> List<T> getExtensions(Class<T> type);
 
     <T> List<T> getExtensions(Class<T> type, String pluginId);