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,7 +11,8 @@ init - Initialize a new Gerrit server installation
[--no-auto-start]
[--list-plugins]
[--install-plugin=<PLUGIN_NAME>]
[--dev]
[--install-all-plugins]
[--dev]
[--skip-all-downloads]
[--skip-download=<LIBRARY_NAME>]
--
@ -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

View File

@ -60,6 +60,10 @@ public class Init extends BaseInit {
@Option(name = "--install-plugin", usage = "Install given plugin without asking")
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",
usage = "Path to jar providing SecureStore implementation class")
private String secureStoreLib;
@ -93,8 +97,14 @@ public class Init extends BaseInit {
if (!skipPlugins) {
final List<PluginData> 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);

View File

@ -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.<String> newArrayList());
bind(new TypeLiteral<List<String>>() {}).annotatedWith(
InstallPlugins.class).toInstance(plugins);
bind(new TypeLiteral<Boolean>() {}).annotatedWith(
InstallAllPlugins.class).toInstance(installAllPlugins());
bind(PluginsDistribution.class).toInstance(pluginsDistribution);
String secureStoreClassName;

View File

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

View File

@ -45,17 +45,19 @@ public class InitFlags {
public final FileBasedConfig cfg;
public final SecureStore sec;
public final List<String> installPlugins;
public final boolean installAllPlugins;
@VisibleForTesting
@Inject
public InitFlags(final SitePaths site,
final SecureStore secureStore,
@InstallPlugins final List<String> installPlugins) throws IOException,
ConfigInvalidException {
@InstallPlugins final List<String> 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();
}
}

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();
final InMemorySecureStore secureStore = new InMemorySecureStore();
final InitFlags flags =
new InitFlags(site, secureStore, Collections.<String> emptyList());
final InitFlags flags = new InitFlags(site, secureStore,
Collections.<String> emptyList(), false);
final ConsoleUI ui = createStrictMock(ConsoleUI.class);
Section.Factory sections = new Section.Factory() {
@Override