Search in sources :

Example 6 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class PluginManager method removePlugin.

protected boolean removePlugin(String pluginId, boolean isUninstall) {
    PluginWrapper pluginWrapper = getPlugin(pluginId);
    final String name = pluginWrapper.getPluginPath().substring(1);
    if (isUninstall) {
        // allow the plugin to prepare for uninstallation
        if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
            ((GitblitPlugin) pluginWrapper.getPlugin()).onUninstall();
        }
    }
    if (pf4j.deletePlugin(pluginId)) {
        // delete the checksums
        File pFolder = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
        File[] checksums = pFolder.listFiles(new FileFilter() {

            @Override
            public boolean accept(File file) {
                if (!file.isFile()) {
                    return false;
                }
                return file.getName().startsWith(name) && (file.getName().toLowerCase().endsWith(".sha1") || file.getName().toLowerCase().endsWith(".md5"));
            }
        });
        if (checksums != null) {
            for (File checksum : checksums) {
                checksum.delete();
            }
        }
        return true;
    }
    return false;
}
Also used : GitblitPlugin(com.gitblit.extensions.GitblitPlugin) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) FileFilter(java.io.FileFilter) File(java.io.File)

Example 7 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class PluginManager method installPlugin.

/**
	 * Installs the plugin from the url.
	 *
	 * @param url
	 * @param verifyChecksum
	 * @return true if successful
	 */
@Override
public synchronized boolean installPlugin(String url, boolean verifyChecksum) throws IOException {
    File file = download(url, verifyChecksum);
    if (file == null || !file.exists()) {
        logger.error("Failed to download plugin {}", url);
        return false;
    }
    String pluginId = pf4j.loadPlugin(file);
    if (StringUtils.isEmpty(pluginId)) {
        logger.error("Failed to load plugin {}", file);
        return false;
    }
    // allow the plugin to prepare for operation after installation
    PluginWrapper pluginWrapper = pf4j.getPlugin(pluginId);
    if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
        ((GitblitPlugin) pluginWrapper.getPlugin()).onInstall();
    }
    PluginState state = pf4j.startPlugin(pluginId);
    return PluginState.STARTED.equals(state);
}
Also used : PluginState(ro.fortsoft.pf4j.PluginState) GitblitPlugin(com.gitblit.extensions.GitblitPlugin) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) File(java.io.File)

Example 8 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.

the class PluginClassResolver method getResources.

@Override
public Iterator<URL> getResources(final String name) {
    Set<URL> urls = new TreeSet<URL>(new UrlExternalFormComparator());
    for (PluginWrapper plugin : pluginManager.getPlugins()) {
        if (PluginState.STARTED != plugin.getPluginState()) {
            // ignore this plugin
            continue;
        }
        Iterator<URL> it = getResources(name, plugin);
        while (it.hasNext()) {
            URL url = it.next();
            urls.add(url);
        }
    }
    Iterator<URL> it = coreResolver.getResources(name);
    while (it.hasNext()) {
        URL url = it.next();
        urls.add(url);
    }
    return urls.iterator();
}
Also used : TreeSet(java.util.TreeSet) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) URL(java.net.URL)

Example 9 with PluginWrapper

use of ro.fortsoft.pf4j.PluginWrapper 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

PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)9 GitblitPlugin (com.gitblit.extensions.GitblitPlugin)3 File (java.io.File)3 JarPluginManager (ro.fortsoft.pf4j.JarPluginManager)2 PluginManager (ro.fortsoft.pf4j.PluginManager)2 PluginState (ro.fortsoft.pf4j.PluginState)2 Version (ro.fortsoft.pf4j.Version)2 GitblitWicketPlugin (com.gitblit.extensions.GitblitWicketPlugin)1 HttpRequestFilter (com.gitblit.extensions.HttpRequestFilter)1 PluginRegistry (com.gitblit.models.PluginRegistry)1 PluginRegistration (com.gitblit.models.PluginRegistry.PluginRegistration)1 FileFilter (java.io.FileFilter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 FilterConfig (javax.servlet.FilterConfig)1 IClassResolver (org.apache.wicket.application.IClassResolver)1 AuthcExtensionPoint (pf4j.plugin.api.AuthcExtensionPoint)1 ExtensionMapping (pf4j.plugin.api.annotation.ExtensionMapping)1