use of com.gitblit.extensions.GitblitPlugin 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 com.gitblit.extensions.GitblitPlugin 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;
}
use of com.gitblit.extensions.GitblitPlugin 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