Control which plugins will be auto installed on auto init
Use the system property 'gerrit.install_plugins' to control which of the packaged plugins will be installed during auto site init in a servlet container. When 'gerrit.install_plugins' property is not defined then all packaged plugins will be installed. If it is present then it is parsed as a comma separated list of plugin names to install. Defining an empty string as the property value means that no plugin will be installed. Change-Id: I52881c9677bc9cc1e51c46c2c2ce4558c79b9a3e
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
|
||||
Gerrit supports automatic site initialization on server startup
|
||||
when Gerrit runs in a servlet container. Both creation of a new site
|
||||
and upgrade of an existing site are supported. All packaged plugins
|
||||
will be installed when Gerrit is deployed in a servlet container and the
|
||||
location of the Gerrit distribution can be determined at runtime.
|
||||
and upgrade of an existing site are supported. By default, all packaged
|
||||
plugins will be installed when Gerrit is deployed in a servlet container
|
||||
and the location of the Gerrit distribution can be determined at
|
||||
runtime. It is also possible to install only a subset of packaged
|
||||
plugins or not install any plugin.
|
||||
|
||||
This feature may be useful for such setups where Gerrit administrators
|
||||
don't have direct access to the database and the file system of the
|
||||
@@ -50,6 +52,11 @@ creation). In order to auto initialize Gerrit with an embedded H2
|
||||
database use the `gerrit.site_path` to define the location of the review
|
||||
site and don't define a JNDI resource with a URL under that path.
|
||||
|
||||
If the 'gerrit.install_plugins' property is not defined then all packaged
|
||||
plugins will be installed. If it is defined then it is parsed as a
|
||||
comma separated list of plugin names to install. If the value is an
|
||||
empty string then no plugin will be installed.
|
||||
|
||||
=== Example 1
|
||||
|
||||
Prepare Tomcat so that a site is initialized at a given path using
|
||||
|
@@ -54,6 +54,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -66,25 +68,29 @@ public class BaseInit extends SiteProgram {
|
||||
private final boolean standalone;
|
||||
private final boolean initDb;
|
||||
protected final PluginsDistribution pluginsDistribution;
|
||||
private final List<String> pluginsToInstall;
|
||||
|
||||
protected BaseInit(PluginsDistribution pluginsDistribution) {
|
||||
protected BaseInit(PluginsDistribution pluginsDistribution,
|
||||
List<String> pluginsToInstall) {
|
||||
this.standalone = true;
|
||||
this.initDb = true;
|
||||
this.pluginsDistribution = pluginsDistribution;
|
||||
this.pluginsToInstall = pluginsToInstall;
|
||||
}
|
||||
|
||||
public BaseInit(File sitePath, boolean standalone, boolean initDb,
|
||||
PluginsDistribution pluginsDistribution) {
|
||||
this(sitePath, null, standalone, initDb, pluginsDistribution);
|
||||
PluginsDistribution pluginsDistribution, List<String> pluginsToInstall) {
|
||||
this(sitePath, null, standalone, initDb, pluginsDistribution, pluginsToInstall);
|
||||
}
|
||||
|
||||
public BaseInit(File sitePath, final Provider<DataSource> dsProvider,
|
||||
boolean standalone, boolean initDb,
|
||||
PluginsDistribution pluginsDistribution) {
|
||||
PluginsDistribution pluginsDistribution, List<String> pluginsToInstall) {
|
||||
super(sitePath, dsProvider);
|
||||
this.standalone = standalone;
|
||||
this.initDb = initDb;
|
||||
this.pluginsDistribution = pluginsDistribution;
|
||||
this.pluginsToInstall = pluginsToInstall;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +142,19 @@ public class BaseInit extends SiteProgram {
|
||||
|
||||
protected List<String> getInstallPlugins() {
|
||||
try {
|
||||
return pluginsDistribution.listPluginNames();
|
||||
if (pluginsToInstall != null && pluginsToInstall.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<String> names = pluginsDistribution.listPluginNames();
|
||||
if (pluginsToInstall != null) {
|
||||
for (Iterator<String> i = names.iterator(); i.hasNext();) {
|
||||
String n = i.next();
|
||||
if (!pluginsToInstall.contains(n)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
return names;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.warn("Couldn't find distribution archive location."
|
||||
+ " No plugin will be installed");
|
||||
|
@@ -60,11 +60,11 @@ public class Init extends BaseInit {
|
||||
Browser browser;
|
||||
|
||||
public Init() {
|
||||
super(new WarDistribution());
|
||||
super(new WarDistribution(), null);
|
||||
}
|
||||
|
||||
public Init(File sitePath) {
|
||||
super(sitePath, true, true, new WarDistribution());
|
||||
super(sitePath, true, true, new WarDistribution(), null);
|
||||
batchMode = true;
|
||||
noAutoStart = true;
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
|
||||
public final class SiteInitializer {
|
||||
private static final Logger LOG = LoggerFactory
|
||||
@@ -33,12 +34,14 @@ public final class SiteInitializer {
|
||||
private final String sitePath;
|
||||
private final String initPath;
|
||||
private final PluginsDistribution pluginsDistribution;
|
||||
private final List<String> pluginsToInstall;
|
||||
|
||||
SiteInitializer(String sitePath, String initPath,
|
||||
PluginsDistribution pluginsDistribution) {
|
||||
PluginsDistribution pluginsDistribution, List<String> pluginsToInstall) {
|
||||
this.sitePath = sitePath;
|
||||
this.initPath = initPath;
|
||||
this.pluginsDistribution = pluginsDistribution;
|
||||
this.pluginsToInstall = pluginsToInstall;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@@ -47,7 +50,7 @@ public final class SiteInitializer {
|
||||
File site = new File(sitePath);
|
||||
LOG.info(String.format("Initializing site at %s",
|
||||
site.getAbsolutePath()));
|
||||
new BaseInit(site, false, true, pluginsDistribution).run();
|
||||
new BaseInit(site, false, true, pluginsDistribution, pluginsToInstall).run();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,7 +64,7 @@ public final class SiteInitializer {
|
||||
LOG.info(String.format("Initializing site at %s",
|
||||
site.getAbsolutePath()));
|
||||
new BaseInit(site, new ReviewDbDataSourceProvider(), false, false,
|
||||
pluginsDistribution).run();
|
||||
pluginsDistribution, pluginsToInstall).run();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.httpd;
|
||||
import static com.google.inject.Scopes.SINGLETON;
|
||||
import static com.google.inject.Stage.PRODUCTION;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.gerrit.common.ChangeHookRunner;
|
||||
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
|
||||
import com.google.gerrit.httpd.plugins.HttpPluginModule;
|
||||
@@ -122,8 +123,16 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
}
|
||||
|
||||
if (System.getProperty("gerrit.init") != null) {
|
||||
List<String> pluginsToInstall;
|
||||
String installPlugins = System.getProperty("gerrit.install_plugins");
|
||||
if (installPlugins == null) {
|
||||
pluginsToInstall = null;
|
||||
} else {
|
||||
pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings()
|
||||
.splitToList(installPlugins);
|
||||
}
|
||||
new SiteInitializer(path, System.getProperty("gerrit.init_path"),
|
||||
new UnzippedDistribution(servletContext)).init();
|
||||
new UnzippedDistribution(servletContext), pluginsToInstall).init();
|
||||
}
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user