Format all Java files with google-java-format Change-Id: Ie4374d90cd7125aa79909b7edd228c243617d866
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/BaseAction.java b/src/main/java/com/googlesource/gerrit/plugins/wip/BaseAction.java index 5e18d9d..4649181 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/BaseAction.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/BaseAction.java
@@ -27,14 +27,13 @@ import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.index.change.ChangeIndexer; import com.google.gerrit.server.notedb.ChangeUpdate; -import com.google.gwtorm.server.OrmException; import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.BatchUpdateOp; import com.google.gerrit.server.update.ChangeContext; import com.google.gerrit.server.update.UpdateException; +import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; - import java.io.IOException; import java.util.Collections; @@ -49,7 +48,8 @@ private final BatchUpdate.Factory batchUpdateFactory; @Inject - BaseAction(Provider<ReviewDb> dbProvider, + BaseAction( + Provider<ReviewDb> dbProvider, Provider<CurrentUser> userProvider, ChangeIndexer indexer, BatchUpdate.Factory batchUpdateFactory) { @@ -59,31 +59,32 @@ this.batchUpdateFactory = batchUpdateFactory; } - protected void changeStatus(Change change, final PatchSet.Id psId, - Input input, final Status from, final Status to) + protected void changeStatus( + Change change, final PatchSet.Id psId, Input input, final Status from, final Status to) throws OrmException, RestApiException, IOException, UpdateException { ReviewDb db = dbProvider.get(); Change.Id changeId = change.getId(); db.changes().beginTransaction(changeId); - try (BatchUpdate bu = batchUpdateFactory.create( - db, change.getProject(), userProvider.get(), TimeUtil.nowTs())) { - bu.addOp(change.getId(), new BatchUpdateOp() { - @Override - public boolean updateChange(ChangeContext ctx) { - Change change = ctx.getChange(); - ChangeUpdate update = ctx.getUpdate(psId); - if (change.getStatus() == from) { - change.setStatus(to); - update.setStatus(change.getStatus()); - return true; - } - return false; - } - }); + try (BatchUpdate bu = + batchUpdateFactory.create(db, change.getProject(), userProvider.get(), TimeUtil.nowTs())) { + bu.addOp( + change.getId(), + new BatchUpdateOp() { + @Override + public boolean updateChange(ChangeContext ctx) { + Change change = ctx.getChange(); + ChangeUpdate update = ctx.getUpdate(psId); + if (change.getStatus() == from) { + change.setStatus(to); + update.setStatus(change.getStatus()); + return true; + } + return false; + } + }); bu.execute(); - db.changeMessages().insert(Collections.singleton( - newMessage(input, change))); + db.changeMessages().insert(Collections.singleton(newMessage(input, change))); db.commit(); } finally { @@ -93,11 +94,10 @@ indexer.index(db, change); } - private ChangeMessage newMessage(Input input, - Change change) throws OrmException { - StringBuilder buf = new StringBuilder(change.getStatus() == Status.DRAFT - ? "Work In Progress" - : "Ready For Review"); + private ChangeMessage newMessage(Input input, Change change) throws OrmException { + StringBuilder buf = + new StringBuilder( + change.getStatus() == Status.DRAFT ? "Work In Progress" : "Ready For Review"); String msg = Strings.nullToEmpty(input.message).trim(); if (!msg.isEmpty()) { @@ -105,20 +105,17 @@ buf.append(msg); } - ChangeMessage message = new ChangeMessage( - new ChangeMessage.Key( - change.getId(), - ChangeUtil.messageUuid()), - ((IdentifiedUser)userProvider.get()).getAccountId(), - change.getLastUpdatedOn(), - change.currentPatchSetId()); + ChangeMessage message = + new ChangeMessage( + new ChangeMessage.Key(change.getId(), ChangeUtil.messageUuid()), + ((IdentifiedUser) userProvider.get()).getAccountId(), + change.getLastUpdatedOn(), + change.currentPatchSetId()); message.setMessage(msg.toString()); return message; } protected static String status(Change change) { - return change != null - ? change.getStatus().name().toLowerCase() - : "deleted"; + return change != null ? change.getStatus().name().toLowerCase() : "deleted"; } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/wip/HttpModule.java index 387c747..9df62f8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/HttpModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/HttpModule.java
@@ -22,7 +22,6 @@ class HttpModule extends HttpPluginModule { @Override protected void configureServlets() { - DynamicSet.bind(binder(), WebUiPlugin.class) - .toInstance(new JavaScriptPlugin("wip.js")); + DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("wip.js")); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/Module.java b/src/main/java/com/googlesource/gerrit/plugins/wip/Module.java index 2a3d06d..64b2281 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/Module.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/Module.java
@@ -23,14 +23,13 @@ @Override protected void configure() { - install(new RestApiModule() { - @Override - protected void configure() { - post(REVISION_KIND, "set-wip") - .to(WorkInProgress.class); - post(REVISION_KIND, "set-ready") - .to(ReadyForReview.class); - } - }); + install( + new RestApiModule() { + @Override + protected void configure() { + post(REVISION_KIND, "set-wip").to(WorkInProgress.class); + post(REVISION_KIND, "set-ready").to(ReadyForReview.class); + } + }); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/ReadyForReview.java b/src/main/java/com/googlesource/gerrit/plugins/wip/ReadyForReview.java index 17db46d..0595c94 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/ReadyForReview.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/ReadyForReview.java
@@ -14,8 +14,6 @@ package com.googlesource.gerrit.plugins.wip; -import java.io.IOException; - import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestApiException; @@ -28,18 +26,19 @@ import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.index.change.ChangeIndexer; -import com.google.gwtorm.server.OrmException; import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.UpdateException; +import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; +import java.io.IOException; -class ReadyForReview extends BaseAction implements - UiAction<RevisionResource>, - RestModifyView<RevisionResource, BaseAction.Input> { +class ReadyForReview extends BaseAction + implements UiAction<RevisionResource>, RestModifyView<RevisionResource, BaseAction.Input> { @Inject - ReadyForReview(Provider<ReviewDb> dbProvider, + ReadyForReview( + Provider<ReviewDb> dbProvider, Provider<CurrentUser> userProvider, ChangeIndexer indexer, BatchUpdate.Factory batchUpdateFactory) { @@ -58,8 +57,7 @@ throw new ResourceConflictException("not current patch set"); } - changeStatus(change, rsrc.getPatchSet().getId(), input, Status.DRAFT, - Status.NEW); + changeStatus(change, rsrc.getPatchSet().getId(), input, Status.DRAFT, Status.NEW); return Response.none(); } @@ -69,8 +67,9 @@ return new Description() .setLabel("Ready") .setTitle("Set Ready For Review") - .setVisible(rsrc.getControl().isOwner() - && rsrc.getChange().getStatus() == Status.DRAFT - && rsrc.getPatchSet().getId().equals(current)); + .setVisible( + rsrc.getControl().isOwner() + && rsrc.getChange().getStatus() == Status.DRAFT + && rsrc.getPatchSet().getId().equals(current)); } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/SetCommand.java b/src/main/java/com/googlesource/gerrit/plugins/wip/SetCommand.java index 071aa84..2693c58 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/SetCommand.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/SetCommand.java
@@ -28,25 +28,27 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; - +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - @CommandMetaData(name = "set", description = "Mark the change as WIP or Ready") class SetCommand extends SshCommand { private static final Logger log = LoggerFactory.getLogger(SetCommand.class); private final Set<PatchSet> patchSets = new HashSet<>(); - @Argument(index = 0, required = true, multiValued = true, - metaVar = "{COMMIT | CHANGE,PATCHSET}", - usage = "list of commits or patch sets to review") + @Argument( + index = 0, + required = true, + multiValued = true, + metaVar = "{COMMIT | CHANGE,PATCHSET}", + usage = "list of commits or patch sets to review" + ) void addPatchSetId(String token) { try { PatchSet ps = psParser.parsePatchSet(token, projectControl, branch); @@ -58,39 +60,43 @@ } } - @Option(name = "--project", aliases = "-p", - usage = "project containing the specified patch set(s)") + @Option( + name = "--project", + aliases = "-p", + usage = "project containing the specified patch set(s)" + ) private ProjectControl projectControl; @Option(name = "--branch", aliases = "-b", usage = "branch containing the specified patch set(s)") private String branch; - @Option(name = "--message", aliases = "-m", - usage = "cover message on change(s)", metaVar = "MESSAGE") + @Option( + name = "--message", + aliases = "-m", + usage = "cover message on change(s)", + metaVar = "MESSAGE" + ) private String changeComment; - @Option(name = "--wip", aliases = "-w", - usage = "mark the specified change(s) as WIP") + @Option(name = "--wip", aliases = "-w", usage = "mark the specified change(s) as WIP") private boolean wipChange; - @Option(name = "--readyChange", aliases = "-r", - usage = "mark the specified change(s) as Ready for Review") + @Option( + name = "--readyChange", + aliases = "-r", + usage = "mark the specified change(s) as Ready for Review" + ) private boolean readyChange; - @Inject - private Provider<WorkInProgress> wipProvider; + @Inject private Provider<WorkInProgress> wipProvider; - @Inject - private Provider<ReadyForReview> readyProvider; + @Inject private Provider<ReadyForReview> readyProvider; - @Inject - ChangeIndexer indexer; + @Inject ChangeIndexer indexer; - @Inject - ChangesCollection changes; + @Inject ChangesCollection changes; - @Inject - PatchSetParser psParser; + @Inject PatchSetParser psParser; @Override protected void run() throws UnloggedFailure { @@ -105,11 +111,9 @@ for (PatchSet patchSet : patchSets) { try { mark(patchSet); - } catch (RestApiException | IOException - | OrmException | UpdateException e) { + } catch (RestApiException | IOException | OrmException | UpdateException e) { ok = false; - writeError("fatal: internal server error while approving " - + patchSet.getId() + "\n"); + writeError("fatal: internal server error while approving " + patchSet.getId() + "\n"); log.error("internal error while approving " + patchSet.getId(), e); } } @@ -119,11 +123,11 @@ } } - private void mark(PatchSet patchSet) throws ResourceConflictException, - OrmException, IOException, RestApiException, UpdateException { + private void mark(PatchSet patchSet) + throws ResourceConflictException, OrmException, IOException, RestApiException, + UpdateException { RevisionResource rsrc = - new RevisionResource(changes.parse(patchSet.getId().getParentKey()), - patchSet); + new RevisionResource(changes.parse(patchSet.getId().getParentKey()), patchSet); BaseAction.Input input = new BaseAction.Input(); input.message = changeComment; if (wipChange) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/wip/WorkInProgress.java b/src/main/java/com/googlesource/gerrit/plugins/wip/WorkInProgress.java index f4d03ba..3777fd8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/wip/WorkInProgress.java +++ b/src/main/java/com/googlesource/gerrit/plugins/wip/WorkInProgress.java
@@ -14,8 +14,6 @@ package com.googlesource.gerrit.plugins.wip; -import java.io.IOException; - import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestApiException; @@ -33,13 +31,14 @@ import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; +import java.io.IOException; -class WorkInProgress extends BaseAction implements - UiAction<RevisionResource>, - RestModifyView<RevisionResource, BaseAction.Input> { +class WorkInProgress extends BaseAction + implements UiAction<RevisionResource>, RestModifyView<RevisionResource, BaseAction.Input> { @Inject - WorkInProgress(Provider<ReviewDb> dbProvider, + WorkInProgress( + Provider<ReviewDb> dbProvider, Provider<CurrentUser> userProvider, ChangeIndexer indexer, BatchUpdate.Factory batchUpdateFactory) { @@ -58,8 +57,7 @@ throw new ResourceConflictException("not current patch set"); } - changeStatus(change, rsrc.getPatchSet().getId(), input, Status.NEW, - Status.DRAFT); + changeStatus(change, rsrc.getPatchSet().getId(), input, Status.NEW, Status.DRAFT); return Response.none(); } @@ -69,8 +67,9 @@ return new Description() .setLabel("WIP") .setTitle("Set Work In Progress") - .setVisible(rsrc.getControl().isOwner() - && rsrc.getChange().getStatus() == Status.NEW - && rsrc.getPatchSet().getId().equals(current)); + .setVisible( + rsrc.getControl().isOwner() + && rsrc.getChange().getStatus() == Status.NEW + && rsrc.getPatchSet().getId().equals(current)); } }