Search in sources :

Example 6 with RequestContext

use of com.google.gerrit.server.util.RequestContext in project gerrit by GerritCodeReview.

the class RefControlTest method setUp.

@Before
public void setUp() throws Exception {
    repoManager = new InMemoryRepositoryManager();
    projectCache = new ProjectCache() {

        @Override
        public ProjectState getAllProjects() {
            return get(allProjectsName);
        }

        @Override
        public ProjectState getAllUsers() {
            return null;
        }

        @Override
        public ProjectState get(Project.NameKey projectName) {
            return all.get(projectName);
        }

        @Override
        public void evict(Project p) {
        }

        @Override
        public void remove(Project p) {
        }

        @Override
        public Iterable<Project.NameKey> all() {
            return Collections.emptySet();
        }

        @Override
        public Iterable<Project.NameKey> byName(String prefix) {
            return Collections.emptySet();
        }

        @Override
        public void onCreateProject(Project.NameKey newProjectName) {
        }

        @Override
        public Set<AccountGroup.UUID> guessRelevantGroupUUIDs() {
            return Collections.emptySet();
        }

        @Override
        public ProjectState checkedGet(Project.NameKey projectName) throws IOException {
            return all.get(projectName);
        }

        @Override
        public void evict(Project.NameKey p) {
        }
    };
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    try {
        Repository repo = repoManager.createRepository(allProjectsName);
        ProjectConfig allProjects = new ProjectConfig(new Project.NameKey(allProjectsName.get()));
        allProjects.load(repo);
        LabelType cr = Util.codeReview();
        allProjects.getLabelSections().put(cr.getName(), cr);
        add(allProjects);
    } catch (IOException | ConfigInvalidException e) {
        throw new RuntimeException(e);
    }
    db = schemaFactory.open();
    singleVersionListener.start();
    try {
        schemaCreator.create(db);
    } finally {
        singleVersionListener.stop();
    }
    Cache<SectionSortCache.EntryKey, SectionSortCache.EntryVal> c = CacheBuilder.newBuilder().build();
    sectionSorter = new PermissionCollection.Factory(new SectionSortCache(c));
    parent = new ProjectConfig(parentKey);
    parent.load(newRepository(parentKey));
    add(parent);
    local = new ProjectConfig(localKey);
    local.load(newRepository(localKey));
    add(local);
    local.getProject().setParentName(parentKey);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return null;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
    changeControlFactory = injector.getInstance(ChangeControl.Factory.class);
}
Also used : Set(java.util.Set) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CurrentUser(com.google.gerrit.server.CurrentUser) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) Injector(com.google.inject.Injector) LabelType(com.google.gerrit.common.data.LabelType) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RequestContext(com.google.gerrit.server.util.RequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IOException(java.io.IOException) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) Provider(com.google.inject.Provider) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) InMemoryRepositoryManager.newRepository(com.google.gerrit.testutil.InMemoryRepositoryManager.newRepository) Repository(org.eclipse.jgit.lib.Repository) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) Before(org.junit.Before)

Example 7 with RequestContext

use of com.google.gerrit.server.util.RequestContext in project gerrit by GerritCodeReview.

the class EmailReviewComments method run.

@Override
public void run() {
    RequestContext old = requestContext.setContext(this);
    try {
        CommentSender cm = commentSenderFactory.create(notes.getProjectName(), notes.getChangeId());
        cm.setFrom(user.getAccountId());
        cm.setPatchSet(patchSet, patchSetInfoFactory.get(notes.getProjectName(), patchSet));
        cm.setChangeMessage(message.getMessage(), message.getWrittenOn());
        cm.setComments(comments);
        cm.setPatchSetComment(patchSetComment);
        cm.setLabels(labels);
        cm.setNotify(notify);
        cm.setAccountsToNotify(accountsToNotify);
        cm.send();
    } catch (Exception e) {
        log.error("Cannot email comments for " + patchSet.getId(), e);
    } finally {
        requestContext.setContext(old);
        if (db != null) {
            db.close();
            db = null;
        }
    }
}
Also used : RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) CommentSender(com.google.gerrit.server.mail.send.CommentSender) OrmException(com.google.gwtorm.server.OrmException) ProvisionException(com.google.inject.ProvisionException)

