Search in sources :

Example 11 with FactoryModule

use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.

the class GerritServer method createTestInjector.

private static Injector createTestInjector(Daemon daemon) throws Exception {
    Injector sysInjector = getInjector(daemon, "sysInjector");
    Module module = new FactoryModule() {

        @Override
        protected void configure() {
            bindConstant().annotatedWith(SshEnabled.class).to(daemon.getEnableSshd());
            bind(AccountCreator.class);
            bind(AccountOperations.class).to(AccountOperationsImpl.class);
            bind(GroupOperations.class).to(GroupOperationsImpl.class);
            bind(ProjectOperations.class).to(ProjectOperationsImpl.class);
            bind(RequestScopeOperations.class).to(RequestScopeOperationsImpl.class);
            bind(ChangeOperations.class).to(ChangeOperationsImpl.class);
            factory(PerPatchsetOperationsImpl.Factory.class);
            factory(PerCommentOperationsImpl.Factory.class);
            factory(PerDraftCommentOperationsImpl.Factory.class);
            factory(PerRobotCommentOperationsImpl.Factory.class);
            factory(PushOneCommit.Factory.class);
            install(InProcessProtocol.module());
            install(new NoSshModule());
            install(new AsyncReceiveCommitsModule());
            factory(ProjectResetter.Builder.Factory.class);
        }

        @Provides
        @Singleton
        @Nullable
        @TestSshServerAddress
        InetSocketAddress getSshAddress(@GerritServerConfig Config cfg) {
            String addr = cfg.getString("sshd", null, "listenAddress");
            // We do not use InitSshd.isOff to avoid coupling GerritServer to the SSH code.
            return !"off".equalsIgnoreCase(addr) ? SocketUtil.resolve(cfg.getString("sshd", null, "listenAddress"), 0) : null;
        }
    };
    return sysInjector.createChildInjector(module);
}
Also used : AccountOperations(com.google.gerrit.acceptance.testsuite.account.AccountOperations) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) 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) AsyncReceiveCommitsModule(com.google.gerrit.server.git.receive.AsyncReceiveCommits.AsyncReceiveCommitsModule) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) PerPatchsetOperationsImpl(com.google.gerrit.acceptance.testsuite.change.PerPatchsetOperationsImpl) PerDraftCommentOperationsImpl(com.google.gerrit.acceptance.testsuite.change.PerDraftCommentOperationsImpl) PerCommentOperationsImpl(com.google.gerrit.acceptance.testsuite.change.PerCommentOperationsImpl) GroupOperations(com.google.gerrit.acceptance.testsuite.group.GroupOperations) Injector(com.google.inject.Injector) PerRobotCommentOperationsImpl(com.google.gerrit.acceptance.testsuite.change.PerRobotCommentOperationsImpl) Module(com.google.inject.Module) FakeIndexModule(com.google.gerrit.index.testing.FakeIndexModule) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) ReindexProjectsAtStartupModule(com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) FakeEmailSenderModule(com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule) ReindexGroupsAtStartupModule(com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule) FakeGroupAuditServiceModule(com.google.gerrit.acceptance.FakeGroupAuditService.FakeGroupAuditServiceModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) AsyncReceiveCommitsModule(com.google.gerrit.server.git.receive.AsyncReceiveCommits.AsyncReceiveCommitsModule) AbstractModule(com.google.inject.AbstractModule) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)

Example 12 with FactoryModule

use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.

the class LocalUsernamesToLowerCase method run.

