Search in sources :

Example 1 with PluginData

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;
}
Also used : PluginData(com.google.gerrit.common.PluginData) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) GerritIndexStatus(com.google.gerrit.server.index.GerritIndexStatus)

Example 2 with PluginData

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");
    }
}
Also used : Path(java.nio.file.Path) PluginData(com.google.gerrit.common.PluginData) IOException(java.io.IOException)

Example 3 with PluginData

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;
}
Also used : Path(java.nio.file.Path) Manifest(java.util.jar.Manifest) Files(java.nio.file.Files) Inject(com.google.inject.Inject) Collection(java.util.Collection) PluginData(com.google.gerrit.common.PluginData) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) InitStep(com.google.gerrit.pgm.init.api.InitStep) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) Injector(com.google.inject.Injector) List(java.util.List) SitePaths(com.google.gerrit.server.config.SitePaths) ConsoleUI(com.google.gerrit.pgm.init.api.ConsoleUI) Comparator.comparing(java.util.Comparator.comparing) Path(java.nio.file.Path) JarPluginProvider(com.google.gerrit.server.plugins.JarPluginProvider) InitFlags(com.google.gerrit.pgm.init.api.InitFlags) Singleton(com.google.inject.Singleton) PluginData(com.google.gerrit.common.PluginData) ArrayList(java.util.ArrayList)

Aggregations

PluginData (com.google.gerrit.common.PluginData)3 ConsoleUI (com.google.gerrit.pgm.init.api.ConsoleUI)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 InitFlags (com.google.gerrit.pgm.init.api.InitFlags)1 InitStep (com.google.gerrit.pgm.init.api.InitStep)1 SitePaths (com.google.gerrit.server.config.SitePaths)1 GerritIndexStatus (com.google.gerrit.server.index.GerritIndexStatus)1 JarPluginProvider (com.google.gerrit.server.plugins.JarPluginProvider)1 Inject (com.google.inject.Inject)1 Injector (com.google.inject.Injector)1 Singleton (com.google.inject.Singleton)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Attributes (java.util.jar.Attributes)1 JarFile (java.util.jar.JarFile)1 Manifest (java.util.jar.Manifest)1