Merge "API: Don't use providers in request scope"

This commit is contained in:
David Pursehouse
2016-04-27 01:19:49 +00:00
committed by Gerrit Code Review
7 changed files with 85 additions and 101 deletions

View File

@@ -46,7 +46,6 @@ import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.ChangesCollection;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.errors.ConfigInvalidException;
@@ -63,7 +62,7 @@ public class AccountApiImpl implements AccountApi {
private final AccountResource account;
private final ChangesCollection changes;
private final AccountLoader.Factory accountLoaderFactory;
private final Provider<GetAvatar> getAvatar;
private final GetAvatar getAvatar;
private final GetPreferences getPreferences;
private final SetPreferences setPreferences;
private final GetDiffPreferences getDiffPreferences;
@@ -80,7 +79,7 @@ public class AccountApiImpl implements AccountApi {
@Inject
AccountApiImpl(AccountLoader.Factory ailf,
ChangesCollection changes,
Provider<GetAvatar> getAvatar,
GetAvatar getAvatar,
GetPreferences getPreferences,
SetPreferences setPreferences,
GetDiffPreferences getDiffPreferences,
@@ -127,9 +126,8 @@ public class AccountApiImpl implements AccountApi {
@Override
public String getAvatarUrl(int size) throws RestApiException {
GetAvatar myGetAvatar = getAvatar.get();
myGetAvatar.setSize(size);
return myGetAvatar.apply(account).location();
getAvatar.setSize(size);
return getAvatar.apply(account).location();
}
@Override

View File

@@ -60,7 +60,6 @@ import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
@@ -74,13 +73,13 @@ class ChangeApiImpl implements ChangeApi {
ChangeApiImpl create(ChangeResource change);
}
private final Provider<CurrentUser> user;
private final CurrentUser user;
private final Changes changeApi;
private final Reviewers reviewers;
private final Revisions revisions;
private final ReviewerApiImpl.Factory reviewerApi;
private final RevisionApiImpl.Factory revisionApi;
private final Provider<SuggestChangeReviewers> suggestReviewers;
private final SuggestChangeReviewers suggestReviewers;
private final ChangeResource change;
private final Abandon abandon;
private final Revert revert;
@@ -103,13 +102,13 @@ class ChangeApiImpl implements ChangeApi {
private final Move move;
@Inject
ChangeApiImpl(Provider<CurrentUser> user,
ChangeApiImpl(CurrentUser user,
Changes changeApi,
Reviewers reviewers,
Revisions revisions,
ReviewerApiImpl.Factory reviewerApi,
RevisionApiImpl.Factory revisionApi,
Provider<SuggestChangeReviewers> suggestReviewers,
SuggestChangeReviewers suggestReviewers,
Abandon abandon,
Revert revert,
Restore restore,
@@ -329,10 +328,9 @@ class ChangeApiImpl implements ChangeApi {
private List<SuggestedReviewerInfo> suggestReviewers(SuggestedReviewersRequest r)
throws RestApiException {
try {
SuggestChangeReviewers mySuggestReviewers = suggestReviewers.get();
mySuggestReviewers.setQuery(r.getQuery());
mySuggestReviewers.setLimit(r.getLimit());
return mySuggestReviewers.apply(change);
suggestReviewers.setQuery(r.getQuery());
suggestReviewers.setLimit(r.getLimit());
return suggestReviewers.apply(change);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot retrieve suggested reviewers", e);
}
@@ -342,9 +340,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeInfo get(EnumSet<ListChangesOption> s)
throws RestApiException {
try {
CurrentUser u = user.get();
if (u.isIdentifiedUser()) {
u.asIdentifiedUser().clearStarredChanges();
if (user.isIdentifiedUser()) {
user.asIdentifiedUser().clearStarredChanges();
}
return changeJson.create(s).format(change);
} catch (OrmException e) {

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
@@ -36,12 +35,12 @@ class FileApiImpl implements FileApi {
}
private final GetContent getContent;
private final Provider<GetDiff> getDiff;
private final GetDiff getDiff;
private final FileResource file;
@Inject
FileApiImpl(GetContent getContent,
Provider<GetDiff> getDiff,
GetDiff getDiff,
@Assisted FileResource file) {
this.getContent = getContent;
this.getDiff = getDiff;
@@ -60,7 +59,7 @@ class FileApiImpl implements FileApi {
@Override
public DiffInfo diff() throws RestApiException {
try {
return getDiff.get().apply(file).value();
return getDiff.apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
}
@@ -69,7 +68,7 @@ class FileApiImpl implements FileApi {
@Override
public DiffInfo diff(String base) throws RestApiException {
try {
return getDiff.get().setBase(base).apply(file).value();
return getDiff.setBase(base).apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
}
@@ -86,21 +85,20 @@ class FileApiImpl implements FileApi {
}
private DiffInfo get(DiffRequest r) throws RestApiException {
GetDiff diff = getDiff.get();
if (r.getBase() != null) {
diff.setBase(r.getBase());
getDiff.setBase(r.getBase());
}
if (r.getContext() != null) {
diff.setContext(r.getContext());
getDiff.setContext(r.getContext());
}
if (r.getIntraline() != null) {
diff.setIntraline(r.getIntraline());
getDiff.setIntraline(r.getIntraline());
}
if (r.getWhitespace() != null) {
diff.setWhitespace(r.getWhitespace());
getDiff.setWhitespace(r.getWhitespace());
}
try {
return diff.apply(file).value();
return getDiff.apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
}

View File

@@ -62,7 +62,6 @@ import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.lib.Repository;
@@ -89,11 +88,11 @@ class RevisionApiImpl implements RevisionApi {
private final Reviewed.PutReviewed putReviewed;
private final Reviewed.DeleteReviewed deleteReviewed;
private final RevisionResource revision;
private final Provider<Files> files;
private final Provider<Files.ListFiles> listFiles;
private final Provider<GetPatch> getPatch;
private final Provider<PostReview> review;
private final Provider<Mergeable> mergeable;
private final Files files;
private final Files.ListFiles listFiles;
private final GetPatch getPatch;
private final PostReview review;
private final Mergeable mergeable;
private final FileApiImpl.Factory fileApi;
private final ListRevisionComments listComments;
private final ListRevisionDrafts listDrafts;
@@ -103,7 +102,7 @@ class RevisionApiImpl implements RevisionApi {
private final Comments comments;
private final CommentApiImpl.Factory commentFactory;
private final GetRevisionActions revisionActions;
private final Provider<TestSubmitType> testSubmitType;
private final TestSubmitType testSubmitType;
private final TestSubmitType.Get getSubmitType;
@Inject
@@ -117,11 +116,11 @@ class RevisionApiImpl implements RevisionApi {
PublishDraftPatchSet publish,
Reviewed.PutReviewed putReviewed,
Reviewed.DeleteReviewed deleteReviewed,
Provider<Files> files,
Provider<Files.ListFiles> listFiles,
Provider<GetPatch> getPatch,
Provider<PostReview> review,
Provider<Mergeable> mergeable,
Files files,
Files.ListFiles listFiles,
GetPatch getPatch,
PostReview review,
Mergeable mergeable,
FileApiImpl.Factory fileApi,
ListRevisionComments listComments,
ListRevisionDrafts listDrafts,
@@ -131,7 +130,7 @@ class RevisionApiImpl implements RevisionApi {
Comments comments,
CommentApiImpl.Factory commentFactory,
GetRevisionActions revisionActions,
Provider<TestSubmitType> testSubmitType,
TestSubmitType testSubmitType,
TestSubmitType.Get getSubmitType,
@Assisted RevisionResource r) {
this.repoManager = repoManager;
@@ -166,7 +165,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public void review(ReviewInput in) throws RestApiException {
try {
review.get().apply(revision, in);
review.apply(revision, in);
} catch (OrmException | UpdateException e) {
throw new RestApiException("Cannot post review", e);
}
@@ -251,7 +250,7 @@ class RevisionApiImpl implements RevisionApi {
view = deleteReviewed;
}
view.apply(
files.get().parse(revision, IdString.fromDecoded(path)),
files.parse(revision, IdString.fromDecoded(path)),
new Reviewed.Input());
} catch (Exception e) {
throw new RestApiException("Cannot update reviewed flag", e);
@@ -263,7 +262,7 @@ class RevisionApiImpl implements RevisionApi {
public Set<String> reviewed() throws RestApiException {
try {
return ImmutableSet.copyOf((Iterable<String>) listFiles
.get().setReviewed(true)
.setReviewed(true)
.apply(revision).value());
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot list reviewed files", e);
@@ -273,7 +272,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public MergeableInfo mergeable() throws RestApiException {
try {
return mergeable.get().apply(revision);
return mergeable.apply(revision);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot check mergeability", e);
}
@@ -282,9 +281,8 @@ class RevisionApiImpl implements RevisionApi {
@Override
public MergeableInfo mergeableOtherBranches() throws RestApiException {
try {
Mergeable m = mergeable.get();
m.setOtherBranches(true);
return m.apply(revision);
mergeable.setOtherBranches(true);
return mergeable.apply(revision);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot check mergeability", e);
}
@@ -294,7 +292,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public Map<String, FileInfo> files() throws RestApiException {
try {
return (Map<String, FileInfo>)listFiles.get().apply(revision).value();
return (Map<String, FileInfo>)listFiles.apply(revision).value();
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot retrieve files", e);
}
@@ -304,7 +302,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public Map<String, FileInfo> files(String base) throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.get().setBase(base)
return (Map<String, FileInfo>) listFiles.setBase(base)
.apply(revision).value();
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot retrieve files", e);
@@ -313,7 +311,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public FileApi file(String path) {
return fileApi.create(files.get().parse(revision,
return fileApi.create(files.parse(revision,
IdString.fromDecoded(path)));
}
@@ -389,7 +387,7 @@ class RevisionApiImpl implements RevisionApi {
@Override
public BinaryResult patch() throws RestApiException {
try {
return getPatch.get().apply(revision);
return getPatch.apply(revision);
} catch (IOException e) {
throw new RestApiException("Cannot get patch", e);
}
@@ -413,7 +411,7 @@ class RevisionApiImpl implements RevisionApi {
public SubmitType testSubmitType(TestSubmitRuleInput in)
throws RestApiException {
try {
return testSubmitType.get().apply(revision, in);
return testSubmitType.apply(revision, in);
} catch (OrmException e) {
throw new RestApiException("Cannot test submit type", e);
}

View File

@@ -41,7 +41,6 @@ import com.google.gerrit.server.group.PutName;
import com.google.gerrit.server.group.PutOptions;
import com.google.gerrit.server.group.PutOwner;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -63,7 +62,7 @@ class GroupApiImpl implements GroupApi {
private final PutDescription putDescription;
private final GetOptions getOptions;
private final PutOptions putOptions;
private final Provider<ListMembers> listMembers;
private final ListMembers listMembers;
private final AddMembers addMembers;
private final DeleteMembers deleteMembers;
private final ListIncludedGroups listGroups;
@@ -84,7 +83,7 @@ class GroupApiImpl implements GroupApi {
PutDescription putDescription,
GetOptions getOptions,
PutOptions putOptions,
Provider<ListMembers> listMembers,
ListMembers listMembers,
AddMembers addMembers,
DeleteMembers deleteMembers,
ListIncludedGroups listGroups,
@@ -205,10 +204,9 @@ class GroupApiImpl implements GroupApi {
@Override
public List<AccountInfo> members(boolean recursive) throws RestApiException {
ListMembers list = listMembers.get();
list.setRecursive(recursive);
listMembers.setRecursive(recursive);
try {
return list.apply(rsrc);
return listMembers.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot list group members", e);
}

View File

@@ -19,7 +19,6 @@ import com.google.gerrit.extensions.common.ProjectInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.project.ChildProjectResource;
import com.google.gerrit.server.project.GetChildProject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -28,14 +27,14 @@ public class ChildProjectApiImpl implements ChildProjectApi {
ChildProjectApiImpl create(ChildProjectResource rsrc);
}
private final Provider<GetChildProject> getProvider;
private final GetChildProject getChildProject;
private final ChildProjectResource rsrc;
@AssistedInject
ChildProjectApiImpl(
Provider<GetChildProject> getProvider,
GetChildProject getChildProject,
@Assisted ChildProjectResource rsrc) {
this.getProvider = getProvider;
this.getChildProject = getChildProject;
this.rsrc = rsrc;
}
@@ -46,8 +45,7 @@ public class ChildProjectApiImpl implements ChildProjectApi {
@Override
public ProjectInfo get(boolean recursive) throws RestApiException {
GetChildProject get = getProvider.get();
get.setRecursive(recursive);
return get.apply(rsrc);
getChildProject.setRecursive(recursive);
return getChildProject.apply(rsrc);
}
}

View File

@@ -44,7 +44,6 @@ import com.google.gerrit.server.project.ProjectJson;
import com.google.gerrit.server.project.ProjectResource;
import com.google.gerrit.server.project.ProjectsCollection;
import com.google.gerrit.server.project.PutDescription;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -59,8 +58,8 @@ public class ProjectApiImpl implements ProjectApi {
ProjectApiImpl create(String name);
}
private final Provider<CurrentUser> user;
private final Provider<CreateProject.Factory> createProjectFactory;
private final CurrentUser user;
private final CreateProject.Factory createProjectFactory;
private final ProjectApiImpl.Factory projectApi;
private final ProjectsCollection projects;
private final GetDescription getDescription;
@@ -73,12 +72,12 @@ public class ProjectApiImpl implements ProjectApi {
private final BranchApiImpl.Factory branchApi;
private final TagApiImpl.Factory tagApi;
private final GetAccess getAccess;
private final Provider<ListBranches> listBranchesProvider;
private final Provider<ListTags> listTagsProvider;
private final ListBranches listBranches;
private final ListTags listTags;
@AssistedInject
ProjectApiImpl(Provider<CurrentUser> user,
Provider<CreateProject.Factory> createProjectFactory,
ProjectApiImpl(CurrentUser user,
CreateProject.Factory createProjectFactory,
ProjectApiImpl.Factory projectApi,
ProjectsCollection projects,
GetDescription getDescription,
@@ -89,18 +88,18 @@ public class ProjectApiImpl implements ProjectApi {
BranchApiImpl.Factory branchApiFactory,
TagApiImpl.Factory tagApiFactory,
GetAccess getAccess,
Provider<ListBranches> listBranchesProvider,
Provider<ListTags> listTagsProvider,
ListBranches listBranches,
ListTags listTags,
@Assisted ProjectResource project) {
this(user, createProjectFactory, projectApi, projects, getDescription,
putDescription, childApi, children, projectJson, branchApiFactory,
tagApiFactory, getAccess, listBranchesProvider, listTagsProvider,
tagApiFactory, getAccess, listBranches, listTags,
project, null);
}
@AssistedInject
ProjectApiImpl(Provider<CurrentUser> user,
Provider<CreateProject.Factory> createProjectFactory,
ProjectApiImpl(CurrentUser user,
CreateProject.Factory createProjectFactory,
ProjectApiImpl.Factory projectApi,
ProjectsCollection projects,
GetDescription getDescription,
@@ -111,17 +110,17 @@ public class ProjectApiImpl implements ProjectApi {
BranchApiImpl.Factory branchApiFactory,
TagApiImpl.Factory tagApiFactory,
GetAccess getAccess,
Provider<ListBranches> listBranchesProvider,
Provider<ListTags> listTagsProvider,
ListBranches listBranches,
ListTags listTags,
@Assisted String name) {
this(user, createProjectFactory, projectApi, projects, getDescription,
putDescription, childApi, children, projectJson, branchApiFactory,
tagApiFactory, getAccess, listBranchesProvider, listTagsProvider,
tagApiFactory, getAccess, listBranches, listTags,
null, name);
}
private ProjectApiImpl(Provider<CurrentUser> user,
Provider<CreateProject.Factory> createProjectFactory,
private ProjectApiImpl(CurrentUser user,
CreateProject.Factory createProjectFactory,
ProjectApiImpl.Factory projectApi,
ProjectsCollection projects,
GetDescription getDescription,
@@ -132,8 +131,8 @@ public class ProjectApiImpl implements ProjectApi {
BranchApiImpl.Factory branchApiFactory,
TagApiImpl.Factory tagApiFactory,
GetAccess getAccess,
Provider<ListBranches> listBranchesProvider,
Provider<ListTags> listTagsProvider,
ListBranches listBranches,
ListTags listTags,
ProjectResource project,
String name) {
this.user = user;
@@ -150,8 +149,8 @@ public class ProjectApiImpl implements ProjectApi {
this.branchApi = branchApiFactory;
this.tagApi = tagApiFactory;
this.getAccess = getAccess;
this.listBranchesProvider = listBranchesProvider;
this.listTagsProvider = listTagsProvider;
this.listBranches = listBranches;
this.listTags = listTags;
}
@Override
@@ -169,7 +168,7 @@ public class ProjectApiImpl implements ProjectApi {
throw new BadRequestException("name must match input.name");
}
checkRequiresCapability(user, null, CreateProject.class);
createProjectFactory.get().create(name)
createProjectFactory.create(name)
.apply(TopLevelResource.INSTANCE, in);
return projectApi.create(projects.parse(name));
} catch (IOException | ConfigInvalidException e) {
@@ -221,13 +220,12 @@ public class ProjectApiImpl implements ProjectApi {
private List<BranchInfo> listBranches(ListRefsRequest<BranchInfo> request)
throws RestApiException {
ListBranches list = listBranchesProvider.get();
list.setLimit(request.getLimit());
list.setStart(request.getStart());
list.setMatchSubstring(request.getSubstring());
list.setMatchRegex(request.getRegex());
listBranches.setLimit(request.getLimit());
listBranches.setStart(request.getStart());
listBranches.setMatchSubstring(request.getSubstring());
listBranches.setMatchRegex(request.getRegex());
try {
return list.apply(checkExists());
return listBranches.apply(checkExists());
} catch (IOException e) {
throw new RestApiException("Cannot list branches", e);
}
@@ -245,13 +243,12 @@ public class ProjectApiImpl implements ProjectApi {
private List<TagInfo> listTags(ListRefsRequest<TagInfo> request)
throws RestApiException {
ListTags list = listTagsProvider.get();
list.setLimit(request.getLimit());
list.setStart(request.getStart());
list.setMatchSubstring(request.getSubstring());
list.setMatchRegex(request.getRegex());
listTags.setLimit(request.getLimit());
listTags.setStart(request.getStart());
listTags.setMatchSubstring(request.getSubstring());
listTags.setMatchRegex(request.getRegex());
try {
return list.apply(checkExists());
return listTags.apply(checkExists());
} catch (IOException e) {
throw new RestApiException("Cannot list tags", e);
}