Merge changes Ieda2c06c,I198f5941,I6b0d658d

* changes:
  RevisionApi: Convert some methods to default methods
  RevisionApi: Document that files(String) takes a nullable arg
  ChangeApi: Convert some methods to default methods
This commit is contained in:
David Pursehouse
2018-11-08 09:10:17 +00:00
committed by Gerrit Code Review
5 changed files with 88 additions and 262 deletions

View File

@@ -49,17 +49,21 @@ public interface ChangeApi {
* @return API for accessing the revision.
* @throws RestApiException if an error occurred.
*/
RevisionApi current() throws RestApiException;
default RevisionApi current() throws RestApiException {
return revision("current");
}
/**
* Look up a revision of a change by number.
*
* @see #current()
*/
RevisionApi revision(int id) throws RestApiException;
default RevisionApi revision(int id) throws RestApiException {
return revision(Integer.toString(id));
}
/**
* Look up a revision of a change by commit SHA-1.
* Look up a revision of a change by commit SHA-1 or other supported revision string.
*
* @see #current()
*/
@@ -79,15 +83,23 @@ public interface ChangeApi {
*/
ReviewerApi reviewer(String id) throws RestApiException;
void abandon() throws RestApiException;
default void abandon() throws RestApiException {
abandon(new AbandonInput());
}
void abandon(AbandonInput in) throws RestApiException;
void restore() throws RestApiException;
default void restore() throws RestApiException {
restore(new RestoreInput());
}
void restore(RestoreInput in) throws RestApiException;
void move(String destination) throws RestApiException;
default void move(String destination) throws RestApiException {
MoveInput in = new MoveInput();
in.destinationBranch = destination;
move(in);
}
void move(MoveInput in) throws RestApiException;
@@ -132,7 +144,9 @@ public interface ChangeApi {
*
* @see Changes#id(int)
*/
ChangeApi revert() throws RestApiException;
default ChangeApi revert() throws RestApiException {
return revert(new RevertInput());
}
/**
* Create a new change that reverts this change.
@@ -144,10 +158,17 @@ public interface ChangeApi {
/** Create a merge patch set for the change. */
ChangeInfo createMergePatchSet(MergePatchSetInput in) throws RestApiException;
List<ChangeInfo> submittedTogether() throws RestApiException;
default List<ChangeInfo> submittedTogether() throws RestApiException {
SubmittedTogetherInfo info =
submittedTogether(
EnumSet.noneOf(ListChangesOption.class), EnumSet.noneOf(SubmittedTogetherOption.class));
return info.changes;
}
SubmittedTogetherInfo submittedTogether(EnumSet<SubmittedTogetherOption> options)
throws RestApiException;
default SubmittedTogetherInfo submittedTogether(EnumSet<SubmittedTogetherOption> options)
throws RestApiException {
return submittedTogether(EnumSet.noneOf(ListChangesOption.class), options);
}
SubmittedTogetherInfo submittedTogether(
EnumSet<ListChangesOption> listOptions, EnumSet<SubmittedTogetherOption> submitOptions)
@@ -155,10 +176,14 @@ public interface ChangeApi {
/** Publishes a draft change. */
@Deprecated
void publish() throws RestApiException;
default void publish() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
/** Rebase the current revision of a change using default options. */
void rebase() throws RestApiException;
default void rebase() throws RestApiException {
rebase(new RebaseInput());
}
/** Rebase the current revision of a change. */
void rebase(RebaseInput in) throws RestApiException;
@@ -172,13 +197,19 @@ public interface ChangeApi {
IncludedInInfo includedIn() throws RestApiException;
AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException;
default AddReviewerResult addReviewer(String reviewer) throws RestApiException {
AddReviewerInput in = new AddReviewerInput();
in.reviewer = reviewer;
return addReviewer(in);
}
AddReviewerResult addReviewer(String in) throws RestApiException;
AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException;
SuggestedReviewersRequest suggestReviewers() throws RestApiException;
SuggestedReviewersRequest suggestReviewers(String query) throws RestApiException;
default SuggestedReviewersRequest suggestReviewers(String query) throws RestApiException {
return suggestReviewers().withQuery(query);
}
ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException;
@@ -198,10 +229,16 @@ public interface ChangeApi {
* <li>{@code SKIP_MERGEABLE} is omitted, so the {@code mergeable} bit <em>is</em> set.
* </ul>
*/
ChangeInfo get() throws RestApiException;
default ChangeInfo get() throws RestApiException {
return get(
EnumSet.complementOf(
EnumSet.of(ListChangesOption.CHECK, ListChangesOption.SKIP_MERGEABLE)));
}
/** {@link #get(ListChangesOption...)} with no options included. */
ChangeInfo info() throws RestApiException;
default ChangeInfo info() throws RestApiException {
return get(EnumSet.noneOf(ListChangesOption.class));
}
/**
* Retrieve change edit when exists.
@@ -210,7 +247,9 @@ public interface ChangeApi {
* ChangeEditApi#get()}.
*/
@Deprecated
EditInfo getEdit() throws RestApiException;
default EditInfo getEdit() throws RestApiException {
return edit().get().orElse(null);
}
/**
* Provides access to an API regarding the change edit of this change.
@@ -221,7 +260,11 @@ public interface ChangeApi {
ChangeEditApi edit() throws RestApiException;
/** Create a new patch set with a new commit message. */
void setMessage(String message) throws RestApiException;
default void setMessage(String message) throws RestApiException {
CommitMessageInput in = new CommitMessageInput();
in.message = message;
setMessage(in);
}
/** Create a new patch set with a new commit message. */
void setMessage(CommitMessageInput in) throws RestApiException;
@@ -346,16 +389,6 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public RevisionApi current() throws RestApiException {
throw new NotImplementedException();
}
@Override
public RevisionApi revision(int id) throws RestApiException {
throw new NotImplementedException();
}
@Override
public ReviewerApi reviewer(String id) throws RestApiException {
throw new NotImplementedException();
@@ -366,31 +399,16 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public void abandon() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void abandon(AbandonInput in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void restore() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void restore(RestoreInput in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void move(String destination) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void move(MoveInput in) throws RestApiException {
throw new NotImplementedException();
@@ -411,27 +429,11 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public ChangeApi revert() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeApi revert(RevertInput in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void publish() throws RestApiException {
throw new NotImplementedException();
}
@Deprecated
@Override
public void rebase() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void rebase(RebaseInput in) throws RestApiException {
throw new NotImplementedException();
@@ -462,51 +464,21 @@ public interface ChangeApi {
throw new NotImplementedException();
}
@Override
public AddReviewerResult addReviewer(String in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public SuggestedReviewersRequest suggestReviewers() throws RestApiException {
throw new NotImplementedException();
}
@Override
public SuggestedReviewersRequest suggestReviewers(String query) throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeInfo get(EnumSet<ListChangesOption> options) throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeInfo get() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeInfo info() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void setMessage(String message) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void setMessage(CommitMessageInput in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public EditInfo getEdit() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeEditApi edit() throws RestApiException {
throw new NotImplementedException();

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.extensions.api.changes;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.ActionInfo;
import com.google.gerrit.extensions.common.CherryPickChangeInfo;
@@ -34,7 +35,9 @@ import java.util.Set;
public interface RevisionApi {
@Deprecated
void delete() throws RestApiException;
default void delete() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
String description() throws RestApiException;
@@ -42,22 +45,32 @@ public interface RevisionApi {
ReviewResult review(ReviewInput in) throws RestApiException;
void submit() throws RestApiException;
default void submit() throws RestApiException {
SubmitInput in = new SubmitInput();
submit(in);
}
void submit(SubmitInput in) throws RestApiException;
BinaryResult submitPreview() throws RestApiException;
default BinaryResult submitPreview() throws RestApiException {
return submitPreview("zip");
}
BinaryResult submitPreview(String format) throws RestApiException;
@Deprecated
void publish() throws RestApiException;
default void publish() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
ChangeApi cherryPick(CherryPickInput in) throws RestApiException;
CherryPickChangeInfo cherryPickAsInfo(CherryPickInput in) throws RestApiException;
ChangeApi rebase() throws RestApiException;
default ChangeApi rebase() throws RestApiException {
RebaseInput in = new RebaseInput();
return rebase(in);
}
ChangeApi rebase(RebaseInput in) throws RestApiException;
@@ -69,9 +82,11 @@ public interface RevisionApi {
Set<String> reviewed() throws RestApiException;
Map<String, FileInfo> files() throws RestApiException;
default Map<String, FileInfo> files() throws RestApiException {
return files(null);
}
Map<String, FileInfo> files(String base) throws RestApiException;
Map<String, FileInfo> files(@Nullable String base) throws RestApiException;
Map<String, FileInfo> files(int parentNum) throws RestApiException;
@@ -165,33 +180,16 @@ public interface RevisionApi {
* interface.
*/
class NotImplemented implements RevisionApi {
@Deprecated
@Override
public void delete() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ReviewResult review(ReviewInput in) throws RestApiException {
throw new NotImplementedException();
}
@Override
public void submit() throws RestApiException {
throw new NotImplementedException();
}
@Override
public void submit(SubmitInput in) throws RestApiException {
throw new NotImplementedException();
}
@Deprecated
@Override
public void publish() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
throw new NotImplementedException();
@@ -202,11 +200,6 @@ public interface RevisionApi {
throw new NotImplementedException();
}
@Override
public ChangeApi rebase() throws RestApiException {
throw new NotImplementedException();
}
@Override
public ChangeApi rebase(RebaseInput in) throws RestApiException {
throw new NotImplementedException();
@@ -252,11 +245,6 @@ public interface RevisionApi {
throw new NotImplementedException();
}
@Override
public Map<String, FileInfo> files() throws RestApiException {
throw new NotImplementedException();
}
@Override
public List<String> queryFiles(String query) throws RestApiException {
throw new NotImplementedException();
@@ -347,11 +335,6 @@ public interface RevisionApi {
throw new NotImplementedException();
}
@Override
public BinaryResult submitPreview() throws RestApiException {
throw new NotImplementedException();
}
@Override
public BinaryResult submitPreview(String format) throws RestApiException {
throw new NotImplementedException();

View File

@@ -43,7 +43,6 @@ import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeMessageInfo;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.common.CommitMessageInput;
import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.extensions.common.Input;
import com.google.gerrit.extensions.common.MergePatchSetInput;
import com.google.gerrit.extensions.common.PureRevertInfo;
@@ -255,16 +254,6 @@ class ChangeApiImpl implements ChangeApi {
return Integer.toString(change.getId().get());
}
@Override
public RevisionApi current() throws RestApiException {
return revision("current");
}
@Override
public RevisionApi revision(int id) throws RestApiException {
return revision(String.valueOf(id));
}
@Override
public RevisionApi revision(String id) throws RestApiException {
try {
@@ -283,11 +272,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public void abandon() throws RestApiException {
abandon(new AbandonInput());
}
@Override
public void abandon(AbandonInput in) throws RestApiException {
try {
@@ -297,11 +281,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public void restore() throws RestApiException {
restore(new RestoreInput());
}
@Override
public void restore(RestoreInput in) throws RestApiException {
try {
@@ -311,13 +290,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public void move(String destination) throws RestApiException {
MoveInput in = new MoveInput();
in.destinationBranch = destination;
move(in);
}
@Override
public void move(MoveInput in) throws RestApiException {
try {
@@ -359,11 +331,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public ChangeApi revert() throws RestApiException {
return revert(new RevertInput());
}
@Override
public ChangeApi revert(RevertInput in) throws RestApiException {
try {
@@ -382,20 +349,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public List<ChangeInfo> submittedTogether() throws RestApiException {
SubmittedTogetherInfo info =
submittedTogether(
EnumSet.noneOf(ListChangesOption.class), EnumSet.noneOf(SubmittedTogetherOption.class));
return info.changes;
}
@Override
public SubmittedTogetherInfo submittedTogether(EnumSet<SubmittedTogetherOption> options)
throws RestApiException {
return submittedTogether(EnumSet.noneOf(ListChangesOption.class), options);
}
@Override
public SubmittedTogetherInfo submittedTogether(
EnumSet<ListChangesOption> listOptions, EnumSet<SubmittedTogetherOption> submitOptions)
@@ -411,17 +364,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Deprecated
@Override
public void publish() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
@Override
public void rebase() throws RestApiException {
rebase(new RebaseInput());
}
@Override
public void rebase(RebaseInput in) throws RestApiException {
try {
@@ -465,13 +407,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public AddReviewerResult addReviewer(String reviewer) throws RestApiException {
AddReviewerInput in = new AddReviewerInput();
in.reviewer = reviewer;
return addReviewer(in);
}
@Override
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
try {
@@ -491,11 +426,6 @@ class ChangeApiImpl implements ChangeApi {
};
}
@Override
public SuggestedReviewersRequest suggestReviewers(String query) throws RestApiException {
return suggestReviewers().withQuery(query);
}
private List<SuggestedReviewerInfo> suggestReviewers(SuggestedReviewersRequest r)
throws RestApiException {
try {
@@ -516,30 +446,11 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public ChangeInfo get() throws RestApiException {
return get(
EnumSet.complementOf(
EnumSet.of(ListChangesOption.CHECK, ListChangesOption.SKIP_MERGEABLE)));
}
@Override
public EditInfo getEdit() throws RestApiException {
return edit().get().orElse(null);
}
@Override
public ChangeEditApi edit() throws RestApiException {
return changeEditApi.create(change);
}
@Override
public void setMessage(String msg) throws RestApiException {
CommitMessageInput in = new CommitMessageInput();
in.message = msg;
setMessage(in);
}
@Override
public void setMessage(CommitMessageInput in) throws RestApiException {
try {
@@ -549,11 +460,6 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public ChangeInfo info() throws RestApiException {
return get(EnumSet.noneOf(ListChangesOption.class));
}
@Override
public void setHashtags(HashtagsInput input) throws RestApiException {
try {

View File

@@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.changes.CherryPickInput;
@@ -226,12 +227,6 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public void submit() throws RestApiException {
SubmitInput in = new SubmitInput();
submit(in);
}
@Override
public void submit(SubmitInput in) throws RestApiException {
try {
@@ -241,11 +236,6 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public BinaryResult submitPreview() throws RestApiException {
return submitPreview("zip");
}
@Override
public BinaryResult submitPreview(String format) throws RestApiException {
try {
@@ -256,22 +246,6 @@ class RevisionApiImpl implements RevisionApi {
}
}
@Override
public void publish() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
@Override
public void delete() throws RestApiException {
throw new UnsupportedOperationException("draft workflow is discontinued");
}
@Override
public ChangeApi rebase() throws RestApiException {
RebaseInput in = new RebaseInput();
return rebase(in);
}
@Override
public ChangeApi rebase(RebaseInput in) throws RestApiException {
try {
@@ -366,17 +340,7 @@ class RevisionApiImpl implements RevisionApi {
@SuppressWarnings("unchecked")
@Override
public Map<String, FileInfo> files() throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.apply(revision).value();
} catch (Exception e) {
throw asRestApiException("Cannot retrieve files", e);
}
}
@SuppressWarnings("unchecked")
@Override
public Map<String, FileInfo> files(String base) throws RestApiException {
public Map<String, FileInfo> files(@Nullable String base) throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.setBase(base).apply(revision).value();
} catch (Exception e) {

View File

@@ -18,6 +18,7 @@ import com.google.common.collect.Lists;
import com.google.common.flogger.FluentLogger;
import com.google.common.hash.Hasher;
import com.google.common.hash.Hashing;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.common.FileInfo;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.AuthException;
@@ -332,7 +333,7 @@ public class Files implements ChildCollection<RevisionResource, FileResource> {
return this;
}
public ListFiles setBase(String base) {
public ListFiles setBase(@Nullable String base) {
this.base = base;
return this;
}