Search in sources :

Example 6 with GerritOptions

use of com.google.gerrit.server.config.GerritOptions in project gerrit by GerritCodeReview.

the class InMemoryModule method configure.

@Override
protected void configure() {
    // Do NOT bind @RemotePeer, as it is bound in a child injector of
    // ChangeMergeQueue (bound via GerritGlobalModule below), so there cannot be
    // a binding in the parent injector. If you need @RemotePeer, you must bind
    // it in a child injector of the one containing InMemoryModule. But unless
    // you really need to test something request-scoped, you likely don't
    // actually need it.
    // For simplicity, don't create child injectors, just use this one to get a
    // few required modules.
    Injector cfgInjector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
        }
    });
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    install(cfgInjector.getInstance(GerritGlobalModule.class));
    install(new DefaultPermissionBackendModule());
    install(new SearchingChangeCacheImpl.Module());
    factory(GarbageCollection.Factory.class);
    bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
    // TODO(dborowitz): Use jimfs.
    bind(Path.class).annotatedWith(SitePath.class).toInstance(Paths.get("."));
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GerritOptions.class).toInstance(new GerritOptions(cfg, false, false, false));
    bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
    bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
    bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
    bind(AllProjectsName.class).toProvider(AllProjectsNameProvider.class);
    bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    bind(NotesMigration.class).toInstance(notesMigration);
    bind(ListeningExecutorService.class).annotatedWith(ChangeUpdateExecutor.class).toInstance(MoreExecutors.newDirectExecutorService());
    bind(DataSourceType.class).to(InMemoryH2Type.class);
    bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
    bind(SecureStore.class).to(DefaultSecureStore.class);
    TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
    };
    bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
    bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
    install(NoSshKeyCache.module());
    install(new CanonicalWebUrlModule() {

        @Override
        protected Class<? extends Provider<String>> provider() {
            return CanonicalWebUrlProvider.class;
        }
    });
    //Replacement of DiffExecutorModule to not use thread pool in the tests
    install(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        @DiffExecutor
        public ExecutorService createDiffExecutor() {
            return MoreExecutors.newDirectExecutorService();
        }
    });
    install(new DefaultCacheFactory.Module());
    install(new FakeEmailSender.Module());
    install(new SignedTokenEmailTokenVerifier.Module());
    install(new GpgModule(cfg));
    install(new H2AccountPatchReviewStore.InMemoryModule());
    bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
    bind(AllChangesIndexer.class).toProvider(Providers.of(null));
    bind(AllGroupsIndexer.class).toProvider(Providers.of(null));
    IndexType indexType = null;
    try {
        indexType = cfg.getEnum("index", null, "type", IndexType.LUCENE);
    } catch (IllegalArgumentException e) {
    // Custom index type, caller must provide their own module.
    }
    if (indexType != null) {
        switch(indexType) {
            case LUCENE:
                install(luceneIndexModule());
                break;
            case ELASTICSEARCH:
                install(elasticIndexModule());
                break;
            default:
                throw new ProvisionException("index type unsupported in tests: " + indexType);
        }
    }
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) GerritServerId(com.google.gerrit.server.config.GerritServerId) GwtormChangeBundleReader(com.google.gerrit.server.notedb.GwtormChangeBundleReader) ChangeBundleReader(com.google.gerrit.server.notedb.ChangeBundleReader) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) NotesMigrationSchemaFactory(com.google.gerrit.server.schema.NotesMigrationSchemaFactory) SchemaFactory(com.google.gwtorm.server.SchemaFactory) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) GerritOptions(com.google.gerrit.server.config.GerritOptions) SecureStore(com.google.gerrit.server.securestore.SecureStore) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore) ChangeUpdateExecutor(com.google.gerrit.server.update.ChangeUpdateExecutor) Singleton(com.google.inject.Singleton) SitePath(com.google.gerrit.server.config.SitePath) DiffExecutor(com.google.gerrit.server.patch.DiffExecutor) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AllChangesIndexer(com.google.gerrit.server.index.change.AllChangesIndexer) GarbageCollection(com.google.gerrit.server.git.GarbageCollection) AllAccountsIndexer(com.google.gerrit.server.index.account.AllAccountsIndexer) SignedTokenEmailTokenVerifier(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) GpgModule(com.google.gerrit.gpg.GpgModule) IndexType(com.google.gerrit.server.index.IndexModule.IndexType) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Provides(com.google.inject.Provides) H2AccountPatchReviewStore(com.google.gerrit.server.schema.H2AccountPatchReviewStore) AbstractModule(com.google.inject.AbstractModule) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Provider(com.google.inject.Provider) AllGroupsIndexer(com.google.gerrit.server.index.group.AllGroupsIndexer) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AllUsersName(com.google.gerrit.server.config.AllUsersName)

Example 7 with GerritOptions

use of com.google.gerrit.server.config.GerritOptions in project gerrit by GerritCodeReview.

