Search in sources :

Example 1 with PluginManager

use of ro.fortsoft.pf4j.PluginManager in project spring-boot-starter-samples by vindell.

the class AuthcPluginTest method main.

public static void main(String[] args) {
    System.setProperty("pf4j.mode", RuntimeMode.DEPLOYMENT.toString());
    System.setProperty("pf4j.pluginsDir", "plugins");
    if (RuntimeMode.DEPLOYMENT.compareTo(RuntimeMode.DEPLOYMENT) == 0) {
    // System.setProperty("pf4j.pluginsDir", System.getProperty("app.home","e:/root") + "/plugins");
    }
    /**
     * 创建PluginManager对象,此处根据生产环境选择合适的实现,或者自定义实现
     */
    // PluginManager pluginManager = new DefaultPluginManager(new File("E:/root/").toPath());
    PluginManager pluginManager = new JarPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();
    // PluginManager pluginManager = new Pf4jPluginManager();
    /**
     * 加载插件到JVM
     */
    pluginManager.loadPlugins();
    /**
     * 调用Plugin实现类的start()方法:
     */
    pluginManager.startPlugins();
    List<PluginWrapper> list = pluginManager.getPlugins();
    for (PluginWrapper pluginWrapper : list) {
        System.out.println(pluginWrapper.getPluginId());
    }
    List<AuthcExtensionPoint> extensions = pluginManager.getExtensions(AuthcExtensionPoint.class);
    for (AuthcExtensionPoint point : extensions) {
        ExtensionMapping m = point.getClass().getAnnotation(ExtensionMapping.class);
        System.out.println(m.title());
    }
    /**
     * 调用Plugin实现类的stop()方法
     */
    pluginManager.stopPlugins();
    System.out.println("=============");
}
Also used : PluginManager(ro.fortsoft.pf4j.PluginManager) JarPluginManager(ro.fortsoft.pf4j.JarPluginManager) ExtensionMapping(pf4j.plugin.api.annotation.ExtensionMapping) JarPluginManager(ro.fortsoft.pf4j.JarPluginManager) AuthcExtensionPoint(pf4j.plugin.api.AuthcExtensionPoint) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper)

Example 2 with PluginManager

use of ro.fortsoft.pf4j.PluginManager in project spring-boot-starter-samples by vindell.

the class Pf4jApplication method run.

@Override
public void run(ApplicationArguments args) throws Exception {
    System.setProperty("pf4j.mode", RuntimeMode.DEPLOYMENT.toString());
    // if(RuntimeMode.DEPLOYMENT.compareTo(RuntimeMode.DEPLOYMENT) == 0) {
    // System.setProperty("pf4j.pluginsDir", System.getProperty("app.home","e:/root") + "/plugins");
    // } else {
    // System.setProperty("pf4j.pluginsDir", "plugins");
    // }
    // PluginManager pluginManager = new DefaultPluginManager(new File("E:/root/").toPath());
    PluginManager pluginManager = new JarPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();
    // PluginManager pluginManager = new Pf4jPluginManager();
    pluginManager.loadPlugins();
    pluginManager.startPlugins();
    List<PluginWrapper> list = pluginManager.getPlugins();
    for (PluginWrapper pluginWrapper : list) {
        System.out.println(pluginWrapper.getPluginId());
        List<?> extensions = pluginManager.getExtensions(pluginWrapper.getPluginId());
        for (Object extension : extensions) {
            System.out.println(extension);
        }
    }
    pluginManager.stopPlugins();
    System.out.println("=============");
}
Also used : PluginManager(ro.fortsoft.pf4j.PluginManager) JarPluginManager(ro.fortsoft.pf4j.JarPluginManager) JarPluginManager(ro.fortsoft.pf4j.JarPluginManager) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper)

Aggregations

JarPluginManager (ro.fortsoft.pf4j.JarPluginManager)2 PluginManager (ro.fortsoft.pf4j.PluginManager)2 PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)2 AuthcExtensionPoint (pf4j.plugin.api.AuthcExtensionPoint)1 ExtensionMapping (pf4j.plugin.api.annotation.ExtensionMapping)1