Merge "Allow init steps to do initialisation after the site is created"
This commit is contained in:
commit
c555134731
@ -89,6 +89,8 @@ public class BaseInit extends SiteProgram {
|
||||
|
||||
run = createSiteRun(init);
|
||||
run.upgradeSchema();
|
||||
|
||||
init.initializer.postRun();
|
||||
} catch (Exception failure) {
|
||||
if (init.flags.deleteOnFailure) {
|
||||
recursiveDelete(getSitePath());
|
||||
|
@ -38,23 +38,19 @@ import java.io.IOException;
|
||||
|
||||
public class AllProjectsConfig extends VersionedMetaData {
|
||||
private final String project;
|
||||
private final File path;
|
||||
private final SitePaths site;
|
||||
private final InitFlags flags;
|
||||
|
||||
private Config cfg;
|
||||
private ObjectId revision;
|
||||
|
||||
@Inject
|
||||
AllProjectsConfig(AllProjectsNameOnInitProvider allProjects, SitePaths site,
|
||||
Section.Factory sections) {
|
||||
project = allProjects.get();
|
||||
File basePath = site.resolve(sections.get("gerrit", null).get("basePath"));
|
||||
if (basePath == null) {
|
||||
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");
|
||||
}
|
||||
InitFlags flags) {
|
||||
this.project = allProjects.get();
|
||||
this.site = site;
|
||||
this.flags = flags;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,7 +58,20 @@ public class AllProjectsConfig extends VersionedMetaData {
|
||||
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 {
|
||||
File path = getPath();
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Repository repo = new FileRepository(path);
|
||||
try {
|
||||
load(repo);
|
||||
@ -85,6 +94,11 @@ public class AllProjectsConfig extends VersionedMetaData {
|
||||
}
|
||||
|
||||
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);
|
||||
try {
|
||||
inserter = repo.newObjectInserter();
|
||||
|
@ -107,4 +107,8 @@ class InitAuth implements InitStep {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
@ -127,4 +127,8 @@ class InitContainer implements InitStep {
|
||||
private static String javaHome() {
|
||||
return System.getProperty("java.home");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +85,8 @@ class InitDatabase implements InitStep {
|
||||
|
||||
dci.initConfig(database);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,8 @@ class InitGitManager implements InitStep {
|
||||
throw die("Cannot create " + d);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
@ -189,4 +189,8 @@ class InitHttpd implements InitStep {
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
postInitPlugins();
|
||||
}
|
||||
|
||||
private void installPlugins() throws IOException {
|
||||
List<PluginData> plugins = listPlugins(site);
|
||||
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 {
|
||||
final JarFile jarFile = new JarFile(plugin);
|
||||
try {
|
||||
|
@ -59,4 +59,8 @@ class InitSendEmail implements InitStep {
|
||||
sendemail.string("SMTP username", "smtpUser", username);
|
||||
sendemail.password("smtpUser", "smtpPass");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
@ -152,4 +152,8 @@ class InitSshd implements InitStep {
|
||||
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. */
|
||||
public interface InitStep {
|
||||
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 {
|
||||
File ex = new File(site.mail_dir, orig + ".example");
|
||||
extract(ex, OutgoingEmail.class, orig);
|
||||
|
@ -286,4 +286,8 @@ class UpgradeFrom2_0_x implements InitStep {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user