Add '--install-plugin' option to init step
This allows automatically install given plugin without asking. Can be also used together with '--batch' to automatically install/update Gerrit without interactions. Change-Id: I8e0cf8f2e39c813e54daff6b587cb8cd2485bae8 Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
@@ -13,6 +13,7 @@ SYNOPSIS
|
|||||||
[\--batch]
|
[\--batch]
|
||||||
[\--no-auto-start]
|
[\--no-auto-start]
|
||||||
[\--list-plugins]
|
[\--list-plugins]
|
||||||
|
[\--install-plugin=<PLUGIN_NAME>]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@@ -49,6 +50,9 @@ 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-plugin:
|
||||||
|
Automatically install plugin with given name without asking.
|
||||||
|
|
||||||
CONTEXT
|
CONTEXT
|
||||||
-------
|
-------
|
||||||
This command can only be run on a server which has direct
|
This command can only be run on a server which has direct
|
||||||
|
@@ -17,12 +17,17 @@ package com.google.gerrit.pgm;
|
|||||||
import static com.google.gerrit.server.schema.DataSourceProvider.Context.SINGLE_USER;
|
import static com.google.gerrit.server.schema.DataSourceProvider.Context.SINGLE_USER;
|
||||||
import static com.google.inject.Stage.PRODUCTION;
|
import static com.google.inject.Stage.PRODUCTION;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.pgm.init.Browser;
|
import com.google.gerrit.pgm.init.Browser;
|
||||||
import com.google.gerrit.pgm.init.InitFlags;
|
import com.google.gerrit.pgm.init.InitFlags;
|
||||||
import com.google.gerrit.pgm.init.InitModule;
|
import com.google.gerrit.pgm.init.InitModule;
|
||||||
import com.google.gerrit.pgm.init.InitPlugins;
|
import com.google.gerrit.pgm.init.InitPlugins;
|
||||||
import com.google.gerrit.pgm.init.InitPlugins.PluginData;
|
import com.google.gerrit.pgm.init.InitPlugins.PluginData;
|
||||||
|
import com.google.gerrit.pgm.init.InstallPlugins;
|
||||||
import com.google.gerrit.pgm.init.SitePathInitializer;
|
import com.google.gerrit.pgm.init.SitePathInitializer;
|
||||||
import com.google.gerrit.pgm.util.ConsoleUI;
|
import com.google.gerrit.pgm.util.ConsoleUI;
|
||||||
import com.google.gerrit.pgm.util.Die;
|
import com.google.gerrit.pgm.util.Die;
|
||||||
@@ -36,6 +41,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
|
|||||||
import com.google.gerrit.server.schema.SchemaUpdater;
|
import com.google.gerrit.server.schema.SchemaUpdater;
|
||||||
import com.google.gerrit.server.schema.UpdateUI;
|
import com.google.gerrit.server.schema.UpdateUI;
|
||||||
import com.google.gerrit.server.util.HostPlatform;
|
import com.google.gerrit.server.util.HostPlatform;
|
||||||
|
import com.google.gwt.thirdparty.guava.common.base.Objects;
|
||||||
import com.google.gwtorm.jdbc.JdbcExecutor;
|
import com.google.gwtorm.jdbc.JdbcExecutor;
|
||||||
import com.google.gwtorm.jdbc.JdbcSchema;
|
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@@ -47,6 +53,7 @@ import com.google.inject.Guice;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.spi.Message;
|
import com.google.inject.spi.Message;
|
||||||
|
|
||||||
import org.kohsuke.args4j.Option;
|
import org.kohsuke.args4j.Option;
|
||||||
@@ -67,6 +74,9 @@ public class Init extends SiteProgram {
|
|||||||
@Option(name = "--list-plugins", usage = "List available plugins")
|
@Option(name = "--list-plugins", usage = "List available plugins")
|
||||||
private boolean listPlugins;
|
private boolean listPlugins;
|
||||||
|
|
||||||
|
@Option(name = "--install-plugin", usage = "Install given plugin without asking", multiValued = true)
|
||||||
|
private List<String> installPlugins;
|
||||||
|
|
||||||
public Init() {
|
public Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,9 +91,10 @@ public class Init extends SiteProgram {
|
|||||||
ErrorLogFile.errorOnlyConsole();
|
ErrorLogFile.errorOnlyConsole();
|
||||||
|
|
||||||
final SiteInit init = createSiteInit();
|
final SiteInit init = createSiteInit();
|
||||||
|
final List<PluginData> plugins = InitPlugins.listPlugins(init.site);
|
||||||
|
ConsoleUI ui = ConsoleUI.getInstance(false);
|
||||||
|
verifyInstallPluginList(ui, plugins);
|
||||||
if (listPlugins) {
|
if (listPlugins) {
|
||||||
final ConsoleUI ui = ConsoleUI.getInstance();
|
|
||||||
final List<PluginData> plugins = InitPlugins.listPlugins(init.site);
|
|
||||||
if (!plugins.isEmpty()) {
|
if (!plugins.isEmpty()) {
|
||||||
ui.message("Available plugins:\n");
|
ui.message("Available plugins:\n");
|
||||||
for (PluginData plugin : plugins) {
|
for (PluginData plugin : plugins) {
|
||||||
@@ -148,6 +159,10 @@ public class Init extends SiteProgram {
|
|||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(ConsoleUI.class).toInstance(ui);
|
bind(ConsoleUI.class).toInstance(ui);
|
||||||
bind(File.class).annotatedWith(SitePath.class).toInstance(sitePath);
|
bind(File.class).annotatedWith(SitePath.class).toInstance(sitePath);
|
||||||
|
List<String> plugins =
|
||||||
|
Objects.firstNonNull(installPlugins, Lists.<String> newArrayList());
|
||||||
|
bind(new TypeLiteral<List<String>>() {}).annotatedWith(
|
||||||
|
InstallPlugins.class).toInstance(plugins);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -334,4 +349,26 @@ public class Init extends SiteProgram {
|
|||||||
System.err.println("warn: Cannot remove " + path);
|
System.err.println("warn: Cannot remove " + path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyInstallPluginList(ConsoleUI ui, List<PluginData> plugins) {
|
||||||
|
if (nullOrEmpty(installPlugins) || nullOrEmpty(plugins)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<String> copy = Lists.newArrayList(installPlugins);
|
||||||
|
List<String> pluginNames = Lists.transform(plugins, new Function<PluginData, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(PluginData input) {
|
||||||
|
return input.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
copy.removeAll(pluginNames);
|
||||||
|
if (!copy.isEmpty()) {
|
||||||
|
ui.message("Cannot find plugin(s): %s\n", Joiner.on(", ").join(copy));
|
||||||
|
listPlugins = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean nullOrEmpty(List<?> list) {
|
||||||
|
return list == null || list.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
|
|||||||
import org.eclipse.jgit.util.FS;
|
import org.eclipse.jgit.util.FS;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/** Global variables used by the 'init' command. */
|
/** Global variables used by the 'init' command. */
|
||||||
@Singleton
|
@Singleton
|
||||||
@@ -35,9 +36,13 @@ public class InitFlags {
|
|||||||
|
|
||||||
public final FileBasedConfig cfg;
|
public final FileBasedConfig cfg;
|
||||||
public final FileBasedConfig sec;
|
public final FileBasedConfig sec;
|
||||||
|
public final List<String> installPlugins;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InitFlags(final SitePaths site) throws IOException, ConfigInvalidException {
|
InitFlags(final SitePaths site,
|
||||||
|
final @InstallPlugins List<String> installPlugins) throws IOException,
|
||||||
|
ConfigInvalidException {
|
||||||
|
this.installPlugins = installPlugins;
|
||||||
cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
cfg = new FileBasedConfig(site.gerrit_config, FS.DETECTED);
|
||||||
sec = new FileBasedConfig(site.secure_config, FS.DETECTED);
|
sec = new FileBasedConfig(site.secure_config, FS.DETECTED);
|
||||||
|
|
||||||
|
@@ -84,12 +84,15 @@ public class InitPlugins implements InitStep {
|
|||||||
|
|
||||||
private final ConsoleUI ui;
|
private final ConsoleUI ui;
|
||||||
private final SitePaths site;
|
private final SitePaths site;
|
||||||
private InitPluginStepsLoader pluginLoader;
|
private final InitFlags initFlags;
|
||||||
|
private final InitPluginStepsLoader pluginLoader;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
InitPlugins(final ConsoleUI ui, final SitePaths site, InitPluginStepsLoader pluginLoader) {
|
InitPlugins(final ConsoleUI ui, final SitePaths site,
|
||||||
|
InitFlags initFlags, InitPluginStepsLoader pluginLoader) {
|
||||||
this.ui = ui;
|
this.ui = ui;
|
||||||
this.site = site;
|
this.site = site;
|
||||||
|
this.initFlags = initFlags;
|
||||||
this.pluginLoader = pluginLoader;
|
this.pluginLoader = pluginLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +111,8 @@ public class InitPlugins implements InitStep {
|
|||||||
try {
|
try {
|
||||||
final File tmpPlugin = plugin.pluginFile;
|
final File tmpPlugin = plugin.pluginFile;
|
||||||
|
|
||||||
if (!ui.yesno(false, "Install plugin %s version %s", pluginName,
|
if (!(initFlags.installPlugins.contains(pluginName) || ui.yesno(false,
|
||||||
plugin.version)) {
|
"Install plugin %s version %s", pluginName, plugin.version))) {
|
||||||
tmpPlugin.delete();
|
tmpPlugin.delete();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (C) 2013 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;
|
||||||
|
|
||||||
|
import com.google.inject.BindingAnnotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@BindingAnnotation
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface InstallPlugins {
|
||||||
|
}
|
Reference in New Issue
Block a user