@Override
public int run() throws Exception {
    Injector dbInjector = createDbInjector();
    manager.add(dbInjector, dbInjector.createChildInjector(NoteDbSchemaVersionCheck.module()));
    manager.start();
    dbInjector.createChildInjector(new FactoryModule() {

        @Override
        protected void configure() {
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
            factory(MetaDataUpdate.InternalFactory.class);
            // The LocalUsernamesToLowerCase program needs to access all external IDs only
            // once to update them. After the update they are not accessed again. Hence the
            // LocalUsernamesToLowerCase program doesn't benefit from caching external IDs and
            // the external ID cache can be disabled.
            install(DisabledExternalIdCache.module());
        }
    }).injectMembers(this);
    Collection<ExternalId> todo = externalIds.all();
    monitor.beginTask("Converting local usernames", todo.size());
    try (Repository repo = repoManager.openRepository(allUsersName)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(repo);
        for (ExternalId extId : todo) {
            convertLocalUserToLowerCase(extIdNotes, extId);
            monitor.update(1);
        }
        try (MetaDataUpdate metaDataUpdate = metaDataUpdateServerFactory.get().create(allUsersName)) {
            metaDataUpdate.setMessage("Convert local usernames to lower case");
            extIdNotes.commit(metaDataUpdate);
        }
    }
    monitor.endTask();
    int exitCode = reindexAccounts();
    manager.stop();
    return exitCode;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Injector(com.google.inject.Injector) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 13 with FactoryModule

use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.

the class Rulec method run.

@Override
public int run() throws Exception {
    dbInjector = createDbInjector();
    manager.add(dbInjector);
    manager.start();
    dbInjector.createChildInjector(new FactoryModule() {

        @Override
        protected void configure() {
            factory(PrologCompiler.Factory.class);
        }
    }).injectMembers(this);
    LinkedHashSet<Project.NameKey> names = new LinkedHashSet<>();
    for (String name : projectNames) {
        names.add(Project.nameKey(name));
    }
    if (all) {
        names.addAll(gitManager.list());
    }
    boolean error = false;
    for (Project.NameKey project : names) {
        try (Repository git = gitManager.openRepository(project)) {
            switch(jarFactory.create(git).call()) {
                case NO_RULES:
                    if (!all || projectNames.contains(project.get())) {
                        System.err.println("error: No rules.pl in " + project.get());
                        error = true;
                    }
                    break;
                case COMPILED:
                    if (!quiet) {
                        System.out.format("Compiled %-60s ... SUCCESS", project.get());
                        System.out.println();
                    }
                    break;
            }
        } catch (CompileException err) {
            if (showStackTrace) {
                err.printStackTrace();
            } else {
                System.err.println("fatal: " + err.getMessage());
            }
            error = true;
        }
    }
    return !error ? 0 : 1;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) CompileException(com.googlecode.prolog_cafe.exceptions.CompileException) PrologCompiler(com.google.gerrit.pgm.rules.PrologCompiler)

Example 14 with FactoryModule

use of com.google.gerrit.extensions.config.FactoryModule in project gerrit by GerritCodeReview.

the class ReceiveCommitsCommentValidationIT method createModule.

@Override
public Module createModule() {
    return new FactoryModule() {

        @Override
        public void configure() {
            CommentValidator mockCommentValidator = mock(CommentValidator.class);
            bind(CommentValidator.class).annotatedWith(Exports.named(mockCommentValidator.getClass())).toInstance(mockCommentValidator);
            bind(CommentValidator.class).toInstance(mockCommentValidator);
        }
    };
}
Also used : CommentValidator(com.google.gerrit.extensions.validators.CommentValidator) FactoryModule(com.google.gerrit.extensions.config.FactoryModule)

Aggregations

FactoryModule (com.google.gerrit.extensions.config.FactoryModule)14 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)5 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)4 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)4 PersonIdent (org.eclipse.jgit.lib.PersonIdent)4 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)3 Repository (org.eclipse.jgit.lib.Repository)3 CommentValidator (com.google.gerrit.extensions.validators.CommentValidator)2 LuceneIndexModule (com.google.gerrit.lucene.LuceneIndexModule)2 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)2 MetricMaker (com.google.gerrit.metrics.MetricMaker)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 CurrentUser (com.google.gerrit.server.CurrentUser)2 InternalUser (com.google.gerrit.server.InternalUser)2 AccountCache (com.google.gerrit.server.account.AccountCache)2 FakeRealm (com.google.gerrit.server.account.FakeRealm)2 Realm (com.google.gerrit.server.account.Realm)2 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)2