use of com.google.gerrit.common.PluginData in project gerrit by GerritCodeReview.
the class Init method beforeInit.
@Override
protected boolean beforeInit(SiteInit init) throws Exception {
indexStatus = new GerritIndexStatus(init.site);
ErrorLogFile.errorOnlyConsole();
if (!skipPlugins) {
final List<PluginData> plugins = InitPlugins.listPluginsAndRemoveTempFiles(init.site, pluginsDistribution);
ConsoleUI ui = ConsoleUI.getInstance(false);
if (installAllPlugins && !nullOrEmpty(installPlugins)) {
ui.message("Cannot use --install-plugin together with --install-all-plugins.\n");
return true;
}
verifyInstallPluginList(ui, plugins);
if (listPlugins) {
if (!plugins.isEmpty()) {
ui.message("Available plugins:\n");
for (PluginData plugin : plugins) {
ui.message(" * %s version %s\n", plugin.name, plugin.version);
}
} else {
ui.message("No plugins found.\n");
}
return true;
}
}
return false;
}
use of com.google.gerrit.common.PluginData in project gerrit by GerritCodeReview.
the class InitPlugins method installPlugins.
private void installPlugins() throws IOException {
ui.message("Installing plugins.\n");
List<PluginData> plugins = listPlugins(site, pluginsDistribution);
for (PluginData plugin : plugins) {
String pluginName = plugin.name;
try {
final Path tmpPlugin = plugin.pluginPath;
Path p = site.plugins_dir.resolve(plugin.name + ".jar");
boolean upgrade = Files.exists(p);
if (!(initFlags.installPlugins.contains(pluginName) || initFlags.installAllPlugins || ui.yesno(upgrade, "Install plugin %s version %s", pluginName, plugin.version))) {
Files.deleteIfExists(tmpPlugin);
continue;
}
if (upgrade) {
final String installedPluginVersion = getVersion(p);
if (!ui.yesno(upgrade, "%s %s is already installed, overwrite it", plugin.name, installedPluginVersion)) {
Files.deleteIfExists(tmpPlugin);
continue;
}
try {
Files.delete(p);
} catch (IOException e) {
throw new IOException("Failed to delete plugin " + pluginName + ": " + p.toAbsolutePath(), e);
}
}
try {
Files.move(tmpPlugin, p);
if (upgrade) {
// or update that is not an upgrade
ui.message("Updated %s to %s\n", plugin.name, plugin.version);
} else {
ui.message("Installed %s %s\n", plugin.name, plugin.version);
}
} catch (IOException e) {
throw new IOException("Failed to install plugin " + pluginName + ": " + tmpPlugin.toAbsolutePath() + " -> " + p.toAbsolutePath(), e);
}
} finally {
Files.deleteIfExists(plugin.pluginPath);
}
}
if (plugins.isEmpty()) {
ui.message("No plugins found to install.\n");
}
}
use of com.google.gerrit.common.PluginData in project gerrit by GerritCodeReview.
the class InitPlugins method listPlugins.
private static List<PluginData> listPlugins(final SitePaths site, final boolean deleteTempPluginFile, PluginsDistribution pluginsDistribution) throws IOException {
final List<PluginData> result = new ArrayList<>();
pluginsDistribution.foreach((pluginName, in) -> {
Path tmpPlugin = JarPluginProvider.storeInTemp(pluginName, in, site);
String pluginVersion = getVersion(tmpPlugin);
if (deleteTempPluginFile) {
Files.delete(tmpPlugin);
}
result.add(new PluginData(pluginName, pluginVersion, tmpPlugin));
});
result.sort(comparing(p -> p.name));
return result;
}
Aggregations