Search in sources :

Example 6 with FactoryModule

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

the class PostReviewIT 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)

Example 7 with FactoryModule

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

the class TestChanges method newUpdate.

public static ChangeUpdate newUpdate(Injector injector, Change c, CurrentUser user, boolean shouldExist) throws Exception {
    injector = injector.createChildInjector(new FactoryModule() {

        @Override
        public void configure() {
            bind(CurrentUser.class).toInstance(user);
        }
    });
    ChangeUpdate update = injector.getInstance(ChangeUpdate.Factory.class).create(new ChangeNotes(injector.getInstance(AbstractChangeNotes.Args.class), c, shouldExist, null).load(), user, TimeUtil.now(), Ordering.natural());
    ChangeNotes notes = update.getNotes();
    boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
    if (hasPatchSets) {
        return update;
    }
    // Change doesn't exist yet. NoteDb requires that there be a commit for the
    // first patch set, so create one.
    GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(c.getProject());
        TestRepository<Repository> tr = new TestRepository<>(repo)) {
        PersonIdent ident = user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
        TestRepository<Repository>.CommitBuilder cb = tr.commit().author(ident).committer(ident).message(firstNonNull(c.getSubject(), "Test change"));
        Ref parent = repo.exactRef(c.getDest().branch());
        if (parent != null) {
            cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
        }
        update.setBranch(c.getDest().branch());
        update.setChangeId(c.getKey().get());
        update.setCommit(tr.getRevWalk(), cb.create());
        return update;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) CurrentUser(com.google.gerrit.server.CurrentUser) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 8 with FactoryModule

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

the class ProjectModule method configureServlets.

@Override
protected void configureServlets() {
    install(new FactoryModule() {

        @Override
        protected void configure() {
            factory(ChangeProjectAccess.Factory.class);
            factory(ReviewProjectAccess.Factory.class);
            factory(ProjectAccessFactory.Factory.class);
        }
    });
    rpc(ProjectAdminServiceImpl.class);
}
Also used : FactoryModule(com.google.gerrit.extensions.config.FactoryModule)

Example 9 with FactoryModule

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

the class AbstractChangeNotesTest method setUp.

@Before
public void setUp() throws Exception {
    setTimeForTesting();
    serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
    project = new Project.NameKey("test-project");
    repoManager = new InMemoryRepositoryManager();
    repo = repoManager.createRepository(project);
    tr = new TestRepository<>(repo);
    rw = tr.getRevWalk();
    accountCache = new FakeAccountCache();
    Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
    co.setFullName("Change Owner");
    co.setPreferredEmail("change@owner.com");
    accountCache.put(co);
    Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
    ou.setFullName("Other Account");
    ou.setPreferredEmail("other@account.com");
    accountCache.put(ou);
    injector = Guice.createInjector(new FactoryModule() {

        @Override
        public void configure() {
            install(new GitModule());
            install(NoteDbModule.forTest(testConfig));
            bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
            bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
            bind(NotesMigration.class).toInstance(MIGRATION);
            bind(GitRepositoryManager.class).toInstance(repoManager);
            bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
            bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(testConfig);
            bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
            bind(Realm.class).to(FakeRealm.class);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(AccountCache.class).toInstance(accountCache);
            bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
            bind(MetricMaker.class).to(DisabledMetricMaker.class);
            bind(ReviewDb.class).toProvider(Providers.<ReviewDb>of(null));
        }
    });
    injector.injectMembers(this);
    repoManager.createRepository(allUsers);
    changeOwner = userFactory.create(co.getId());
    otherUser = userFactory.create(ou.getId());
    otherUserId = otherUser.getAccountId();
    internalUser = new InternalUser(null);
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) Account(com.google.gerrit.reviewdb.client.Account) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) CapabilityControl(com.google.gerrit.server.account.CapabilityControl) InternalUser(com.google.gerrit.server.InternalUser) GerritServerId(com.google.gerrit.server.config.GerritServerId) DisableReverseDnsLookup(com.google.gerrit.server.config.DisableReverseDnsLookup) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) FakeRealm(com.google.gerrit.server.account.FakeRealm) Realm(com.google.gerrit.server.account.Realm) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) CanonicalWebUrl(com.google.gerrit.server.config.CanonicalWebUrl) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitModule(com.google.gerrit.server.git.GitModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) FakeAccountCache(com.google.gerrit.testutil.FakeAccountCache) AccountCache(com.google.gerrit.server.account.AccountCache) Project(com.google.gerrit.reviewdb.client.Project) ProjectCache(com.google.gerrit.server.project.ProjectCache) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) AllUsersName(com.google.gerrit.server.config.AllUsersName) Before(org.junit.Before)

Example 10 with FactoryModule

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

the class TestChanges method newUpdate.

public static ChangeUpdate newUpdate(Injector injector, Change c, final CurrentUser user) throws Exception {
    injector = injector.createChildInjector(new FactoryModule() {

        @Override
        public void configure() {
            bind(CurrentUser.class).toInstance(user);
        }
    });
    ChangeUpdate update = injector.getInstance(ChangeUpdate.Factory.class).create(stubChangeControl(injector.getInstance(AbstractChangeNotes.Args.class), c, user), TimeUtil.nowTs(), Ordering.<String>natural());
    ChangeNotes notes = update.getNotes();
    boolean hasPatchSets = notes.getPatchSets() != null && !notes.getPatchSets().isEmpty();
    NotesMigration migration = injector.getInstance(NotesMigration.class);
    if (hasPatchSets || !migration.readChanges()) {
        return update;
    }
    // Change doesn't exist yet. NoteDb requires that there be a commit for the
    // first patch set, so create one.
    GitRepositoryManager repoManager = injector.getInstance(GitRepositoryManager.class);
    try (Repository repo = repoManager.openRepository(c.getProject())) {
        TestRepository<Repository> tr = new TestRepository<>(repo);
        PersonIdent ident = user.asIdentifiedUser().newCommitterIdent(update.getWhen(), TimeZone.getDefault());
        TestRepository<Repository>.CommitBuilder<Repository> cb = tr.commit().author(ident).committer(ident).message(firstNonNull(c.getSubject(), "Test change"));
        Ref parent = repo.exactRef(c.getDest().get());
        if (parent != null) {
            cb.parent(tr.getRevWalk().parseCommit(parent.getObjectId()));
        }
        update.setBranch(c.getDest().get());
        update.setChangeId(c.getKey().get());
        update.setCommit(tr.getRevWalk(), cb.create());
        return update;
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) CurrentUser(com.google.gerrit.server.CurrentUser) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes) ChangeUpdate(com.google.gerrit.server.notedb.ChangeUpdate) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

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