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
This commit is contained in:
Marco Miller 2016-04-08 11:52:09 -04:00
parent 309f8835f3
commit a3bb9106fc
7 changed files with 73 additions and 15 deletions

View File

@ -11,6 +11,7 @@ init - Initialize a new Gerrit server installation
[--no-auto-start] [--no-auto-start]
[--list-plugins] [--list-plugins]
[--install-plugin=<PLUGIN_NAME>] [--install-plugin=<PLUGIN_NAME>]
[--install-all-plugins]
[--dev] [--dev]
[--skip-all-downloads] [--skip-all-downloads]
[--skip-download=<LIBRARY_NAME>] [--skip-download=<LIBRARY_NAME>]
@ -30,10 +31,10 @@ as necessary.
configuration defaults are chosen based on the whims of configuration defaults are chosen based on the whims of
the Gerrit developers. the Gerrit developers.
+ +
If during a schema migration unused objects (e.g. tables, columns) If during a schema migration unused objects (e.g. tables, columns)
are detected they are *not* automatically dropped, but only a list of are detected they are *not* automatically dropped, but only a list of
SQL statements to drop these objects is provided. To drop the unused SQL statements to drop these objects is provided. To drop the unused
objects these SQL statements have to be executed manually. objects these SQL statements have to be executed manually.
--no-auto-start:: --no-auto-start::
Don't automatically start the daemon after initializing a Don't automatically start the daemon after initializing a
@ -49,10 +50,16 @@ objects these SQL statements have to be executed manually.
--list-plugins:: --list-plugins::
Print names of plugins that can be installed during init process. 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:: --install-plugin::
Automatically install plugin with given name without asking. Automatically install plugin with given name without asking.
This option may be supplied more than once to install multiple This option also works in batch mode. This option may be supplied
plugins. more than once to install multiple plugins. This option cannot be
supplied alongside --install-all-plugins.
--dev:: --dev::
Install in developer mode. Default configuration settings are Install in developer mode. Default configuration settings are

View File

