Merge "Move more endpoints to singleton scope and remove providers"

This commit is contained in:
Shawn Pearce 2014-05-29 19:52:07 +00:00 committed by Gerrit Code Review
commit 7af3ec348e
41 changed files with 159 additions and 133 deletions

View File

@ -51,6 +51,7 @@ import com.google.gwtorm.server.OrmConcurrencyException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@ -79,6 +80,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
@Singleton
public class ChangeUtil {
/**
* Epoch for sort key calculations, Tue Sep 30 2008 17:00:00.

View File

@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.Collections;
import java.util.HashSet;
@ -29,6 +30,7 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Singleton
public class AccountResolver {
private final Realm realm;
private final AccountByEmailCache byEmail;

View File

@ -59,7 +59,7 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
private final AuthConfig authConfig;
private final AccountManager accountManager;
private final RegisterNewEmailSender.Factory registerNewEmailFactory;
private final Provider<PutPreferred> putPreferredProvider;
private final PutPreferred putPreferred;
private final String email;
@Inject
@ -68,14 +68,14 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
AuthConfig authConfig,
AccountManager accountManager,
RegisterNewEmailSender.Factory registerNewEmailFactory,
Provider<PutPreferred> putPreferredProvider,
PutPreferred putPreferred,
@Assisted String email) {
this.self = self;
this.realm = realm;
this.authConfig = authConfig;
this.accountManager = accountManager;
this.registerNewEmailFactory = registerNewEmailFactory;
this.putPreferredProvider = putPreferredProvider;
this.putPreferred = putPreferred;
this.email = email;
}
@ -128,7 +128,7 @@ public class CreateEmail implements RestModifyView<AccountResource, Input> {
throw new ResourceConflictException(e.getMessage());
}
if (input.preferred) {
putPreferredProvider.get().apply(
putPreferred.apply(
new AccountResource.Email(user, email),
null);
info.preferred = true;

View File

@ -20,9 +20,11 @@ import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.AuthConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Set;
@Singleton
public class DefaultRealm implements Realm {
private final EmailExpander emailExpander;
private final AccountByEmailCache byEmail;

View File

@ -32,13 +32,13 @@ public class Emails implements
ChildCollection<AccountResource, AccountResource.Email>,
AcceptsCreate<AccountResource> {
private final DynamicMap<RestView<AccountResource.Email>> views;
private final Provider<GetEmails> list;
private final GetEmails list;
private final Provider<CurrentUser> self;
private final CreateEmail.Factory createEmailFactory;
@Inject
Emails(DynamicMap<RestView<AccountResource.Email>> views,
Provider<GetEmails> list,
GetEmails list,
Provider<CurrentUser> self,
CreateEmail.Factory createEmailFactory) {
this.views = views;
@ -49,7 +49,7 @@ public class Emails implements
@Override
public RestView<AccountResource> list() {
return list.get();
return list;
}
@Override

View File

@ -21,11 +21,13 @@ import com.google.gerrit.server.CurrentUser;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@Singleton
public class GetEmails implements RestReadView<AccountResource> {
private final Provider<CurrentUser> self;

View File

@ -25,9 +25,11 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.List;
@Singleton
public class GetSshKeys implements RestReadView<AccountResource> {
private final Provider<CurrentUser> self;

View File

@ -32,13 +32,13 @@ import com.google.inject.Singleton;
public class SshKeys implements
ChildCollection<AccountResource, AccountResource.SshKey> {
private final DynamicMap<RestView<AccountResource.SshKey>> views;
private final Provider<GetSshKeys> list;
private final GetSshKeys list;
private final Provider<CurrentUser> self;
private final Provider<ReviewDb> dbProvider;
@Inject
SshKeys(DynamicMap<RestView<AccountResource.SshKey>> views,
Provider<GetSshKeys> list, Provider<CurrentUser> self,
GetSshKeys list, Provider<CurrentUser> self,
Provider<ReviewDb> dbProvider) {
this.views = views;
this.list = list;
@ -48,7 +48,7 @@ public class SshKeys implements
@Override
public RestView<AccountResource> list() {
return list.get();
return list;
}
@Override

View File

@ -14,24 +14,23 @@
package com.google.gerrit.server.api;
import com.google.gerrit.extensions.api.accounts.Accounts;
import com.google.gerrit.extensions.api.GerritApi;
import com.google.gerrit.extensions.api.accounts.Accounts;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.projects.Projects;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
class GerritApiImpl extends GerritApi.NotImplemented implements GerritApi {
private final Provider<Accounts> accounts;
private final Provider<Changes> changes;
private final Provider<Projects> projects;
private final Accounts accounts;
private final Changes changes;
private final Projects projects;
@Inject
GerritApiImpl(Provider<Accounts> accounts,
Provider<Changes> changes,
Provider<Projects> projects) {
GerritApiImpl(Accounts accounts,
Changes changes,
Projects projects) {
this.accounts = accounts;
this.changes = changes;
this.projects = projects;
@ -39,16 +38,16 @@ class GerritApiImpl extends GerritApi.NotImplemented implements GerritApi {
@Override
public Accounts accounts() {
return accounts.get();
return accounts;
}
@Override
public Changes changes() {
return changes.get();
return changes;
}
@Override
public Projects projects() {
return projects.get();
return projects;
}
}

View File

@ -50,21 +50,21 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
private final Revisions revisions;
private final RevisionApiImpl.Factory revisionApi;
private final ChangeResource change;
private final Provider<Abandon> abandon;
private final Provider<Revert> revert;
private final Provider<Restore> restore;
private final Abandon abandon;
private final Revert revert;
private final Restore restore;
private final Provider<PostReviewers> postReviewers;
private final ChangeJson changeJson;
private final Provider<ChangeJson> changeJson;
@Inject
ChangeApiImpl(Changes changeApi,
Revisions revisions,
RevisionApiImpl.Factory revisionApi,
Provider<Abandon> abandon,
Provider<Revert> revert,
Provider<Restore> restore,
Abandon abandon,
Revert revert,
Restore restore,
Provider<PostReviewers> postReviewers,
ChangeJson changeJson,
Provider<ChangeJson> changeJson,
@Assisted ChangeResource change) {
this.changeApi = changeApi;
this.revert = revert;
@ -110,7 +110,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
@Override
public void abandon(AbandonInput in) throws RestApiException {
try {
abandon.get().apply(change, in);
abandon.apply(change, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot abandon change", e);
}
@ -124,7 +124,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
@Override
public void restore(RestoreInput in) throws RestApiException {
try {
restore.get().apply(change, in);
restore.apply(change, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot restore change", e);
}
@ -138,7 +138,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
@Override
public ChangeApi revert(RevertInput in) throws RestApiException {
try {
return changeApi.id(revert.get().apply(change, in)._number);
return changeApi.id(revert.apply(change, in)._number);
} catch (OrmException | EmailException | IOException e) {
throw new RestApiException("Cannot revert change", e);
}
@ -165,7 +165,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
throws RestApiException {
try {
return ChangeInfoMapper.INSTANCE.apply(
changeJson.addOptions(s).format(change));
changeJson.get().addOptions(s).format(change));
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve change", e);
}

View File

@ -43,24 +43,24 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
}
private final Changes changes;
private final Provider<CherryPick> cherryPick;
private final Provider<DeleteDraftPatchSet> deleteDraft;
private final Provider<Rebase> rebase;
private final Provider<RebaseChange> rebaseChange;
private final Provider<PostReview> review;
private final Provider<Submit> submit;
private final Provider<Publish> publish;
private final CherryPick cherryPick;
private final DeleteDraftPatchSet deleteDraft;
private final Rebase rebase;
private final RebaseChange rebaseChange;
private final Submit submit;
private final Publish publish;
private final RevisionResource revision;
private final Provider<PostReview> review;
@Inject
RevisionApiImpl(Changes changes,
Provider<CherryPick> cherryPick,
Provider<DeleteDraftPatchSet> deleteDraft,
Provider<Rebase> rebase,
Provider<RebaseChange> rebaseChange,
CherryPick cherryPick,
DeleteDraftPatchSet deleteDraft,
Rebase rebase,
RebaseChange rebaseChange,
Submit submit,
Publish publish,
Provider<PostReview> review,
Provider<Submit> submit,
Provider<Publish> publish,
@Assisted RevisionResource r) {
this.changes = changes;
this.cherryPick = cherryPick;
@ -92,7 +92,7 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
@Override
public void submit(SubmitInput in) throws RestApiException {
try {
submit.get().apply(revision, in);
submit.apply(revision, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot submit change", e);
}
@ -101,7 +101,7 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
@Override
public void publish() throws RestApiException {
try {
publish.get().apply(revision, new Publish.Input());
publish.apply(revision, new Publish.Input());
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot publish draft patch set", e);
}
@ -110,7 +110,7 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
@Override
public void delete() throws RestApiException {
try {
deleteDraft.get().apply(revision, null);
deleteDraft.apply(revision, null);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot delete draft ps", e);
}
@ -119,7 +119,7 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
@Override
public ChangeApi rebase() throws RestApiException {
try {
return changes.id(rebase.get().apply(revision, null)._number);
return changes.id(rebase.apply(revision, null)._number);
} catch (OrmException | EmailException e) {
throw new RestApiException("Cannot rebase ps", e);
}
@ -127,13 +127,13 @@ class RevisionApiImpl extends RevisionApi.NotImplemented implements RevisionApi
@Override
public boolean canRebase() {
return rebaseChange.get().canRebase(revision);
return rebaseChange.canRebase(revision);
}
@Override
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
try {
return changes.id(cherryPick.get().apply(revision, in)._number);
return changes.id(cherryPick.apply(revision, in)._number);
} catch (OrmException | EmailException | IOException e) {
throw new RestApiException("Cannot cherry pick", e);
}

View File

@ -42,12 +42,12 @@ import java.io.IOException;
public class CherryPick implements RestModifyView<RevisionResource, CherryPickInput>,
UiAction<RevisionResource> {
private final Provider<ReviewDb> dbProvider;
private final Provider<CherryPickChange> cherryPickChange;
private final CherryPickChange cherryPickChange;
private final ChangeJson json;
@Inject
CherryPick(Provider<ReviewDb> dbProvider,
Provider<CherryPickChange> cherryPickChange,
CherryPickChange cherryPickChange,
ChangeJson json) {
this.dbProvider = dbProvider;
this.cherryPickChange = cherryPickChange;
@ -85,7 +85,7 @@ public class CherryPick implements RestModifyView<RevisionResource, CherryPickIn
final PatchSet.Id patchSetId = revision.getPatchSet().getId();
try {
Change.Id cherryPickedChangeId = cherryPickChange.get().cherryPick(
Change.Id cherryPickedChangeId = cherryPickChange.cherryPick(
patchSetId, input.message,
input.destination, refControl);
return json.format(cherryPickedChangeId);

View File

@ -29,12 +29,12 @@ import com.google.inject.Singleton;
@Singleton
class Comments implements ChildCollection<RevisionResource, CommentResource> {
private final DynamicMap<RestView<CommentResource>> views;
private final Provider<ListComments> list;
private final ListComments list;
private final Provider<ReviewDb> dbProvider;
@Inject
Comments(DynamicMap<RestView<CommentResource>> views,
Provider<ListComments> list,
ListComments list,
Provider<ReviewDb> dbProvider) {
this.views = views;
this.list = list;
@ -48,7 +48,7 @@ class Comments implements ChildCollection<RevisionResource, CommentResource> {
@Override
public RestView<RevisionResource> list() {
return list.get();
return list;
}
@Override

View File

@ -76,7 +76,7 @@ public class CreateChange implements
private final GitRepositoryManager gitManager;
private final TimeZone serverTimeZone;
private final Provider<CurrentUser> userProvider;
private final Provider<ProjectsCollection> projectsCollection;
private final ProjectsCollection projectsCollection;
private final CommitValidators.Factory commitValidatorsFactory;
private final ChangeInserter.Factory changeInserterFactory;
private final ChangeJson json;
@ -86,7 +86,7 @@ public class CreateChange implements
GitRepositoryManager gitManager,
@GerritPersonIdent PersonIdent myIdent,
Provider<CurrentUser> userProvider,
Provider<ProjectsCollection> projectsCollection,
ProjectsCollection projectsCollection,
CommitValidators.Factory commitValidatorsFactory,
ChangeInserter.Factory changeInserterFactory,
ChangeJson json) {
@ -130,7 +130,7 @@ public class CreateChange implements
refName = Constants.R_HEADS + input.branch;
}
ProjectResource rsrc = projectsCollection.get().parse(input.project);
ProjectResource rsrc = projectsCollection.parse(input.project);
Capable r = rsrc.getControl().canPushToAtLeastOneRef();
if (r != Capable.OK) {

View File

@ -32,13 +32,13 @@ import com.google.inject.Singleton;
class Drafts implements ChildCollection<RevisionResource, DraftResource> {
private final DynamicMap<RestView<DraftResource>> views;
private final Provider<CurrentUser> user;
private final Provider<ListDrafts> list;
private final ListDrafts list;
private final Provider<ReviewDb> dbProvider;
@Inject
Drafts(DynamicMap<RestView<DraftResource>> views,
Provider<CurrentUser> user,
Provider<ListDrafts> list,
ListDrafts list,
Provider<ReviewDb> dbProvider) {
this.views = views;
this.user = user;
@ -54,7 +54,7 @@ class Drafts implements ChildCollection<RevisionResource, DraftResource> {
@Override
public RestView<RevisionResource> list() throws AuthException {
checkIdentifiedUser();
return list.get();
return list;
}
@Override

View File

@ -27,11 +27,13 @@ import com.google.gerrit.server.patch.PatchListEntry;
import com.google.gerrit.server.patch.PatchListKey;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.ObjectId;
import java.util.Map;
@Singleton
public class FileInfoJson {
private final PatchListCache patchListCache;

View File

@ -97,7 +97,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
private final Provider<ReviewDb> db;
private final Provider<CurrentUser> self;
private final FileInfoJson fileInfoJson;
private final Provider<Revisions> revisions;
private final Revisions revisions;
private final GitRepositoryManager gitManager;
private final PatchListCache patchListCache;
@ -105,7 +105,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
ListFiles(Provider<ReviewDb> db,
Provider<CurrentUser> self,
FileInfoJson fileInfoJson,
Provider<Revisions> revisions,
Revisions revisions,
GitRepositoryManager gitManager,
PatchListCache patchListCache) {
this.db = db;
@ -127,7 +127,7 @@ class Files implements ChildCollection<RevisionResource, FileResource> {
PatchSet basePatchSet = null;
if (base != null) {
RevisionResource baseResource = revisions.get().parse(
RevisionResource baseResource = revisions.parse(
resource.getChangeResource(), IdString.fromDecoded(base));
basePatchSet = baseResource.getPatchSet();
}

View File

@ -41,7 +41,6 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.jgit.diff.Edit;
import org.eclipse.jgit.diff.ReplaceEdit;
@ -60,7 +59,7 @@ import java.util.concurrent.TimeUnit;
public class GetDiff implements RestReadView<FileResource> {
private final ProjectCache projectCache;
private final PatchScriptFactory.Factory patchScriptFactoryFactory;
private final Provider<Revisions> revisions;
private final Revisions revisions;
@Option(name = "--base", metaVar = "REVISION")
String base;
@ -77,7 +76,7 @@ public class GetDiff implements RestReadView<FileResource> {
@Inject
GetDiff(ProjectCache projectCache,
PatchScriptFactory.Factory patchScriptFactoryFactory,
Provider<Revisions> revisions) {
Revisions revisions) {
this.projectCache = projectCache;
this.patchScriptFactoryFactory = patchScriptFactoryFactory;
this.revisions = revisions;
@ -88,7 +87,7 @@ public class GetDiff implements RestReadView<FileResource> {
throws ResourceConflictException, ResourceNotFoundException, OrmException {
PatchSet.Id basePatchSet = null;
if (base != null) {
RevisionResource baseResource = revisions.get().parse(
RevisionResource baseResource = revisions.parse(
resource.getRevision().getChangeResource(), IdString.fromDecoded(base));
basePatchSet = baseResource.getPatchSet().getId();
}

View File

@ -25,6 +25,7 @@ import com.google.gerrit.server.project.ChangeControl;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@ -36,6 +37,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
import java.io.IOException;
import java.util.Collection;
@Singleton
class IncludedIn implements RestReadView<ChangeResource> {
private final Provider<ReviewDb> db;

View File

@ -20,7 +20,9 @@ import com.google.gerrit.server.account.AccountInfo;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
class ListComments extends ListDrafts {
@Inject
ListComments(Provider<ReviewDb> db, AccountInfo.Loader.Factory alf) {

View File

@ -26,12 +26,14 @@ import com.google.gerrit.server.account.AccountInfo;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@Singleton
class ListDrafts implements RestReadView<RevisionResource> {
protected final Provider<ReviewDb> db;
private final AccountInfo.Loader.Factory accountLoaderFactory;

View File

@ -23,10 +23,12 @@ import com.google.gerrit.server.change.ReviewerJson.ReviewerInfo;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.util.List;
import java.util.Map;
@Singleton
class ListReviewers implements RestReadView<ChangeResource> {
private final Provider<ReviewDb> dbProvider;
private final ApprovalsUtil approvalsUtil;

View File

@ -79,7 +79,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
private final ReviewerResource.Factory reviewerFactory;
private final ApprovalsUtil approvalsUtil;
private final AddReviewerSender.Factory addReviewerSenderFactory;
private final Provider<GroupsCollection> groupsCollection;
private final GroupsCollection groupsCollection;
private final GroupMembers.Factory groupMembersFactory;
private final AccountInfo.Loader.Factory accountLoaderFactory;
private final Provider<ReviewDb> dbProvider;
@ -97,7 +97,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
ReviewerResource.Factory reviewerFactory,
ApprovalsUtil approvalsUtil,
AddReviewerSender.Factory addReviewerSenderFactory,
Provider<GroupsCollection> groupsCollection,
GroupsCollection groupsCollection,
GroupMembers.Factory groupMembersFactory,
AccountInfo.Loader.Factory accountLoaderFactory,
Provider<ReviewDb> db,
@ -162,7 +162,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
private PostResult putGroup(ChangeResource rsrc, AddReviewerInput input)
throws BadRequestException,
UnprocessableEntityException, OrmException, EmailException, IOException {
GroupDescription.Basic group = groupsCollection.get().parseInternal(input.reviewer);
GroupDescription.Basic group = groupsCollection.parseInternal(input.reviewer);
PostResult result = new PostResult();
if (!isLegalReviewerGroup(group.getGroupUUID())) {
result.error = MessageFormat.format(

View File

@ -40,7 +40,7 @@ public class Reviewers implements
private final ApprovalsUtil approvalsUtil;
private final AccountsCollection accounts;
private final ReviewerResource.Factory resourceFactory;
private final Provider<ListReviewers> list;
private final ListReviewers list;
@Inject
Reviewers(Provider<ReviewDb> dbProvider,
@ -48,7 +48,7 @@ public class Reviewers implements
AccountsCollection accounts,
ReviewerResource.Factory resourceFactory,
DynamicMap<RestView<ReviewerResource>> views,
Provider<ListReviewers> list) {
ListReviewers list) {
this.dbProvider = dbProvider;
this.approvalsUtil = approvalsUtil;
this.accounts = accounts;
@ -64,7 +64,7 @@ public class Reviewers implements
@Override
public RestView<ChangeResource> list() {
return list.get();
return list;
}
@Override

View File

@ -35,13 +35,13 @@ public class CachesCollection implements
ChildCollection<ConfigResource, CacheResource> {
private final DynamicMap<RestView<CacheResource>> views;
private final Provider<ListCaches> list;
private final ListCaches list;
private final Provider<CurrentUser> self;
private final DynamicMap<Cache<?, ?>> cacheMap;
@Inject
CachesCollection(DynamicMap<RestView<CacheResource>> views,
Provider<ListCaches> list, Provider<CurrentUser> self,
ListCaches list, Provider<CurrentUser> self,
DynamicMap<Cache<?, ?>> cacheMap) {
this.views = views;
this.list = list;
@ -51,7 +51,7 @@ public class CachesCollection implements
@Override
public RestView<ConfigResource> list() {
return list.get();
return list;
}
@Override

View File

@ -20,25 +20,24 @@ import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
public class CapabilitiesCollection implements
ChildCollection<ConfigResource, CapabilityResource> {
private final DynamicMap<RestView<CapabilityResource>> views;
private final Provider<ListCapabilities> list;
private final ListCapabilities list;
@Inject
CapabilitiesCollection(DynamicMap<RestView<CapabilityResource>> views,
Provider<ListCapabilities> list) {
ListCapabilities list) {
this.views = views;
this.list = list;
}
@Override
public RestView<ConfigResource> list() throws ResourceNotFoundException {
return list.get();
return list;
}
@Override

View File

@ -21,7 +21,9 @@ import com.google.gerrit.extensions.restapi.RestCollection;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@Singleton
public class ConfigCollection implements
RestCollection<TopLevelResource, ConfigResource> {
private final DynamicMap<RestView<ConfigResource>> views;

View File

@ -22,6 +22,7 @@ import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -29,6 +30,7 @@ import org.slf4j.LoggerFactory;
import java.util.Map;
/** List capabilities visible to the calling user. */
@Singleton
public class ListCapabilities implements RestReadView<ConfigResource> {
private static final Logger log = LoggerFactory.getLogger(ListCapabilities.class);
private final DynamicMap<CapabilityDefinition> pluginCapabilities;

View File

@ -19,9 +19,11 @@ import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.extensions.webui.TopMenu;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
@Singleton
class ListTopMenus implements RestReadView<ConfigResource> {
private final DynamicSet<TopMenu> extensions;

View File

@ -20,25 +20,24 @@ import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@Singleton
class TopMenuCollection implements
ChildCollection<ConfigResource, TopMenuResource> {
private final DynamicMap<RestView<TopMenuResource>> views;
private final Provider<ListTopMenus> list;
private final ListTopMenus list;
@Inject
TopMenuCollection(DynamicMap<RestView<TopMenuResource>> views,
Provider<ListTopMenus> list) {
ListTopMenus list) {
this.views = views;
this.list = list;
}
@Override
public RestView<ConfigResource> list() throws ResourceNotFoundException {
return list.get();
return list;
}
@Override

View File

@ -31,6 +31,7 @@ import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
@ -44,6 +45,7 @@ import org.slf4j.LoggerFactory;
import java.util.Set;
/** Factory to create a {@link SubmitStrategy} for a {@link SubmitType}. */
@Singleton
public class SubmitStrategyFactory {
private static final Logger log = LoggerFactory
.getLogger(SubmitStrategyFactory.class);

View File

@ -71,13 +71,13 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
}
}
private final Provider<GroupsCollection> groupsCollection;
private final GroupsCollection groupsCollection;
private final GroupIncludeCache groupIncludeCache;
private final Provider<ReviewDb> db;
private final GroupJson json;
@Inject
public AddIncludedGroups(Provider<GroupsCollection> groupsCollection,
public AddIncludedGroups(GroupsCollection groupsCollection,
GroupIncludeCache groupIncludeCache,
Provider<ReviewDb> db, GroupJson json) {
this.groupsCollection = groupsCollection;
@ -103,7 +103,7 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
Account.Id me = ((IdentifiedUser) control.getCurrentUser()).getAccountId();
for (String includedGroup : input.groups) {
GroupDescription.Basic d = groupsCollection.get().parse(includedGroup);
GroupDescription.Basic d = groupsCollection.parse(includedGroup);
if (!control.canAddGroup(d.getGroupUUID())) {
throw new AuthException(String.format("Cannot add group: %s",
d.getName()));
@ -140,10 +140,10 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
static class Input {
}
private final Provider<AddIncludedGroups> put;
private final AddIncludedGroups put;
private final String id;
PutIncludedGroup(Provider<AddIncludedGroups> put, String id) {
PutIncludedGroup(AddIncludedGroups put, String id) {
this.put = put;
this.id = id;
}
@ -154,7 +154,7 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
UnprocessableEntityException, OrmException {
AddIncludedGroups.Input in = new AddIncludedGroups.Input();
in.groups = ImmutableList.of(id);
List<GroupInfo> list = put.get().apply(resource, in);
List<GroupInfo> list = put.apply(resource, in);
if (list.size() == 1) {
return list.get(0);
}

View File

@ -77,7 +77,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
private final AccountManager accountManager;
private final AuthType authType;
private final Provider<AccountsCollection> accounts;
private final AccountsCollection accounts;
private final AccountResolver accountResolver;
private final AccountCache accountCache;
private final AccountInfo.Loader.Factory infoFactory;
@ -86,7 +86,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
@Inject
AddMembers(AccountManager accountManager,
AuthConfig authConfig,
Provider<AccountsCollection> accounts,
AccountsCollection accounts,
AccountResolver accountResolver,
AccountCache accountCache,
AccountInfo.Loader.Factory infoFactory,
@ -155,7 +155,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
private Account findAccount(String nameOrEmail) throws AuthException,
UnprocessableEntityException, OrmException {
try {
return accounts.get().parse(nameOrEmail).getAccount();
return accounts.parse(nameOrEmail).getAccount();
} catch (UnprocessableEntityException e) {
// might be because the account does not exist or because the account is
// not visible
@ -193,10 +193,10 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
static class Input {
}
private final Provider<AddMembers> put;
private final AddMembers put;
private final String id;
PutMember(Provider<AddMembers> put, String id) {
PutMember(AddMembers put, String id) {
this.put = put;
this.id = id;
}
@ -207,7 +207,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
UnprocessableEntityException, OrmException {
AddMembers.Input in = new AddMembers.Input();
in._oneMember = id;
List<AccountInfo> list = put.get().apply(resource, in);
List<AccountInfo> list = put.apply(resource, in);
if (list.size() == 1) {
return list.get(0);
}
@ -220,10 +220,10 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
static class Input {
}
private final Provider<GetMember> get;
private final GetMember get;
@Inject
UpdateMember(Provider<GetMember> get) {
UpdateMember(GetMember get) {
this.get = get;
}
@ -231,7 +231,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
public AccountInfo apply(MemberResource resource, PutMember.Input input)
throws OrmException {
// Do nothing, the user is already a member.
return get.get().apply(resource);
return get.apply(resource);
}
}
}

View File

@ -44,13 +44,13 @@ import java.util.Map;
@Singleton
public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input> {
private final Provider<GroupsCollection> groupsCollection;
private final GroupsCollection groupsCollection;
private final GroupIncludeCache groupIncludeCache;
private final Provider<ReviewDb> db;
private final Provider<CurrentUser> self;
@Inject
DeleteIncludedGroups(Provider<GroupsCollection> groupsCollection,
DeleteIncludedGroups(GroupsCollection groupsCollection,
GroupIncludeCache groupIncludeCache,
Provider<ReviewDb> db,
Provider<CurrentUser> self) {
@ -75,7 +75,7 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
final List<AccountGroupById> toRemove = Lists.newLinkedList();
for (final String includedGroup : input.groups) {
GroupDescription.Basic d = groupsCollection.get().parse(includedGroup);
GroupDescription.Basic d = groupsCollection.parse(includedGroup);
if (!control.canRemoveGroup(d.getGroupUUID())) {
throw new AuthException(String.format("Cannot delete group: %s",
d.getName()));

View File

@ -43,13 +43,13 @@ import java.util.Map;
@Singleton
public class DeleteMembers implements RestModifyView<GroupResource, Input> {
private final Provider<AccountsCollection> accounts;
private final AccountsCollection accounts;
private final AccountCache accountCache;
private final Provider<ReviewDb> db;
private final Provider<CurrentUser> self;
@Inject
DeleteMembers(Provider<AccountsCollection> accounts,
DeleteMembers(AccountsCollection accounts,
AccountCache accountCache, Provider<ReviewDb> db,
Provider<CurrentUser> self) {
this.accounts = accounts;
@ -73,7 +73,7 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
final List<AccountGroupMember> toRemove = Lists.newLinkedList();
for (final String nameOrEmail : input.members) {
Account a = accounts.get().parse(nameOrEmail).getAccount();
Account a = accounts.parse(nameOrEmail).getAccount();
if (!control.canRemoveMember(a.getId())) {
throw new AuthException("Cannot delete member: " + a.getFullName());

View File

@ -38,16 +38,17 @@ public class IncludedGroupsCollection implements
ChildCollection<GroupResource, IncludedGroupResource>,
AcceptsCreate<GroupResource> {
private final DynamicMap<RestView<IncludedGroupResource>> views;
private final Provider<ListIncludedGroups> list;
private final Provider<GroupsCollection> groupsCollection;
private final ListIncludedGroups list;
private final GroupsCollection groupsCollection;
private final Provider<ReviewDb> dbProvider;
private final Provider<AddIncludedGroups> put;
private final AddIncludedGroups put;
@Inject
IncludedGroupsCollection(DynamicMap<RestView<IncludedGroupResource>> views,
Provider<ListIncludedGroups> list,
Provider<GroupsCollection> groupsCollection,
Provider<ReviewDb> dbProvider, Provider<AddIncludedGroups> put) {
ListIncludedGroups list,
GroupsCollection groupsCollection,
Provider<ReviewDb> dbProvider,
AddIncludedGroups put) {
this.views = views;
this.list = list;
this.groupsCollection = groupsCollection;
@ -57,7 +58,7 @@ public class IncludedGroupsCollection implements
@Override
public RestView<GroupResource> list() {
return list.get();
return list;
}
@Override
@ -70,7 +71,7 @@ public class IncludedGroupsCollection implements
}
GroupDescription.Basic member =
groupsCollection.get().parse(TopLevelResource.INSTANCE, id).getGroup();
groupsCollection.parse(TopLevelResource.INSTANCE, id).getGroup();
if (isMember(parent, member)
&& resource.getControl().canSeeGroup(member.getGroupUUID())) {
return new IncludedGroupResource(resource, member);

View File

@ -39,16 +39,16 @@ public class MembersCollection implements
AcceptsCreate<GroupResource> {
private final DynamicMap<RestView<MemberResource>> views;
private final Provider<ListMembers> list;
private final Provider<AccountsCollection> accounts;
private final AccountsCollection accounts;
private final Provider<ReviewDb> db;
private final Provider<AddMembers> put;
private final AddMembers put;
@Inject
MembersCollection(DynamicMap<RestView<MemberResource>> views,
Provider<ListMembers> list,
Provider<AccountsCollection> accounts,
AccountsCollection accounts,
Provider<ReviewDb> db,
Provider<AddMembers> put) {
AddMembers put) {
this.views = views;
this.list = list;
this.accounts = accounts;
@ -70,7 +70,7 @@ public class MembersCollection implements
throw new MethodNotAllowedException();
}
IdentifiedUser user = accounts.get().parse(TopLevelResource.INSTANCE, id).getUser();
IdentifiedUser user = accounts.parse(TopLevelResource.INSTANCE, id).getUser();
AccountGroupMember.Key key =
new AccountGroupMember.Key(user.getAccountId(), parent.toAccountGroup().getId());
if (db.get().accountGroupMembers().get(key) != null

View File

@ -42,13 +42,13 @@ public class PutOwner implements RestModifyView<GroupResource, Input> {
public String owner;
}
private final Provider<GroupsCollection> groupsCollection;
private final GroupsCollection groupsCollection;
private final GroupCache groupCache;
private final Provider<ReviewDb> db;
private final GroupJson json;
@Inject
PutOwner(Provider<GroupsCollection> groupsCollection, GroupCache groupCache,
PutOwner(GroupsCollection groupsCollection, GroupCache groupCache,
Provider<ReviewDb> db, GroupJson json) {
this.groupsCollection = groupsCollection;
this.groupCache = groupCache;
@ -77,7 +77,7 @@ public class PutOwner implements RestModifyView<GroupResource, Input> {
throw new ResourceNotFoundException();
}
GroupDescription.Basic owner = groupsCollection.get().parse(input.owner);
GroupDescription.Basic owner = groupsCollection.parse(input.owner);
if (!group.getOwnerGroupUUID().equals(owner.getGroupUUID())) {
group.setOwnerGroupUUID(owner.getGroupUUID());
db.get().accountGroups().update(Collections.singleton(group));

View File

@ -21,6 +21,7 @@ import com.google.gwtjsonrpc.server.ValidToken;
import com.google.gwtjsonrpc.server.XsrfException;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.util.Base64;
@ -29,6 +30,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** Verifies the token sent by {@link RegisterNewEmailSender}. */
@Singleton
public class SignedTokenEmailTokenVerifier implements EmailTokenVerifier {
private final SignedToken emailRegistrationToken;

View File

@ -22,7 +22,6 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.project.ListBranches.BranchInfo;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Constants;
@ -35,12 +34,12 @@ public class BranchesCollection implements
ChildCollection<ProjectResource, BranchResource>,
AcceptsCreate<ProjectResource> {
private final DynamicMap<RestView<BranchResource>> views;
private final Provider<ListBranches> list;
private final ListBranches list;
private final CreateBranch.Factory createBranchFactory;
@Inject
BranchesCollection(DynamicMap<RestView<BranchResource>> views,
Provider<ListBranches> list, CreateBranch.Factory createBranchFactory) {
ListBranches list, CreateBranch.Factory createBranchFactory) {
this.views = views;
this.list = list;
this.createBranchFactory = createBranchFactory;
@ -48,7 +47,7 @@ public class BranchesCollection implements
@Override
public RestView<ProjectResource> list() {
return list.get();
return list;
}
@Override
@ -59,7 +58,7 @@ public class BranchesCollection implements
&& !branchName.equals(Constants.HEAD)) {
branchName = Constants.R_HEADS + branchName;
}
List<BranchInfo> branches = list.get().apply(parent);
List<BranchInfo> branches = list.apply(parent);
for (BranchInfo b : branches) {
if (branchName.equals(b.ref)) {
return new BranchResource(parent.getControl(), b);

View File

@ -31,12 +31,12 @@ import java.io.IOException;
public class ChildProjectsCollection implements
ChildCollection<ProjectResource, ChildProjectResource> {
private final Provider<ListChildProjects> list;
private final Provider<ProjectsCollection> projectsCollection;
private final ProjectsCollection projectsCollection;
private final DynamicMap<RestView<ChildProjectResource>> views;
@Inject
ChildProjectsCollection(Provider<ListChildProjects> list,
Provider<ProjectsCollection> projectsCollection,
ProjectsCollection projectsCollection,
DynamicMap<RestView<ChildProjectResource>> views) {
this.list = list;
this.projectsCollection = projectsCollection;
@ -53,7 +53,7 @@ public class ChildProjectsCollection implements
public ChildProjectResource parse(ProjectResource parent, IdString id)
throws ResourceNotFoundException, IOException {
ProjectResource p =
projectsCollection.get().parse(TopLevelResource.INSTANCE, id);
projectsCollection.parse(TopLevelResource.INSTANCE, id);
for (ProjectState pp : p.getControl().getProjectState().parents()) {
if (parent.getNameKey().equals(pp.getProject().getNameKey())) {
return new ChildProjectResource(parent, p.getControl());