use of com.google.gerrit.pgm.Init in project gerrit by GerritCodeReview.
the class GerritServer method initSite.
private static File initSite(Config base) throws Exception {
File tmp = TempFileUtil.createTempDirectory();
Init init = new Init();
int rc = init.main(new String[] { "-d", tmp.getPath(), "--batch", "--no-auto-start", "--skip-plugins" });
if (rc != 0) {
throw new RuntimeException("Couldn't initialize site");
}
MergeableFileBasedConfig cfg = new MergeableFileBasedConfig(new File(new File(tmp, "etc"), "gerrit.config"), FS.DETECTED);
cfg.load();
cfg.merge(base);
mergeTestConfig(cfg);
cfg.save();
return tmp;
}
use of com.google.gerrit.pgm.Init in project gerrit by GerritCodeReview.
the class GerritServer method init.
/**
* Initializes on-disk site but does not start server.
*
* @param desc server description
* @param baseConfig default config values; merged with config from {@code desc} and then written
* into {@code site/etc/gerrit.config}.
* @param site temp directory where site will live.
*/
public static void init(Description desc, Config baseConfig, Path site) throws Exception {
checkArgument(!desc.memory(), "can't initialize site path for in-memory test: %s", desc);
Config cfg = desc.buildConfig(baseConfig);
Map<String, Config> pluginConfigs = desc.buildPluginConfigs();
MergeableFileBasedConfig gerritConfig = new MergeableFileBasedConfig(site.resolve("etc").resolve("gerrit.config").toFile(), FS.DETECTED);
gerritConfig.load();
gerritConfig.merge(cfg);
mergeTestConfig(gerritConfig);
String configuredIndexBackend = cfg.getString("index", null, "type");
if (configuredIndexBackend == null) {
// Propagate index type to pgms that run off of the gerrit.config file on local disk.
IndexType indexType = IndexType.fromEnvironment().orElse(new IndexType("fake"));
gerritConfig.setString("index", null, "type", indexType.isLucene() ? "lucene" : "fake");
}
gerritConfig.save();
Init init = new Init();
int rc = init.main(new String[] { "-d", site.toString(), "--batch", "--no-auto-start", "--skip-plugins" });
if (rc != 0) {
throw new RuntimeException("Couldn't initialize site");
}
for (String pluginName : pluginConfigs.keySet()) {
MergeableFileBasedConfig pluginCfg = new MergeableFileBasedConfig(site.resolve("etc").resolve(pluginName + ".config").toFile(), FS.DETECTED);
pluginCfg.load();
pluginCfg.merge(pluginConfigs.get(pluginName));
pluginCfg.save();
}
}
Aggregations