Search in sources :

Example 6 with PluginWrapper

use of org.pf4j.PluginWrapper in project spring-boot-starter-samples by vindell.

the class Pf4jApplication method run.

@Override
public void run(ApplicationArguments args) throws Exception {
    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 : PluginWrapper(org.pf4j.PluginWrapper)

Example 7 with PluginWrapper

use of org.pf4j.PluginWrapper 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();
    // PluginManager pluginManager = new Pf4jPluginManager();
    // PluginManager pluginManager = new SpringPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginManager();
    // PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();
    /**
     * 加载插件到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(org.pf4j.PluginManager) DefaultPluginManager(org.pf4j.DefaultPluginManager) Pf4jJarPluginManager(org.pf4j.spring.boot.ext.Pf4jJarPluginManager) ExtensionMapping(pf4j2.plugin.api.annotation.ExtensionMapping) AuthcExtensionPoint(pf4j2.plugin.api.AuthcExtensionPoint) PluginWrapper(org.pf4j.PluginWrapper) DefaultPluginManager(org.pf4j.DefaultPluginManager)

Example 8 with PluginWrapper

use of org.pf4j.PluginWrapper in project pf4j-spring by pf4j.

the class ExtensionsInjector method injectExtensions.

public void injectExtensions() {
    // add extensions from classpath (non plugin)
    Set<String> extensionClassNames = springPluginManager.getExtensionClassNames(null);
    for (String extensionClassName : extensionClassNames) {
        try {
            log.debug("Register extension '{}' as bean", extensionClassName);
            Class<?> extensionClass = getClass().getClassLoader().loadClass(extensionClassName);
            registerExtension(extensionClass);
        } catch (ClassNotFoundException e) {
            log.error(e.getMessage(), e);
        }
    }
    // add extensions for each started plugin
    List<PluginWrapper> startedPlugins = springPluginManager.getStartedPlugins();
    for (PluginWrapper plugin : startedPlugins) {
        log.debug("Registering extensions of the plugin '{}' as beans", plugin.getPluginId());
        extensionClassNames = springPluginManager.getExtensionClassNames(plugin.getPluginId());
        for (String extensionClassName : extensionClassNames) {
            try {
                log.debug("Register extension '{}' as bean", extensionClassName);
                Class<?> extensionClass = plugin.getPluginClassLoader().loadClass(extensionClassName);
                registerExtension(extensionClass);
            } catch (ClassNotFoundException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : PluginWrapper(org.pf4j.PluginWrapper)

Aggregations

PluginWrapper (org.pf4j.PluginWrapper)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 CompoundClassResolver (org.apache.wicket.application.CompoundClassResolver)1 DefaultClassResolver (org.apache.wicket.application.DefaultClassResolver)1 DefaultPluginManager (org.pf4j.DefaultPluginManager)1 Plugin (org.pf4j.Plugin)1 PluginManager (org.pf4j.PluginManager)1 Pf4jJarPluginManager (org.pf4j.spring.boot.ext.Pf4jJarPluginManager)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AuthcExtensionPoint (pf4j2.plugin.api.AuthcExtensionPoint)1 ExtensionMapping (pf4j2.plugin.api.annotation.ExtensionMapping)1