Search in sources :

Example 1 with Version

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

the class PluginManager method start.

@Override
public PluginManager start() {
    File dir = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
    dir.mkdirs();
    pf4j = new DefaultPluginManager(dir) {

        @Override
        protected PluginFactory createPluginFactory() {
            return new GuicePluginFactory();
        }

        @Override
        protected ExtensionFactory createExtensionFactory() {
            return new GuiceExtensionFactory();
        }
    };
    try {
        Version systemVersion = Version.createVersion(Constants.getVersion());
        pf4j.setSystemVersion(systemVersion);
    } catch (Exception e) {
        logger.error(null, e);
    }
    pf4j.loadPlugins();
    logger.debug("Starting plugins");
    pf4j.startPlugins();
    return this;
}
Also used : Version(ro.fortsoft.pf4j.Version) ExtensionFactory(ro.fortsoft.pf4j.ExtensionFactory) DefaultPluginFactory(ro.fortsoft.pf4j.DefaultPluginFactory) PluginFactory(ro.fortsoft.pf4j.PluginFactory) File(java.io.File) DefaultPluginManager(ro.fortsoft.pf4j.DefaultPluginManager) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with Version

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

the class PluginManager method getRegisteredPlugins.

@Override
public synchronized List<PluginRegistration> getRegisteredPlugins() {
    List<PluginRegistration> list = new ArrayList<PluginRegistration>();
    Map<String, PluginRegistration> map = new TreeMap<String, PluginRegistration>();
    for (PluginRegistry registry : getRegistries()) {
        list.addAll(registry.registrations);
        for (PluginRegistration reg : list) {
            reg.installedRelease = null;
            map.put(reg.id, reg);
        }
    }
    for (PluginWrapper pw : pf4j.getPlugins()) {
        String id = pw.getDescriptor().getPluginId();
        Version pv = pw.getDescriptor().getVersion();
        PluginRegistration reg = map.get(id);
        if (reg != null) {
            reg.installedRelease = pv.toString();
        }
    }
    return list;
}
Also used : Version(ro.fortsoft.pf4j.Version) PluginRegistry(com.gitblit.models.PluginRegistry) ArrayList(java.util.ArrayList) PluginRegistration(com.gitblit.models.PluginRegistry.PluginRegistration) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) TreeMap(java.util.TreeMap)

Example 3 with Version

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

the class PluginManager method upgradePlugin.

@Override
public synchronized boolean upgradePlugin(String pluginId, String url, boolean verifyChecksum) throws IOException {
    // ensure we can download the update BEFORE we remove the existing one
    File file = download(url, verifyChecksum);
    if (file == null || !file.exists()) {
        logger.error("Failed to download plugin {}", url);
        return false;
    }
    Version oldVersion = pf4j.getPlugin(pluginId).getDescriptor().getVersion();
    if (removePlugin(pluginId, false)) {
        String newPluginId = pf4j.loadPlugin(file);
        if (StringUtils.isEmpty(newPluginId)) {
            logger.error("Failed to load plugin {}", file);
            return false;
        }
        // the plugin to handle an upgrade
        PluginWrapper pluginWrapper = pf4j.getPlugin(newPluginId);
        if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
            ((GitblitPlugin) pluginWrapper.getPlugin()).onUpgrade(oldVersion);
        }
        PluginState state = pf4j.startPlugin(newPluginId);
        return PluginState.STARTED.equals(state);
    } else {
        logger.error("Failed to delete plugin {}", pluginId);
    }
    return false;
}
Also used : PluginState(ro.fortsoft.pf4j.PluginState) GitblitPlugin(com.gitblit.extensions.GitblitPlugin) Version(ro.fortsoft.pf4j.Version) PluginWrapper(ro.fortsoft.pf4j.PluginWrapper) File(java.io.File)

Aggregations

Version (ro.fortsoft.pf4j.Version)3 File (java.io.File)2 PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)2 GitblitPlugin (com.gitblit.extensions.GitblitPlugin)1 PluginRegistry (com.gitblit.models.PluginRegistry)1 PluginRegistration (com.gitblit.models.PluginRegistry.PluginRegistration)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 DefaultPluginFactory (ro.fortsoft.pf4j.DefaultPluginFactory)1 DefaultPluginManager (ro.fortsoft.pf4j.DefaultPluginManager)1 ExtensionFactory (ro.fortsoft.pf4j.ExtensionFactory)1 PluginFactory (ro.fortsoft.pf4j.PluginFactory)1 PluginState (ro.fortsoft.pf4j.PluginState)1