Format all Java files with google-java-format
Change-Id: Ic726e55d416c3ceda674111b20fdc985c857c245
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/CommitReceived.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/CommitReceived.java
index bca5ab6..5d8d852 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/CommitReceived.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/CommitReceived.java
@@ -24,11 +24,9 @@
import com.google.gerrit.server.git.validators.CommitValidationListener;
import com.google.gerrit.server.git.validators.CommitValidationMessage;
import com.google.inject.Inject;
-
-import org.eclipse.jgit.lib.ObjectId;
-
import java.util.Collections;
import java.util.List;
+import org.eclipse.jgit.lib.ObjectId;
public class CommitReceived implements CommitValidationListener {
private final SynchronousHook hook;
@@ -41,8 +39,8 @@
}
@Override
- public List<CommitValidationMessage> onCommitReceived(
- CommitReceivedEvent receiveEvent) throws CommitValidationException {
+ public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
+ throws CommitValidationException {
IdentifiedUser user = receiveEvent.user;
String refname = receiveEvent.refName;
ObjectId old = ObjectId.zeroId();
@@ -52,13 +50,13 @@
if (receiveEvent.command.getRefName().startsWith(REFS_CHANGES)) {
/*
- * If the ref-update hook tries to distinguish behavior between pushes to
- * refs/heads/... and refs/for/..., make sure we send it the correct
- * refname.
- * Also, if this is targetting refs/for/, make sure we behave the same as
- * what a push to refs/for/ would behave; in particular, setting oldrev
- * to 0000000000000000000000000000000000000000.
- */
+ * If the ref-update hook tries to distinguish behavior between pushes to
+ * refs/heads/... and refs/for/..., make sure we send it the correct
+ * refname.
+ * Also, if this is targetting refs/for/, make sure we behave the same as
+ * what a push to refs/for/ would behave; in particular, setting oldrev
+ * to 0000000000000000000000000000000000000000.
+ */
refname = refname.replace(R_HEADS, "refs/for/refs/heads/");
old = ObjectId.zeroId();
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HashtagsEdited.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HashtagsEdited.java
index 439fcf5..e781833 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HashtagsEdited.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HashtagsEdited.java
@@ -18,7 +18,6 @@
import com.google.gerrit.extensions.events.HashtagsEditedListener;
import com.google.inject.Inject;
import com.google.inject.Singleton;
-
import java.util.Collection;
@Singleton
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
index f68395c..61af73b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
@@ -22,7 +22,6 @@
import com.google.gerrit.extensions.common.ApprovalInfo;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.inject.Provider;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -33,8 +32,7 @@
private final HookMetrics metrics;
private final List<String> args;
- HookArgs(String anonymousCowardName, Provider<String> urlProvider,
- HookMetrics metrics) {
+ HookArgs(String anonymousCowardName, Provider<String> urlProvider, HookMetrics metrics) {
this.anonymousCowardName = anonymousCowardName;
this.urlProvider = urlProvider;
this.metrics = metrics;
@@ -86,8 +84,8 @@
}
}
- public void addApprovals(Map<String, ApprovalInfo> approvals,
- Map<String, ApprovalInfo> oldApprovals) {
+ public void addApprovals(
+ Map<String, ApprovalInfo> approvals, Map<String, ApprovalInfo> oldApprovals) {
for (Map.Entry<String, ApprovalInfo> approval : approvals.entrySet()) {
if (approval.getValue() != null) {
args.add("--" + approval.getKey());
@@ -104,12 +102,9 @@
}
private String format(AccountInfo account) {
- StringBuilder who = new StringBuilder(
- firstNonNull(account.name, anonymousCowardName));
+ StringBuilder who = new StringBuilder(firstNonNull(account.name, anonymousCowardName));
if (account.email != null) {
- who.append(" (")
- .append(account.email)
- .append(")");
+ who.append(" (").append(account.email).append(")");
}
return who.toString();
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java
index ba5ee70..3765128 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookExecutor.java
@@ -6,11 +6,6 @@
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
-
-import org.eclipse.jgit.lib.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.lang.Thread.UncaughtExceptionHandler;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -19,16 +14,17 @@
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.eclipse.jgit.lib.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class HookExecutor implements LifecycleListener {
- private static final Logger log =
- LoggerFactory.getLogger(HookExecutor.class);
+ private static final Logger log = LoggerFactory.getLogger(HookExecutor.class);
private static final UncaughtExceptionHandler LOG_UNCAUGHT_EXCEPTION =
new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
- log.error("HookExecutor thread " + t.getName()
- + " threw exception", e);
+ log.error("HookExecutor thread " + t.getName() + " threw exception", e);
}
};
@@ -38,18 +34,18 @@
private final int timeout;
@Inject
- HookExecutor(@GerritServerConfig Config config,
- SitePaths sitePaths,
- GitRepositoryManager gitManager) {
+ HookExecutor(
+ @GerritServerConfig Config config, SitePaths sitePaths, GitRepositoryManager gitManager) {
this.sitePaths = sitePaths;
this.gitManager = gitManager;
this.timeout = config.getInt("hooks", "syncHookTimeout", 30);
- this.threadPool = Executors.newCachedThreadPool(
- new ThreadFactoryBuilder()
- .setNameFormat("SyncHook-%d")
- .setUncaughtExceptionHandler(LOG_UNCAUGHT_EXCEPTION)
- .build());
+ this.threadPool =
+ Executors.newCachedThreadPool(
+ new ThreadFactoryBuilder()
+ .setNameFormat("SyncHook-%d")
+ .setUncaughtExceptionHandler(LOG_UNCAUGHT_EXCEPTION)
+ .build());
}
HookResult submit(Path hook, HookArgs args) {
@@ -60,8 +56,8 @@
if (!Files.exists(hook)) {
return null;
}
- HookTask.Sync hookTask = new HookTask.Sync(
- gitManager, sitePaths.site_path, projectName, hook, args);
+ HookTask.Sync hookTask =
+ new HookTask.Sync(gitManager, sitePaths.site_path, projectName, hook, args);
FutureTask<HookResult> task = new FutureTask<>(hookTask);
threadPool.execute(task);
String message;
@@ -69,7 +65,7 @@
try {
return task.get(timeout, TimeUnit.SECONDS);
} catch (TimeoutException e) {
- message = "Synchronous hook timed out " + hook.toAbsolutePath();
+ message = "Synchronous hook timed out " + hook.toAbsolutePath();
log.error(message);
} catch (Exception e) {
message = "Error running hook " + hook.toAbsolutePath();
@@ -82,8 +78,7 @@
}
@Override
- public void start() {
- }
+ public void start() {}
@Override
public void stop() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java
index 61207b8..210c588 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookFactory.java
@@ -24,11 +24,9 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
-
-import org.eclipse.jgit.lib.Config;
-
import java.nio.file.Path;
import java.nio.file.Paths;
+import org.eclipse.jgit.lib.Config;
@Singleton
public class HookFactory {
@@ -41,7 +39,8 @@
private final Path hooksPath;
@Inject
- HookFactory(HookQueue queue,
+ HookFactory(
+ HookQueue queue,
HookExecutor syncHookExecutor,
@GerritServerConfig Config config,
@AnonymousCowardName String anonymousCowardName,
@@ -73,8 +72,7 @@
}
public SynchronousHook createSync(String configName, String defaultName) {
- return new SynchronousHook(
- syncHookExecutor, getHookPath(configName, defaultName));
+ return new SynchronousHook(syncHookExecutor, getHookPath(configName, defaultName));
}
public HookArgs createArgs() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
index 066def0..9b0bc82 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookMetrics.java
@@ -32,23 +32,19 @@
@Inject
HookMetrics(MetricMaker metricMaker) {
Field<String> field = Field.ofString("hook");
- latency = metricMaker.newTimer("latency",
- new Description("Time spent executing a hook")
- .setCumulative()
- .setUnit(Description.Units.MILLISECONDS),
- field);
- count = metricMaker.newCounter("count",
- new Description("Hook executions")
- .setRate(),
- field);
- error = metricMaker.newCounter("error",
- new Description("Hook execution errors")
- .setRate(),
- field);
- timeout = metricMaker.newCounter("timeout",
- new Description("Hook execution timeouts")
- .setRate(),
- field);
+ latency =
+ metricMaker.newTimer(
+ "latency",
+ new Description("Time spent executing a hook")
+ .setCumulative()
+ .setUnit(Description.Units.MILLISECONDS),
+ field);
+ count = metricMaker.newCounter("count", new Description("Hook executions").setRate(), field);
+ error =
+ metricMaker.newCounter("error", new Description("Hook execution errors").setRate(), field);
+ timeout =
+ metricMaker.newCounter(
+ "timeout", new Description("Hook execution timeouts").setRate(), field);
}
public Timer1.Context start(String name) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
index 0b9c387..9f06cd1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookQueue.java
@@ -19,7 +19,6 @@
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.WorkQueue;
import com.google.inject.Inject;
-
import java.nio.file.Files;
import java.nio.file.Path;
@@ -31,9 +30,7 @@
private WorkQueue.Executor queue;
@Inject
- HookQueue(GitRepositoryManager m,
- WorkQueue q,
- SitePaths s) {
+ HookQueue(GitRepositoryManager m, WorkQueue q, SitePaths s) {
gitManager = m;
workQueue = q;
sitePaths = s;
@@ -45,12 +42,7 @@
void submit(String projectName, Path hook, HookArgs args) {
if (Files.exists(hook)) {
- queue.submit(new HookTask.Async(
- gitManager,
- sitePaths.site_path,
- projectName,
- hook,
- args));
+ queue.submit(new HookTask.Async(gitManager, sitePaths.site_path, projectName, hook, args));
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
index 6e87d3d..7b59630 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookTask.java
@@ -20,11 +20,6 @@
import com.google.gerrit.metrics.Timer1;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.GitRepositoryManager;
-
-import org.eclipse.jgit.lib.Repository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
@@ -34,6 +29,9 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
+import org.eclipse.jgit.lib.Repository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
class HookTask {
private static final Logger log = LoggerFactory.getLogger(HookTask.class);
@@ -48,8 +46,12 @@
private Process ps;
public static class Async extends HookTask implements Runnable {
- Async(GitRepositoryManager gitManager, Path sitePath, String projectName,
- Path hook, HookArgs args) {
+ Async(
+ GitRepositoryManager gitManager,
+ Path sitePath,
+ String projectName,
+ Path hook,
+ HookArgs args) {
super(gitManager, sitePath, projectName, hook, args);
}
@@ -60,8 +62,12 @@
}
public static class Sync extends HookTask implements Callable<HookResult> {
- Sync(GitRepositoryManager gitManager, Path sitePath, String projectName,
- Path hook, HookArgs args) {
+ Sync(
+ GitRepositoryManager gitManager,
+ Path sitePath,
+ String projectName,
+ Path hook,
+ HookArgs args) {
super(gitManager, sitePath, projectName, hook, args);
}
@@ -71,7 +77,8 @@
}
}
- HookTask(GitRepositoryManager gitManager,
+ HookTask(
+ GitRepositoryManager gitManager,
Path sitePath,
String projectName,
Path hook,
@@ -112,8 +119,7 @@
env.put("GERRIT_SITE", sitePath.toAbsolutePath().toString());
if (projectName != null) {
- try (Repository git = gitManager.openRepository(
- new Project.NameKey(projectName))) {
+ try (Repository git = gitManager.openRepository(new Project.NameKey(projectName))) {
pb.directory(git.getDirectory());
env.put("GIT_DIR", git.getDirectory().getAbsolutePath());
}
@@ -121,8 +127,7 @@
ps = pb.start();
ps.getOutputStream().close();
- String output =
- new String(ByteStreams.toByteArray(ps.getInputStream()), UTF_8);
+ String output = new String(ByteStreams.toByteArray(ps.getInputStream()), UTF_8);
ps.waitFor();
result = new HookResult(ps.exitValue(), output);
} catch (InterruptedException iex) {
@@ -141,8 +146,7 @@
log.info("hook[" + getName() + "] exitValue:" + exitValue);
}
- BufferedReader br =
- new BufferedReader(new StringReader(result.getOutput()));
+ BufferedReader br = new BufferedReader(new StringReader(result.getOutput()));
try {
String line;
while ((line = br.readLine()) != null) {
@@ -161,4 +165,3 @@
return "hook " + hook.getFileName();
}
}
-
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
index b75fc34..2dd3352 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/Module.java
@@ -38,42 +38,24 @@
@Override
protected void configure() {
bind(HookQueue.class).in(Scopes.SINGLETON);
- bind(LifecycleListener.class)
- .annotatedWith(UniqueAnnotations.create())
- .to(HookQueue.class);
+ bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(HookQueue.class);
bind(HookExecutor.class).in(Scopes.SINGLETON);
- bind(LifecycleListener.class)
- .annotatedWith(UniqueAnnotations.create())
- .to(HookExecutor.class);
+ bind(LifecycleListener.class).annotatedWith(UniqueAnnotations.create()).to(HookExecutor.class);
- DynamicSet.bind(binder(), AgreementSignupListener.class)
- .to(AgreementSignup.class);
- DynamicSet.bind(binder(), ChangeAbandonedListener.class)
- .to(ChangeAbandoned.class);
- DynamicSet.bind(binder(), ChangeMergedListener.class)
- .to(ChangeMerged.class);
- DynamicSet.bind(binder(), ChangeRestoredListener.class)
- .to(ChangeRestored.class);
- DynamicSet.bind(binder(), CommentAddedListener.class)
- .to(CommentAdded.class);
- DynamicSet.bind(binder(), DraftPublishedListener.class)
- .to(DraftPublished.class);
- DynamicSet.bind(binder(), GitReferenceUpdatedListener.class)
- .to(GitReferenceUpdated.class);
- DynamicSet.bind(binder(), HashtagsEditedListener.class)
- .to(HashtagsEdited.class);
- DynamicSet.bind(binder(), NewProjectCreatedListener.class)
- .to(NewProjectCreated.class);
- DynamicSet.bind(binder(), ReviewerAddedListener.class)
- .to(ReviewerAdded.class);
- DynamicSet.bind(binder(), ReviewerDeletedListener.class)
- .to(ReviewerDeleted.class);
- DynamicSet.bind(binder(), RevisionCreatedListener.class)
- .to(RevisionCreated.class);
- DynamicSet.bind(binder(), TopicEditedListener.class)
- .to(TopicEdited.class);
+ DynamicSet.bind(binder(), AgreementSignupListener.class).to(AgreementSignup.class);
+ DynamicSet.bind(binder(), ChangeAbandonedListener.class).to(ChangeAbandoned.class);
+ DynamicSet.bind(binder(), ChangeMergedListener.class).to(ChangeMerged.class);
+ DynamicSet.bind(binder(), ChangeRestoredListener.class).to(ChangeRestored.class);
+ DynamicSet.bind(binder(), CommentAddedListener.class).to(CommentAdded.class);
+ DynamicSet.bind(binder(), DraftPublishedListener.class).to(DraftPublished.class);
+ DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(GitReferenceUpdated.class);
+ DynamicSet.bind(binder(), HashtagsEditedListener.class).to(HashtagsEdited.class);
+ DynamicSet.bind(binder(), NewProjectCreatedListener.class).to(NewProjectCreated.class);
+ DynamicSet.bind(binder(), ReviewerAddedListener.class).to(ReviewerAdded.class);
+ DynamicSet.bind(binder(), ReviewerDeletedListener.class).to(ReviewerDeleted.class);
+ DynamicSet.bind(binder(), RevisionCreatedListener.class).to(RevisionCreated.class);
+ DynamicSet.bind(binder(), TopicEditedListener.class).to(TopicEdited.class);
- DynamicSet.bind(binder(), CommitValidationListener.class)
- .to(CommitReceived.class);
+ DynamicSet.bind(binder(), CommitValidationListener.class).to(CommitReceived.class);
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/ReviewerAdded.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/ReviewerAdded.java
index e8b6d01..ac0763a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/ReviewerAdded.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/ReviewerAdded.java
@@ -34,7 +34,7 @@
@Override
public void onReviewersAdded(ReviewerAddedListener.Event event) {
ChangeInfo c = event.getChange();
- for (AccountInfo reviewer: event.getReviewers()) {
+ for (AccountInfo reviewer : event.getReviewers()) {
HookArgs args = hookFactory.createArgs();
args.add("--change", c.id);