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;
}
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);
}
Aggregations