Hoist ContactStore configurtion out of WebModule

Move this up into Daemon and WebAppInitializer. This allows
gerrit-review to trivially bind its own ContactStore instead
of relying on SitePaths for the GPG key.

Change-Id: Ib71e073680657980ff2e4f6ba339b99127151e35
This commit is contained in:
Shawn Pearce 2014-12-05 15:45:02 -08:00
parent beaee2acf7
commit 9c12c4fe2f
5 changed files with 16 additions and 23 deletions

View File

@ -32,8 +32,6 @@ import com.google.gerrit.server.RemotePeer;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.GerritRequestModule;
import com.google.gerrit.server.contact.ContactStore;
import com.google.gerrit.server.contact.ContactStoreProvider;
import com.google.gerrit.server.git.AsyncReceiveCommits;
import com.google.gerrit.server.util.GuiceRequestScopePropagator;
import com.google.gerrit.server.util.RequestScopePropagator;
@ -95,8 +93,6 @@ public class WebModule extends LifecycleModule {
install(new GitWebModule());
}
bind(ContactStore.class).toProvider(ContactStoreProvider.class).in(
SINGLETON);
bind(GerritConfigProvider.class);
bind(GerritConfig.class).toProvider(GerritConfigProvider.class);
DynamicSet.setOf(binder(), WebUiPlugin.class);

View File

@ -51,6 +51,7 @@ import com.google.gerrit.server.config.GerritGlobalModule;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.MasterNodeStartup;
import com.google.gerrit.server.config.RestCacheAdminModule;
import com.google.gerrit.server.contact.ContactStoreModule;
import com.google.gerrit.server.contact.HttpContactStoreConnection;
import com.google.gerrit.server.git.GarbageCollectionRunner;
import com.google.gerrit.server.git.ReceiveCommitsExecutorModule;
@ -419,6 +420,7 @@ public class Daemon extends SiteProgram {
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
modules.add(sysInjector.getInstance(WebModule.class));
modules.add(new HttpPluginModule());
modules.add(new ContactStoreModule());
if (sshd) {
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
} else {

View File

@ -14,12 +14,13 @@
package com.google.gerrit.server.contact;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.ProvisionException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@ -35,24 +36,16 @@ import java.net.URL;
import java.security.Security;
/** Creates the {@link ContactStore} based on the configuration. */
public class ContactStoreProvider implements Provider<ContactStore> {
private final Config config;
private final SitePaths site;
private final SchemaFactory<ReviewDb> schema;
private final ContactStoreConnection.Factory connFactory;
@Inject
ContactStoreProvider(@GerritServerConfig final Config config,
final SitePaths site, final SchemaFactory<ReviewDb> schema,
final ContactStoreConnection.Factory connFactory) {
this.config = config;
this.site = site;
this.schema = schema;
this.connFactory = connFactory;
public class ContactStoreModule extends AbstractModule {
@Override
protected void configure() {
}
@Override
public ContactStore get() {
@Nullable
@Provides
public ContactStore provideContactStore(@GerritServerConfig final Config config,
final SitePaths site, final SchemaFactory<ReviewDb> schema,
final ContactStoreConnection.Factory connFactory) {
final String url = config.getString("contactstore", null, "url");
if (StringUtils.isEmptyOrNull(url)) {
return new NoContactStore();

View File

@ -18,7 +18,7 @@ import com.google.gerrit.common.errors.ContactInformationStoreException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.ContactInformation;
class NoContactStore implements ContactStore {
public class NoContactStore implements ContactStore {
@Override
public boolean isEnabled() {
return false;

View File

@ -36,6 +36,7 @@ import com.google.gerrit.server.config.GerritServerConfigModule;
import com.google.gerrit.server.config.MasterNodeStartup;
import com.google.gerrit.server.config.RestCacheAdminModule;
import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.contact.ContactStoreModule;
import com.google.gerrit.server.contact.HttpContactStoreConnection;
import com.google.gerrit.server.git.GarbageCollectionRunner;
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
@ -337,6 +338,7 @@ public class WebAppInitializer extends GuiceServletContextListener
modules.add(H2CacheBasedWebSession.module());
modules.add(HttpContactStoreConnection.module());
modules.add(new HttpPluginModule());
modules.add(new ContactStoreModule());
AuthConfig authConfig = cfgInjector.getInstance(AuthConfig.class);
if (authConfig.getAuthType() == AuthType.OPENID) {