From a3bb9106fc34a642ef3a7ab4a30e7f58c0611154 Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Fri, 8 Apr 2016 11:52:09 -0400 Subject: [PATCH] Add --install-all-plugins (from gerrit.war) option to pgm init Automatically installs all plugins from gerrit.war without asking. This option cannot be supplied alongside --install-plugin. If it is, there is a message about this to the user and the init command aborts. Change-Id: Ia793e64d2cb24b34ffd7f6c33677701c8b6d43d4 --- Documentation/pgm-init.txt | 21 ++++++++++------ .../main/java/com/google/gerrit/pgm/Init.java | 17 ++++++++++++- .../com/google/gerrit/pgm/init/BaseInit.java | 7 ++++++ .../google/gerrit/pgm/init/InitPlugins.java | 6 +++-- .../google/gerrit/pgm/init/api/InitFlags.java | 8 +++--- .../pgm/init/api/InstallAllPlugins.java | 25 +++++++++++++++++++ .../gerrit/pgm/init/UpgradeFrom2_0_xTest.java | 4 +-- 7 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InstallAllPlugins.java diff --git a/Documentation/pgm-init.txt b/Documentation/pgm-init.txt index 9fe813bc6f..9dea161f25 100644 --- a/Documentation/pgm-init.txt +++ b/Documentation/pgm-init.txt @@ -11,7 +11,8 @@ init - Initialize a new Gerrit server installation [--no-auto-start] [--list-plugins] [--install-plugin=] - [--dev] + [--install-all-plugins] + [--dev] [--skip-all-downloads] [--skip-download=] -- @@ -30,10 +31,10 @@ as necessary. configuration defaults are chosen based on the whims of the Gerrit developers. + -If during a schema migration unused objects (e.g. tables, columns) -are detected they are *not* automatically dropped, but only a list of -SQL statements to drop these objects is provided. To drop the unused -objects these SQL statements have to be executed manually. + If during a schema migration unused objects (e.g. tables, columns) + are detected they are *not* automatically dropped, but only a list of + SQL statements to drop these objects is provided. To drop the unused + objects these SQL statements have to be executed manually. --no-auto-start:: Don't automatically start the daemon after initializing a @@ -49,10 +50,16 @@ objects these SQL statements have to be executed manually. --list-plugins:: Print names of plugins that can be installed during init process. +--install-all-plugins:: + Automatically install all plugins from gerrit.war without asking. + This option also works in batch mode. This option cannot be supplied + alongside --install-plugin. + --install-plugin:: Automatically install plugin with given name without asking. - This option may be supplied more than once to install multiple - plugins. + This option also works in batch mode. This option may be supplied + more than once to install multiple plugins. This option cannot be + supplied alongside --install-all-plugins. --dev:: Install in developer mode. Default configuration settings are diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Init.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Init.java index f57f95f17e..e51218e5d2 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Init.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/Init.java @@ -60,6 +60,10 @@ public class Init extends BaseInit { @Option(name = "--install-plugin", usage = "Install given plugin without asking") private List installPlugins; + @Option(name = "--install-all-plugins", + usage = "Install all plugins from war without asking") + private boolean installAllPlugins; + @Option(name = "--secure-store-lib", usage = "Path to jar providing SecureStore implementation class") private String secureStoreLib; @@ -93,8 +97,14 @@ public class Init extends BaseInit { if (!skipPlugins) { final List plugins = - InitPlugins.listPluginsAndRemoveTempFiles(init.site, pluginsDistribution); + 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()) { @@ -133,6 +143,11 @@ public class Init extends BaseInit { return installPlugins; } + @Override + protected boolean installAllPlugins() { + return installAllPlugins; + } + @Override protected ConsoleUI getConsoleUI() { return ConsoleUI.getInstance(batchMode); diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/BaseInit.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/BaseInit.java index 2136723f16..d16c3bdfa1 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/BaseInit.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/BaseInit.java @@ -25,6 +25,7 @@ import com.google.gerrit.common.Die; import com.google.gerrit.common.IoUtil; import com.google.gerrit.pgm.init.api.ConsoleUI; import com.google.gerrit.pgm.init.api.InitFlags; +import com.google.gerrit.pgm.init.api.InstallAllPlugins; import com.google.gerrit.pgm.init.api.InstallPlugins; import com.google.gerrit.pgm.init.api.LibraryDownload; import com.google.gerrit.pgm.util.SiteProgram; @@ -197,6 +198,10 @@ public class BaseInit extends SiteProgram { } } + protected boolean installAllPlugins() { + return false; + } + protected boolean getAutoStart() { return false; } @@ -245,6 +250,8 @@ public class BaseInit extends SiteProgram { getInstallPlugins(), Lists. newArrayList()); bind(new TypeLiteral>() {}).annotatedWith( InstallPlugins.class).toInstance(plugins); + bind(new TypeLiteral() {}).annotatedWith( + InstallAllPlugins.class).toInstance(installAllPlugins()); bind(PluginsDistribution.class).toInstance(pluginsDistribution); String secureStoreClassName; diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java index 7fdd7e2b41..515ca20755 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java @@ -121,8 +121,10 @@ public class InitPlugins implements InitStep { Path p = site.plugins_dir.resolve(plugin.name + ".jar"); boolean upgrade = Files.exists(p); - if (!(initFlags.installPlugins.contains(pluginName) || ui.yesno(upgrade, - "Install plugin %s version %s", pluginName, plugin.version))) { + if (!(initFlags.installPlugins.contains(pluginName) + || initFlags.installAllPlugins + || ui.yesno(upgrade, "Install plugin %s version %s", pluginName, + plugin.version))) { Files.deleteIfExists(tmpPlugin); continue; } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InitFlags.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InitFlags.java index bdd8b8674a..f0674d6db2 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InitFlags.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InitFlags.java @@ -45,17 +45,19 @@ public class InitFlags { public final FileBasedConfig cfg; public final SecureStore sec; public final List installPlugins; + public final boolean installAllPlugins; @VisibleForTesting @Inject public InitFlags(final SitePaths site, final SecureStore secureStore, - @InstallPlugins final List installPlugins) throws IOException, - ConfigInvalidException { + @InstallPlugins final List installPlugins, + @InstallAllPlugins final Boolean installAllPlugins) throws IOException, + ConfigInvalidException { sec = secureStore; this.installPlugins = installPlugins; + this.installAllPlugins = installAllPlugins; cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED); - cfg.load(); } } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InstallAllPlugins.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InstallAllPlugins.java new file mode 100644 index 0000000000..809a19758f --- /dev/null +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/api/InstallAllPlugins.java @@ -0,0 +1,25 @@ +// Copyright (C) 2016 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.pgm.init.api; + +import com.google.inject.BindingAnnotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@BindingAnnotation +@Retention(RetentionPolicy.RUNTIME) +public @interface InstallAllPlugins { +} diff --git a/gerrit-pgm/src/test/java/com/google/gerrit/pgm/init/UpgradeFrom2_0_xTest.java b/gerrit-pgm/src/test/java/com/google/gerrit/pgm/init/UpgradeFrom2_0_xTest.java index dc7ce59104..af30f735e2 100644 --- a/gerrit-pgm/src/test/java/com/google/gerrit/pgm/init/UpgradeFrom2_0_xTest.java +++ b/gerrit-pgm/src/test/java/com/google/gerrit/pgm/init/UpgradeFrom2_0_xTest.java @@ -71,8 +71,8 @@ public class UpgradeFrom2_0_xTest extends InitTestCase { old.save(); final InMemorySecureStore secureStore = new InMemorySecureStore(); - final InitFlags flags = - new InitFlags(site, secureStore, Collections. emptyList()); + final InitFlags flags = new InitFlags(site, secureStore, + Collections. emptyList(), false); final ConsoleUI ui = createStrictMock(ConsoleUI.class); Section.Factory sections = new Section.Factory() { @Override