the class WebAppInitializer method createWebInjector.

private Injector createWebInjector() {
    final List<Module> modules = new ArrayList<>();
    modules.add(RequestContextFilter.module());
    modules.add(RequestMetricsFilter.module());
    modules.add(sysInjector.getInstance(GerritAuthModule.class));
    modules.add(sysInjector.getInstance(GitOverHttpModule.class));
    modules.add(sysInjector.getInstance(HttpdModule.class));
    modules.add(RequestCleanupFilter.module());
    modules.add(SetThreadNameFilter.module());
    modules.add(AllRequestFilter.module());
    modules.add(sysInjector.getInstance(WebModule.class));
    modules.add(sysInjector.getInstance(RequireSslFilterModule.class));
    if (sshInjector != null) {
        modules.add(sshInjector.getInstance(WebSshGlueModule.class));
    } else {
        modules.add(new NoSshModule());
    }
    modules.add(H2CacheBasedWebSession.module());
    modules.add(new HttpPluginModule());
    AuthConfig authConfig = cfgInjector.getInstance(AuthConfig.class);
    if (authConfig.getAuthType() == AuthType.OPENID) {
        modules.add(new OpenIdModule());
    } else if (authConfig.getAuthType() == AuthType.OAUTH) {
        modules.add(new OAuthModule());
    }
    modules.add(new AuthModule(authConfig));
    modules.add(sysInjector.getInstance(GetUserFilter.GetUserFilterModule.class));
    // StaticModule contains a "/*" wildcard, place it last.
    GerritOptions opts = sysInjector.getInstance(GerritOptions.class);
    if (opts.enableMasterFeatures()) {
        modules.add(sysInjector.getInstance(StaticModule.class));
    }
    return sysInjector.createChildInjector(modules);
}
Also used : OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) OpenIdModule(com.google.gerrit.httpd.auth.openid.OpenIdModule) GitOverHttpModule(com.google.gerrit.httpd.GitOverHttpModule) GerritOptions(com.google.gerrit.server.config.GerritOptions) ArrayList(java.util.ArrayList) WebModule(com.google.gerrit.httpd.WebModule) AuthConfig(com.google.gerrit.server.config.AuthConfig) GerritAuthModule(com.google.gerrit.httpd.GerritAuthModule) HttpPluginModule(com.google.gerrit.httpd.plugins.HttpPluginModule) HttpdModule(com.google.gerrit.httpd.HttpdModule) RequireSslFilterModule(com.google.gerrit.httpd.RequireSslFilter.RequireSslFilterModule) OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) AuthModule(com.google.gerrit.auth.AuthModule) GerritAuthModule(com.google.gerrit.httpd.GerritAuthModule) SubscriptionGraphModule(com.google.gerrit.server.submit.SubscriptionGraph.SubscriptionGraphModule) H2CacheModule(com.google.gerrit.server.cache.h2.H2CacheModule) PluginApiModule(com.google.gerrit.server.api.PluginApiModule) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) InternalAccountDirectoryModule(com.google.gerrit.server.account.InternalAccountDirectory.InternalAccountDirectoryModule) WorkQueueModule(com.google.gerrit.server.git.WorkQueue.WorkQueueModule) SshModule(com.google.gerrit.sshd.SshModule) DefaultPermissionBackendModule(com.google.gerrit.server.permissions.DefaultPermissionBackendModule) ChangeCleanupRunnerModule(com.google.gerrit.server.change.ChangeCleanupRunner.ChangeCleanupRunnerModule) SshAddressesModule(com.google.gerrit.server.ssh.SshAddressesModule) DefaultMemoryCacheModule(com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule) HttpPluginModule(com.google.gerrit.httpd.plugins.HttpPluginModule) DefaultCommandModule(com.google.gerrit.sshd.commands.DefaultCommandModule) WebModule(com.google.gerrit.httpd.WebModule) SmtpEmailSenderModule(com.google.gerrit.server.mail.send.SmtpEmailSender.SmtpEmailSenderModule) StreamEventsApiListenerModule(com.google.gerrit.server.events.StreamEventsApiListener.StreamEventsApiListenerModule) PluginModule(com.google.gerrit.server.plugins.PluginModule) IndexModule(com.google.gerrit.server.index.IndexModule) StaticModule(com.google.gerrit.httpd.raw.StaticModule) AccountDeactivatorModule(com.google.gerrit.server.account.AccountDeactivator.AccountDeactivatorModule) HttpdModule(com.google.gerrit.httpd.HttpdModule) LocalMergeSuperSetComputationModule(com.google.gerrit.server.submit.LocalMergeSuperSetComputation.LocalMergeSuperSetComputationModule) JdbcAccountPatchReviewStoreModule(com.google.gerrit.server.schema.JdbcAccountPatchReviewStore.JdbcAccountPatchReviewStoreModule) SearchingChangeCacheImplModule(com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule) GpgModule(com.google.gerrit.gpg.GpgModule) OpenIdModule(com.google.gerrit.httpd.auth.openid.OpenIdModule) AuthModule(com.google.gerrit.auth.AuthModule) SshHostKeyModule(com.google.gerrit.sshd.SshHostKeyModule) DefaultProjectNameLockManagerModule(com.google.gerrit.server.project.DefaultProjectNameLockManager.DefaultProjectNameLockManagerModule) OAuthRestModule(com.google.gerrit.httpd.auth.restapi.OAuthRestModule) SignedTokenEmailTokenVerifierModule(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier.SignedTokenEmailTokenVerifierModule) AbstractModule(com.google.inject.AbstractModule) GitRepositoryManagerModule(com.google.gerrit.server.git.GitRepositoryManagerModule) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) SequenceCommandsModule(com.google.gerrit.sshd.commands.SequenceCommandsModule) Module(com.google.inject.Module) DefaultUrlFormatterModule(com.google.gerrit.server.config.DefaultUrlFormatter.DefaultUrlFormatterModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) LfsPluginAuthCommandModule(com.google.gerrit.sshd.plugin.LfsPluginAuthCommand.LfsPluginAuthCommandModule) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) SchemaModule(com.google.gerrit.server.schema.SchemaModule) MimeUtil2Module(com.google.gerrit.server.mime.MimeUtil2Module) SysExecutorModule(com.google.gerrit.server.config.SysExecutorModule) GarbageCollectionModule(com.google.gerrit.server.git.GarbageCollectionModule) GerritAuthModule(com.google.gerrit.httpd.GerritAuthModule) WebSshGlueModule(com.google.gerrit.httpd.WebSshGlueModule) MailReceiverModule(com.google.gerrit.server.mail.receive.MailReceiver.MailReceiverModule) ExternalIdCommandsModule(com.google.gerrit.sshd.commands.ExternalIdCommandsModule) RequireSslFilterModule(com.google.gerrit.httpd.RequireSslFilter.RequireSslFilterModule) GerritServerConfigModule(com.google.gerrit.server.config.GerritServerConfigModule) OnlineUpgraderModule(com.google.gerrit.server.index.OnlineUpgrader.OnlineUpgraderModule) AuditModule(com.google.gerrit.server.audit.AuditModule) GitOverHttpModule(com.google.gerrit.httpd.GitOverHttpModule) RestApiModule(com.google.gerrit.server.restapi.RestApiModule) LogFileCompressorModule(com.google.gerrit.pgm.util.LogFileCompressor.LogFileCompressorModule) SuperprojectUpdateSubmissionListenerModule(com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener.SuperprojectUpdateSubmissionListenerModule) IndexCommandsModule(com.google.gerrit.sshd.commands.IndexCommandsModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) EventBrokerModule(com.google.gerrit.server.events.EventBroker.EventBrokerModule) StartupChecksModule(com.google.gerrit.server.StartupChecks.StartupChecksModule) GerritApiModule(com.google.gerrit.server.api.GerritApiModule) GerritInstanceNameModule(com.google.gerrit.server.config.GerritInstanceNameModule) WebSshGlueModule(com.google.gerrit.httpd.WebSshGlueModule) StaticModule(com.google.gerrit.httpd.raw.StaticModule)

