Remove excessive injection stack from InitIndex
All this class needs to do is mark an empty index as ready. Factor out a small static method to do this work. Change-Id: Id0bcef9cb7e5a6879288ed4716ea45fb6539f07c
This commit is contained in:
parent
5ac379ca64
commit
fc9d9628cd
@ -134,6 +134,18 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
LUCENE_VERSIONS = versions.build();
|
||||
}
|
||||
|
||||
public static void setReady(SitePaths sitePaths, int version, boolean ready)
|
||||
throws IOException {
|
||||
try {
|
||||
FileBasedConfig cfg =
|
||||
LuceneVersionManager.loadGerritIndexConfig(sitePaths);
|
||||
LuceneVersionManager.setReady(cfg, version, ready);
|
||||
cfg.save();
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static interface Factory {
|
||||
LuceneChangeIndex create(Schema<ChangeData> schema, String base);
|
||||
}
|
||||
@ -304,13 +316,7 @@ public class LuceneChangeIndex implements ChangeIndex {
|
||||
|
||||
@Override
|
||||
public void markReady(boolean ready) throws IOException {
|
||||
try {
|
||||
FileBasedConfig cfg = LuceneVersionManager.loadGerritIndexConfig(sitePaths);
|
||||
LuceneVersionManager.setReady(cfg, schema.getVersion(), ready);
|
||||
cfg.save();
|
||||
} catch (ConfigInvalidException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
setReady(sitePaths, schema.getVersion(), ready);
|
||||
}
|
||||
|
||||
private static final ImmutableSet<String> FIELDS =
|
||||
|
@ -14,47 +14,15 @@
|
||||
|
||||
package com.google.gerrit.pgm.init;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.lucene.LuceneChangeIndex;
|
||||
import com.google.gerrit.lucene.LuceneIndexModule;
|
||||
import com.google.gerrit.pgm.util.ConsoleUI;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.Project.NameKey;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.config.FactoryModule;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.config.TrackingFooter;
|
||||
import com.google.gerrit.server.config.TrackingFooters;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.index.ChangeIndex;
|
||||
import com.google.gerrit.server.index.ChangeSchemas;
|
||||
import com.google.gerrit.server.index.IndexModule.IndexType;
|
||||
import com.google.gerrit.server.patch.IntraLineDiff;
|
||||
import com.google.gerrit.server.patch.IntraLineDiffKey;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.gerrit.server.patch.PatchListCache;
|
||||
import com.google.gerrit.server.patch.PatchListKey;
|
||||
import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.SortedSet;
|
||||
|
||||
/** Initialize the {@code index} configuration section. */
|
||||
@Singleton
|
||||
@ -80,7 +48,8 @@ class InitIndex implements InitStep {
|
||||
|
||||
IndexType type = index.select("Type", "type", IndexType.LUCENE);
|
||||
if (site.isNew && type == IndexType.LUCENE) {
|
||||
createLuceneIndex();
|
||||
LuceneChangeIndex.setReady(
|
||||
site, ChangeSchemas.getLatest().getVersion(), true);
|
||||
} else {
|
||||
ui.message("The index must be built before starting Gerrit:\n"
|
||||
+ " java -jar gerrit.war reindex -d site_path\n");
|
||||
@ -88,96 +57,6 @@ class InitIndex implements InitStep {
|
||||
}
|
||||
}
|
||||
|
||||
private void createLuceneIndex() throws IOException {
|
||||
Injector injector = Guice.createInjector(
|
||||
new LuceneIndexModule(ChangeSchemas.getLatest().getVersion(), 0, null),
|
||||
new MockIndexSupportModule());
|
||||
|
||||
ChangeIndex index = injector.getInstance(LuceneChangeIndex.class);
|
||||
index.markReady(true);
|
||||
index.close();
|
||||
}
|
||||
|
||||
private class MockIndexSupportModule extends FactoryModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(SitePaths.class).toInstance(site);
|
||||
factory(ChangeData.Factory.class);
|
||||
}
|
||||
|
||||
@Provides @GerritServerConfig Config getConfig() {
|
||||
return new Config();
|
||||
}
|
||||
|
||||
@Provides TrackingFooters newTrackingFooters() {
|
||||
return new TrackingFooters(Collections.<TrackingFooter> emptyList());
|
||||
}
|
||||
|
||||
@Provides ReviewDb getReviewDb() {
|
||||
throw new ProvisionException("database not initialized");
|
||||
}
|
||||
|
||||
@Provides SchemaFactory<ReviewDb> getSchemaFactory() {
|
||||
return new SchemaFactory<ReviewDb>() {
|
||||
@Override
|
||||
public ReviewDb open() throws OrmException {
|
||||
return getReviewDb();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides GitRepositoryManager getGitRepositoryManager() {
|
||||
return new GitRepositoryManager() {
|
||||
@Override
|
||||
public Repository openRepository(Project.NameKey name)
|
||||
throws RepositoryNotFoundException{
|
||||
throw new RepositoryNotFoundException(name.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository createRepository(Project.NameKey name)
|
||||
throws RepositoryNotFoundException {
|
||||
throw new RepositoryNotFoundException(name.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedSet<Project.NameKey> list() {
|
||||
return Sets.newTreeSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectDescription(Project.NameKey name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProjectDescription(NameKey name, String description) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides PatchListCache newPatchListCache() {
|
||||
return new PatchListCache() {
|
||||
@Override
|
||||
public PatchList get(PatchListKey key)
|
||||
throws PatchListNotAvailableException {
|
||||
throw new PatchListNotAvailableException("new site, no changes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PatchList get(Change change, PatchSet patchSet)
|
||||
throws PatchListNotAvailableException {
|
||||
throw new PatchListNotAvailableException("new site, no changes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntraLineDiff getIntraLineDiff(IntraLineDiffKey key) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postRun() throws Exception {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user