Search in sources :

Example 1 with Init

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;
}
Also used : Init(com.google.gerrit.pgm.Init) File(java.io.File)

Example 2 with Init

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();
    }
}
Also used : Init(com.google.gerrit.pgm.Init) Config(org.eclipse.jgit.lib.Config) GlobalPluginConfig(com.google.gerrit.acceptance.config.GlobalPluginConfig) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) IndexType(com.google.gerrit.index.IndexType)

Aggregations

Init (com.google.gerrit.pgm.Init)2 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 GlobalPluginConfig (com.google.gerrit.acceptance.config.GlobalPluginConfig)1 IndexType (com.google.gerrit.index.IndexType)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 File (java.io.File)1 Config (org.eclipse.jgit.lib.Config)1