@ -60,6 +60,10 @@ public class Init extends BaseInit {
@Option(name = "--install-plugin", usage = "Install given plugin without asking") @Option(name = "--install-plugin", usage = "Install given plugin without asking")
private List<String> installPlugins; private List<String> installPlugins;
@Option(name = "--install-all-plugins",
usage = "Install all plugins from war without asking")
private boolean installAllPlugins;
@Option(name = "--secure-store-lib", @Option(name = "--secure-store-lib",
usage = "Path to jar providing SecureStore implementation class") usage = "Path to jar providing SecureStore implementation class")
private String secureStoreLib; private String secureStoreLib;
@ -93,8 +97,14 @@ public class Init extends BaseInit {
if (!skipPlugins) { if (!skipPlugins) {
final List<PluginData> plugins = final List<PluginData> plugins =
InitPlugins.listPluginsAndRemoveTempFiles(init.site, pluginsDistribution); InitPlugins.listPluginsAndRemoveTempFiles(init.site,
pluginsDistribution);
ConsoleUI ui = ConsoleUI.getInstance(false); 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); verifyInstallPluginList(ui, plugins);
if (listPlugins) { if (listPlugins) {
if (!plugins.isEmpty()) { if (!plugins.isEmpty()) {
@ -133,6 +143,11 @@ public class Init extends BaseInit {
return installPlugins; return installPlugins;
} }
@Override
protected boolean installAllPlugins() {
return installAllPlugins;
}
@Override @Override
protected ConsoleUI getConsoleUI() { protected ConsoleUI getConsoleUI() {
return ConsoleUI.getInstance(batchMode); return ConsoleUI.getInstance(batchMode);

View File

@ -25,6 +25,7 @@ import com.google.gerrit.common.Die;
import com.google.gerrit.common.IoUtil; import com.google.gerrit.common.IoUtil;
import com.google.gerrit.pgm.init.api.ConsoleUI; import com.google.gerrit.pgm.init.api.ConsoleUI;
import com.google.gerrit.pgm.init.api.InitFlags; 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.InstallPlugins;
import com.google.gerrit.pgm.init.api.LibraryDownload; import com.google.gerrit.pgm.init.api.LibraryDownload;
import com.google.gerrit.pgm.util.SiteProgram; import com.google.gerrit.pgm.util.SiteProgram;
@ -197,6 +198,10 @@ public class BaseInit extends SiteProgram {
} }
} }
protected boolean installAllPlugins() {
return false;
}
protected boolean getAutoStart() { protected boolean getAutoStart() {
return false; return false;
} }
@ -245,6 +250,8 @@ public class BaseInit extends SiteProgram {
getInstallPlugins(), Lists.<String> newArrayList()); getInstallPlugins(), Lists.<String> newArrayList());
bind(new TypeLiteral<List<String>>() {}).annotatedWith( bind(new TypeLiteral<List<String>>() {}).annotatedWith(
InstallPlugins.class).toInstance(plugins); InstallPlugins.class).toInstance(plugins);
bind(new TypeLiteral<Boolean>() {}).annotatedWith(
InstallAllPlugins.class).toInstance(installAllPlugins());
bind(PluginsDistribution.class).toInstance(pluginsDistribution); bind(PluginsDistribution.class).toInstance(pluginsDistribution);
String secureStoreClassName; String secureStoreClassName;

View File

@ -121,8 +121,10 @@ public class InitPlugins implements InitStep {
Path p = site.plugins_dir.resolve(plugin.name + ".jar"); Path p = site.plugins_dir.resolve(plugin.name + ".jar");
boolean upgrade = Files.exists(p); boolean upgrade = Files.exists(p);
if (!(initFlags.installPlugins.contains(pluginName) || ui.yesno(upgrade, if (!(initFlags.installPlugins.contains(pluginName)
"Install plugin %s version %s", pluginName, plugin.version))) { || initFlags.installAllPlugins
|| ui.yesno(upgrade, "Install plugin %s version %s", pluginName,
plugin.version))) {
Files.deleteIfExists(tmpPlugin); Files.deleteIfExists(tmpPlugin);
continue; continue;
} }

View File

@ -45,17 +45,19 @@ public class InitFlags {
public final FileBasedConfig cfg; public final FileBasedConfig cfg;
public final SecureStore sec; public final SecureStore sec;
public final List<String> installPlugins; public final List<String> installPlugins;
public final boolean installAllPlugins;
@VisibleForTesting @VisibleForTesting
@Inject @Inject
public InitFlags(final SitePaths site, public InitFlags(final SitePaths site,
final SecureStore secureStore, final SecureStore secureStore,
@InstallPlugins final List<String> installPlugins) throws IOException, @InstallPlugins final List<String> installPlugins,
@InstallAllPlugins final Boolean installAllPlugins) throws IOException,
ConfigInvalidException { ConfigInvalidException {
sec = secureStore; sec = secureStore;
this.installPlugins = installPlugins; this.installPlugins = installPlugins;
this.installAllPlugins = installAllPlugins;
cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED); cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
cfg.load(); cfg.load();
} }
} }

View File

@ -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 {
}

View File

@ -71,8 +71,8 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
old.save(); old.save();
final InMemorySecureStore secureStore = new InMemorySecureStore(); final InMemorySecureStore secureStore = new InMemorySecureStore();
final InitFlags flags = final InitFlags flags = new InitFlags(site, secureStore,
new InitFlags(site, secureStore, Collections.<String> emptyList()); Collections.<String> emptyList(), false);
final ConsoleUI ui = createStrictMock(ConsoleUI.class); final ConsoleUI ui = createStrictMock(ConsoleUI.class);
Section.Factory sections = new Section.Factory() { Section.Factory sections = new Section.Factory() {
@Override @Override