Merge "Allow init steps to do initialisation after the site is created"
This commit is contained in:
@@ -89,6 +89,8 @@ public class BaseInit extends SiteProgram {
|
|||||||
|
|
||||||
run = createSiteRun(init);
|
run = createSiteRun(init);
|
||||||
run.upgradeSchema();
|
run.upgradeSchema();
|
||||||
|
|
||||||
|
init.initializer.postRun();
|
||||||
} catch (Exception failure) {
|
} catch (Exception failure) {
|
||||||
if (init.flags.deleteOnFailure) {
|
if (init.flags.deleteOnFailure) {
|
||||||
recursiveDelete(getSitePath());
|
recursiveDelete(getSitePath());
|
||||||
|
@@ -38,23 +38,19 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class AllProjectsConfig extends VersionedMetaData {
|
public class AllProjectsConfig extends VersionedMetaData {
|
||||||
private final String project;
|
private final String project;
|
||||||
private final File path;
|
private final SitePaths site;
|
||||||
|
private final InitFlags flags;
|
||||||
|
|
||||||
private Config cfg;
|
private Config cfg;
|
||||||
private ObjectId revision;
|
private ObjectId revision;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AllProjectsConfig(AllProjectsNameOnInitProvider allProjects, SitePaths site,
|
AllProjectsConfig(AllProjectsNameOnInitProvider allProjects, SitePaths site,
|
||||||
Section.Factory sections) {
|
InitFlags flags) {
|
||||||
project = allProjects.get();
|
this.project = allProjects.get();
|
||||||
File basePath = site.resolve(sections.get("gerrit", null).get("basePath"));
|
this.site = site;
|
||||||
if (basePath == null) {
|
this.flags = flags;
|
||||||
throw new IllegalStateException("gerrit.basePath must be configured");
|
|
||||||
}
|
|
||||||
path = FileKey.resolve(new File(basePath, project), FS.DETECTED);
|
|
||||||
if (path == null) {
|
|
||||||
throw new IllegalStateException(project + " project not found");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,7 +58,20 @@ public class AllProjectsConfig extends VersionedMetaData {
|
|||||||
return RefNames.REFS_CONFIG;
|
return RefNames.REFS_CONFIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File getPath() {
|
||||||
|
File basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
|
||||||
|
if (basePath == null) {
|
||||||
|
throw new IllegalStateException("gerrit.basePath must be configured");
|
||||||
|
}
|
||||||
|
return FileKey.resolve(new File(basePath, project), FS.DETECTED);
|
||||||
|
}
|
||||||
|
|
||||||
public Config load() throws IOException, ConfigInvalidException {
|
public Config load() throws IOException, ConfigInvalidException {
|
||||||
|
File path = getPath();
|
||||||
|
if (path == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Repository repo = new FileRepository(path);
|
Repository repo = new FileRepository(path);
|
||||||
try {
|
try {
|
||||||
load(repo);
|
load(repo);
|
||||||
@@ -85,6 +94,11 @@ public class AllProjectsConfig extends VersionedMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save(String pluginName, String message) throws IOException {
|
public void save(String pluginName, String message) throws IOException {
|
||||||
|
File path = getPath();
|
||||||
|
if (path == null) {
|
||||||
|
throw new IOException("All-Projects does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
Repository repo = new FileRepository(path);
|
Repository repo = new FileRepository(path);
|
||||||
try {
|
try {
|
||||||
inserter = repo.newObjectInserter();
|
inserter = repo.newObjectInserter();
|
||||||
|
@@ -107,4 +107,8 @@ class InitAuth implements InitStep {
|
|||||||
auth.setSecure("restTokenPrivateKey", SignedToken.generateRandomKey());
|
auth.setSecure("restTokenPrivateKey", SignedToken.generateRandomKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,4 +54,8 @@ class InitCache implements InitStep {
|
|||||||
throw die("cannot create cache.directory " + loc.getAbsolutePath());
|
throw die("cannot create cache.directory " + loc.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -127,4 +127,8 @@ class InitContainer implements InitStep {
|
|||||||
private static String javaHome() {
|
private static String javaHome() {
|
||||||
return System.getProperty("java.home");
|
return System.getProperty("java.home");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -85,4 +85,8 @@ class InitDatabase implements InitStep {
|
|||||||
|
|
||||||
dci.initConfig(database);
|
dci.initConfig(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,4 +45,8 @@ class InitGitManager implements InitStep {
|
|||||||
throw die("Cannot create " + d);
|
throw die("Cannot create " + d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -189,4 +189,8 @@ class InitHttpd implements InitStep {
|
|||||||
throw die("Cannot delete " + tmpdir);
|
throw die("Cannot delete " + tmpdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -177,4 +177,8 @@ class InitIndex implements InitStep {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -115,6 +115,11 @@ public class InitPlugins implements InitStep {
|
|||||||
initPlugins();
|
initPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
postInitPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
private void installPlugins() throws IOException {
|
private void installPlugins() throws IOException {
|
||||||
List<PluginData> plugins = listPlugins(site);
|
List<PluginData> plugins = listPlugins(site);
|
||||||
for (PluginData plugin : plugins) {
|
for (PluginData plugin : plugins) {
|
||||||
@@ -164,6 +169,12 @@ public class InitPlugins implements InitStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postInitPlugins() throws Exception {
|
||||||
|
for (InitStep initStep : pluginLoader.getInitSteps()) {
|
||||||
|
initStep.postRun();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String getVersion(final File plugin) throws IOException {
|
private static String getVersion(final File plugin) throws IOException {
|
||||||
final JarFile jarFile = new JarFile(plugin);
|
final JarFile jarFile = new JarFile(plugin);
|
||||||
try {
|
try {
|
||||||
|
@@ -59,4 +59,8 @@ class InitSendEmail implements InitStep {
|
|||||||
sendemail.string("SMTP username", "smtpUser", username);
|
sendemail.string("SMTP username", "smtpUser", username);
|
||||||
sendemail.password("smtpUser", "smtpPass");
|
sendemail.password("smtpUser", "smtpPass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -152,4 +152,8 @@ class InitSshd implements InitStep {
|
|||||||
System.err.println(" done");
|
System.err.println(" done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,4 +17,7 @@ package com.google.gerrit.pgm.init;
|
|||||||
/** A single step in the site initialization process. */
|
/** A single step in the site initialization process. */
|
||||||
public interface InitStep {
|
public interface InitStep {
|
||||||
public void run() throws Exception;
|
public void run() throws Exception;
|
||||||
|
|
||||||
|
/** Executed after the site has been initialized */
|
||||||
|
public void postRun() throws Exception;
|
||||||
}
|
}
|
||||||
|
@@ -109,6 +109,16 @@ public class SitePathInitializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
for (InitStep step : steps) {
|
||||||
|
if (step instanceof InitPlugins
|
||||||
|
&& flags.skipPlugins) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
step.postRun();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void extractMailExample(String orig) throws Exception {
|
private void extractMailExample(String orig) throws Exception {
|
||||||
File ex = new File(site.mail_dir, orig + ".example");
|
File ex = new File(site.mail_dir, orig + ".example");
|
||||||
extract(ex, OutgoingEmail.class, orig);
|
extract(ex, OutgoingEmail.class, orig);
|
||||||
|
@@ -286,4 +286,8 @@ class UpgradeFrom2_0_x implements InitStep {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postRun() throws Exception {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user