Example 8 with RequestContext

use of com.google.gerrit.server.util.RequestContext in project gerrit by GerritCodeReview.

the class EmailMerge method run.

@Override
public void run() {
    RequestContext old = requestContext.setContext(this);
    try {
        MergedSender cm = mergedSenderFactory.create(project, changeId);
        if (submitter != null) {
            cm.setFrom(submitter);
        }
        cm.setNotify(notifyHandling);
        cm.setAccountsToNotify(accountsToNotify);
        cm.send();
    } catch (Exception e) {
        log.error("Cannot email merged notification for " + changeId, e);
    } finally {
        requestContext.setContext(old);
        if (db != null) {
            db.close();
            db = null;
        }
    }
}
Also used : MergedSender(com.google.gerrit.server.mail.send.MergedSender) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) OrmException(com.google.gwtorm.server.OrmException) OutOfScopeException(com.google.inject.OutOfScopeException) ProvisionException(com.google.inject.ProvisionException)

Example 9 with RequestContext

use of com.google.gerrit.server.util.RequestContext in project gerrit by GerritCodeReview.

the class ServerPlugin method stop.

@Override
protected void stop(PluginGuiceEnvironment env) {
    if (serverManager != null) {
        RequestContext oldContext = env.enter(this);
        try {
            serverManager.stop();
        } finally {
            env.exit(oldContext);
        }
        serverManager = null;
        sysInjector = null;
        sshInjector = null;
        httpInjector = null;
    }
}
Also used : RequestContext(com.google.gerrit.server.util.RequestContext)

Example 10 with RequestContext

use of com.google.gerrit.server.util.RequestContext in project gerrit by GerritCodeReview.

the class PluginGuiceEnvironment method onStartPlugin.

public void onStartPlugin(Plugin plugin) {
    RequestContext oldContext = enter(plugin);
    try {
        attachItem(sysItems, plugin.getSysInjector(), plugin);
        attachItem(sshItems, plugin.getSshInjector(), plugin);
        attachItem(httpItems, plugin.getHttpInjector(), plugin);
        attachSet(sysSets, plugin.getSysInjector(), plugin);
        attachSet(sshSets, plugin.getSshInjector(), plugin);
        attachSet(httpSets, plugin.getHttpInjector(), plugin);
        attachMap(sysMaps, plugin.getSysInjector(), plugin);
        attachMap(sshMaps, plugin.getSshInjector(), plugin);
        attachMap(httpMaps, plugin.getHttpInjector(), plugin);
    } finally {
        exit(oldContext);
    }
    for (StartPluginListener l : onStart) {
        l.onStartPlugin(plugin);
    }
}
Also used : PluginRequestContext(com.google.gerrit.server.util.PluginRequestContext) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext)

Aggregations

RequestContext (com.google.gerrit.server.util.RequestContext)11 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)10 CurrentUser (com.google.gerrit.server.CurrentUser)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 Injector (com.google.inject.Injector)6 Provider (com.google.inject.Provider)6 Before (org.junit.Before)6 LifecycleManager (com.google.gerrit.lifecycle.LifecycleManager)5 Account (com.google.gerrit.reviewdb.client.Account)4 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)4 Project (com.google.gerrit.reviewdb.client.Project)3 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)2 ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 PluginRequestContext (com.google.gerrit.server.util.PluginRequestContext)2 OrmException (com.google.gwtorm.server.OrmException)2 ProvisionException (com.google.inject.ProvisionException)2 LabelType (com.google.gerrit.common.data.LabelType)1 ReloadableRegistrationHandle (com.google.gerrit.extensions.registration.ReloadableRegistrationHandle)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1