Search in sources :

Example 1 with PluginState

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

Example 2 with PluginState

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

Aggregations

GitblitPlugin (com.gitblit.extensions.GitblitPlugin)2 File (java.io.File)2 PluginState (ro.fortsoft.pf4j.PluginState)2 PluginWrapper (ro.fortsoft.pf4j.PluginWrapper)2 Version (ro.fortsoft.pf4j.Version)1