Aggregations

GpgModule (com.google.gerrit.gpg.GpgModule)7 CanonicalWebUrlModule (com.google.gerrit.server.config.CanonicalWebUrlModule)7 GerritGlobalModule (com.google.gerrit.server.config.GerritGlobalModule)7 GerritOptions (com.google.gerrit.server.config.GerritOptions)7 AbstractModule (com.google.inject.AbstractModule)7 AuthModule (com.google.gerrit.auth.AuthModule)5 OAuthModule (com.google.gerrit.httpd.auth.oauth.OAuthModule)5 OpenIdModule (com.google.gerrit.httpd.auth.openid.OpenIdModule)5 HttpPluginModule (com.google.gerrit.httpd.plugins.HttpPluginModule)5 StaticModule (com.google.gerrit.httpd.raw.StaticModule)5 LuceneIndexModule (com.google.gerrit.lucene.LuceneIndexModule)5 AuthConfigModule (com.google.gerrit.server.config.AuthConfigModule)5 GerritAuthModule (com.google.gerrit.httpd.GerritAuthModule)4 GitOverHttpModule (com.google.gerrit.httpd.GitOverHttpModule)4 HttpdModule (com.google.gerrit.httpd.HttpdModule)4 RequireSslFilterModule (com.google.gerrit.httpd.RequireSslFilter.RequireSslFilterModule)4 OAuthRestModule (com.google.gerrit.httpd.auth.restapi.OAuthRestModule)4 GerritApiModule (com.google.gerrit.server.api.GerritApiModule)4 PluginApiModule (com.google.gerrit.server.api.PluginApiModule)4 AuditModule (com.google.gerrit.server.audit.AuditModule)4