Format all Java files with google-java-format
Change-Id: I61c547d086a536a2652bd358a9cd58e38e826b13
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
index 834df61..18471b3 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AtomicityHelper.java
@@ -24,54 +24,40 @@
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.util.List;
import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class AtomicityHelper {
- private final static Logger log = LoggerFactory.getLogger(AtomicityHelper.class);
+ private static final Logger log = LoggerFactory.getLogger(AtomicityHelper.class);
- @Inject
- private AccountByEmailCache byEmailCache;
+ @Inject private AccountByEmailCache byEmailCache;
- @Inject
- ChangeData.Factory changeDataFactory;
+ @Inject ChangeData.Factory changeDataFactory;
- @Inject
- private ChangeControl.GenericFactory changeFactory;
+ @Inject private ChangeControl.GenericFactory changeFactory;
- @Inject
- private ChangesCollection collection;
+ @Inject private ChangesCollection collection;
- @Inject
- AutomergeConfig config;
+ @Inject AutomergeConfig config;
- @Inject
- Provider<ReviewDb> db;
+ @Inject Provider<ReviewDb> db;
- @Inject
- private IdentifiedUser.GenericFactory factory;
+ @Inject private IdentifiedUser.GenericFactory factory;
- @Inject
- GetRelated getRelated;
+ @Inject GetRelated getRelated;
- @Inject
- MergeUtil.Factory mergeUtilFactory;
+ @Inject MergeUtil.Factory mergeUtilFactory;
- @Inject
- Provider<PostReview> reviewer;
+ @Inject Provider<PostReview> reviewer;
- @Inject
- Submit submitter;
+ @Inject Submit submitter;
/**
- * Check if the current patchset of the specified change has dependent
- * unmerged changes.
+ * Check if the current patchset of the specified change has dependent unmerged changes.
*
* @param project
* @param number
@@ -80,29 +66,35 @@
* @throws NoSuchChangeException
* @throws OrmException
*/
- public boolean hasDependentReview(String project, int number) throws IOException, NoSuchChangeException, OrmException {
- RevisionResource r = getRevisionResource(project, number);
+ public boolean hasDependentReview(String project, int number)
+ throws IOException, NoSuchChangeException, OrmException {
+ RevisionResource r = getRevisionResource(project, number);
RelatedInfo related = getRelated.apply(r);
log.debug(String.format("Checking for related changes on review %d", number));
String checkedCommitSha1 = r.getPatchSet().getRevision().get();
int firstParentIndex = 0;
int i = 0;
- for (ChangeAndCommit c: related.changes) {
+ for (ChangeAndCommit c : related.changes) {
if (checkedCommitSha1.equals(c.commit.commit)) {
- firstParentIndex = i+1;
- log.debug(String.format("First parent index on review %d is %d on commit %s", number, firstParentIndex, c.commit.commit));
- break;
+ firstParentIndex = i + 1;
+ log.debug(
+ String.format(
+ "First parent index on review %d is %d on commit %s",
+ number, firstParentIndex, c.commit.commit));
+ break;
}
i++;
}
boolean hasNonMergedParent = false;
- for (ChangeAndCommit c: related.changes.subList(firstParentIndex, related.changes.size())) {
+ for (ChangeAndCommit c : related.changes.subList(firstParentIndex, related.changes.size())) {
if (!ChangeStatus.MERGED.toString().equals(c.status)) {
- log.info(String.format("Found non merged parent commit on review %d: %s", number, c.commit.commit));
- hasNonMergedParent = true;
- break;
+ log.info(
+ String.format(
+ "Found non merged parent commit on review %d: %s", number, c.commit.commit));
+ hasNonMergedParent = true;
+ break;
}
}
@@ -110,15 +102,16 @@
}
/**
- * Check if a change is an atomic change or not. A change is atomic if it has
- * the atomic topic prefix.
+ * Check if a change is an atomic change or not. A change is atomic if it has the atomic topic
+ * prefix.
*
* @param change a ChangeAttribute instance
* @return true or false
*/
public boolean isAtomicReview(final Change change) {
final boolean atomic = change.topic != null && change.topic.startsWith(config.getTopicPrefix());
- log.debug(String.format("Checking if change %s is an atomic change: %b", change.number, atomic));
+ log.debug(
+ String.format("Checking if change %s is an atomic change: %b", change.number, atomic));
return atomic;
}
@@ -131,9 +124,14 @@
* @throws OrmException
*/
public boolean isSubmittable(String project, int change) throws OrmException {
- ChangeData changeData = changeDataFactory.create(db.get(), new Project.NameKey(project), new com.google.gerrit.reviewdb.client.Change.Id(change));
+ ChangeData changeData =
+ changeDataFactory.create(
+ db.get(),
+ new Project.NameKey(project),
+ new com.google.gerrit.reviewdb.client.Change.Id(change));
// For draft reviews, the patchSet must be set to avoid an NPE.
- final List<SubmitRecord> cansubmit = new SubmitRuleEvaluator(changeData).setPatchSet(changeData.currentPatchSet()).evaluate();
+ final List<SubmitRecord> cansubmit =
+ new SubmitRuleEvaluator(changeData).setPatchSet(changeData.currentPatchSet()).evaluate();
log.debug(String.format("Checking if change %d is submitable.", change));
for (SubmitRecord submit : cansubmit) {
if (submit.status != SubmitRecord.Status.OK) {
@@ -162,9 +160,16 @@
submitter.apply(r, input);
}
- public RevisionResource getRevisionResource(String project, int changeNumber) throws NoSuchChangeException, OrmException {
- ChangeControl ctl = changeFactory.validateFor(db.get(), new com.google.gerrit.reviewdb.client.Change.Id(changeNumber), getBotUser());
- ChangeData changeData = changeDataFactory.create(db.get(), new Project.NameKey(project), new com.google.gerrit.reviewdb.client.Change.Id(changeNumber));
+ public RevisionResource getRevisionResource(String project, int changeNumber)
+ throws NoSuchChangeException, OrmException {
+ ChangeControl ctl =
+ changeFactory.validateFor(
+ db.get(), new com.google.gerrit.reviewdb.client.Change.Id(changeNumber), getBotUser());
+ ChangeData changeData =
+ changeDataFactory.create(
+ db.get(),
+ new Project.NameKey(project),
+ new com.google.gerrit.reviewdb.client.Change.Id(changeNumber));
RevisionResource r = new RevisionResource(collection.parse(ctl), changeData.currentPatchSet());
return r;
}
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
index edde850..4696b2d 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomaticMerger.java
@@ -17,8 +17,8 @@
import com.google.common.collect.Lists;
import com.google.gerrit.common.EventListener;
import com.google.gerrit.extensions.api.GerritApi;
-import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.client.ListChangesOption;
+import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.server.ReviewDb;
@@ -36,69 +36,54 @@
import com.google.gerrit.server.events.ReviewerDeletedEvent;
import com.google.gerrit.server.events.TopicChangedEvent;
import com.google.gerrit.server.git.MergeUtil;
-import com.google.gerrit.server.update.UpdateException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.query.change.ChangeData;
+import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-/**
- * Starts at the same time as the gerrit server, and sets up our change hook
- * listener.
- */
+/** Starts at the same time as the gerrit server, and sets up our change hook listener. */
public class AutomaticMerger implements EventListener, LifecycleListener {
- private final static Logger log = LoggerFactory.getLogger(AutomaticMerger.class);
+ private static final Logger log = LoggerFactory.getLogger(AutomaticMerger.class);
- @Inject
- private GerritApi api;
+ @Inject private GerritApi api;
- @Inject
- private AtomicityHelper atomicityHelper;
+ @Inject private AtomicityHelper atomicityHelper;
- @Inject
- ChangeData.Factory changeDataFactory;
+ @Inject ChangeData.Factory changeDataFactory;
- @Inject
- private AutomergeConfig config;
+ @Inject private AutomergeConfig config;
- @Inject
- Provider<ReviewDb> db;
+ @Inject Provider<ReviewDb> db;
- @Inject
- GetRelated getRelated;
+ @Inject GetRelated getRelated;
- @Inject
- MergeUtil.Factory mergeUtilFactory;
+ @Inject MergeUtil.Factory mergeUtilFactory;
- @Inject
- Provider<PostReview> reviewer;
+ @Inject Provider<PostReview> reviewer;
- @Inject
- private ReviewUpdater reviewUpdater;
+ @Inject private ReviewUpdater reviewUpdater;
- @Inject
- Submit submitter;
+ @Inject Submit submitter;
@Override
- synchronized public void onEvent(final Event event) {
- if (event instanceof TopicChangedEvent ||
- event instanceof DraftPublishedEvent ||
- event instanceof ReviewerDeletedEvent || // A blocking score might be removed when a reviewer is deleted.
+ public synchronized void onEvent(final Event event) {
+ if (event instanceof TopicChangedEvent
+ || event instanceof DraftPublishedEvent
+ || event instanceof ReviewerDeletedEvent
+ || // A blocking score might be removed when a reviewer is deleted.
event instanceof PatchSetCreatedEvent) {
- Change change = Change.from(((ChangeEvent)event).change.get());
+ Change change = Change.from(((ChangeEvent) event).change.get());
onNewOrChangedPatchSet(change);
- }
- else if (event instanceof CommentAddedEvent) {
- onCommentAdded((CommentAddedEvent)event);
+ } else if (event instanceof CommentAddedEvent) {
+ onCommentAdded((CommentAddedEvent) event);
}
// it is not an else since the previous automatic submit(s) can potentially
// trigger others on the whole project/branch
@@ -182,8 +167,8 @@
}
/**
- * Returns true if the plugin must handle this comment, i.e. if we are sure it does not come
- * from this plugin (to avoid infinite loop).
+ * Returns true if the plugin must handle this comment, i.e. if we are sure it does not come from
+ * this plugin (to avoid infinite loop).
*
* @param comment
* @return a boolean
@@ -209,18 +194,27 @@
.get());
for (final ChangeInfo info : related) {
if (!atomicityHelper.isSubmittable(info.project, info._number)) {
- log.info("Change {} is not submittable because same topic change {} has not all approvals.", change.number, info._number);
+ log.info(
+ "Change {} is not submittable because same topic change {} has not all approvals.",
+ change.number,
+ info._number);
return;
}
}
for (final ChangeInfo info : related) {
- boolean dependsOnNonMergedCommit = atomicityHelper.hasDependentReview(info.project, info._number);
+ boolean dependsOnNonMergedCommit =
+ atomicityHelper.hasDependentReview(info.project, info._number);
if (!info.mergeable || dependsOnNonMergedCommit) {
- log.info("Change {} is not mergeable because same topic change {} {}", change.number, info._number,
+ log.info(
+ "Change {} is not mergeable because same topic change {} {}",
+ change.number,
+ info._number,
!info.mergeable ? "is non mergeable" : "depends on a non merged commit.");
- PluginComment comment = !info.mergeable ? config.cantMergeGitConflict : config.cantMergeDependsOnNonMerged;
- reviewUpdater.commentOnReview(change.project, change.number, String.format(comment.getContent(), info._number));
+ PluginComment comment =
+ !info.mergeable ? config.cantMergeGitConflict : config.cantMergeDependsOnNonMerged;
+ reviewUpdater.commentOnReview(
+ change.project, change.number, String.format(comment.getContent(), info._number));
return;
}
}
@@ -235,11 +229,15 @@
try {
checkReviewExists(change.number);
log.info(String.format("Detected atomic review on change %d.", change.number));
- reviewUpdater.commentOnReview(change.project, change.number, config.atomicReviewDetected.getContent());
+ reviewUpdater.commentOnReview(
+ change.project, change.number, config.atomicReviewDetected.getContent());
if (atomicityHelper.hasDependentReview(change.project, change.number)) {
- log.info(String.format("Warn the user on change %d, as other atomic changes exists on the same repository.",
- change.number));
- reviewUpdater.commentOnReview(change.project, change.number, config.atomicReviewsSameRepo.getContent());
+ log.info(
+ String.format(
+ "Warn the user on change %d, as other atomic changes exists on the same repository.",
+ change.number));
+ reviewUpdater.commentOnReview(
+ change.project, change.number, config.atomicReviewsSameRepo.getContent());
}
} catch (RestApiException | IOException | OrmException | UpdateException e) {
throw new RuntimeException(e);
@@ -256,6 +254,5 @@
}
@Override
- public void stop() {
- }
+ public void stop() {}
}
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
index cd048c6..8eb1010 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeConfig.java
@@ -3,26 +3,21 @@
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
-
+import java.io.File;
import org.eclipse.jgit.lib.Config;
-import java.io.File;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
public class AutomergeConfig {
- public final static String AUTOMERGE_SECTION = "automerge";
- public final static String BOT_EMAIL_KEY = "botEmail";
+ public static final String AUTOMERGE_SECTION = "automerge";
+ public static final String BOT_EMAIL_KEY = "botEmail";
public final PluginComment atomicReviewDetected;
public final PluginComment atomicReviewsSameRepo;
public final PluginComment cantMergeGitConflict;
public final PluginComment cantMergeDependsOnNonMerged;
- private final static String defaultBotEmail = "qabot@criteo.com";
- private final static String defaultTopicPrefix = "crossrepo/";
- public final static String TOPIC_PREFIX_KEY = "topicPrefix";
+ private static final String defaultBotEmail = "qabot@criteo.com";
+ private static final String defaultTopicPrefix = "crossrepo/";
+ public static final String TOPIC_PREFIX_KEY = "topicPrefix";
public static final String getDefaultBotEmail() {
return defaultBotEmail;
@@ -49,15 +44,23 @@
templatesPath = paths.etc_dir.toFile();
- atomicReviewDetected = new PluginComment(getCommentPath("atomic_review_detected.txt"),
- "This review is part of a cross-repository change.\n"
- + "It will be submitted once all related reviews are submittable.");
- atomicReviewsSameRepo = new PluginComment(getCommentPath("atomic_review_same_repo.txt"),
- "This cross-repo review depends on a not merged commit that must be merged first.");
- cantMergeGitConflict = new PluginComment(getCommentPath("cantmerge_git_conflict.txt"),
- "This cross-repo review is blocked by a git conflict on change #/c/%d.");
- cantMergeDependsOnNonMerged = new PluginComment(getCommentPath("cantmerge_depends_on_non_merged.txt"),
- "This cross-repo review is blocked by a non merged commit below #/c/%d.");
+ atomicReviewDetected =
+ new PluginComment(
+ getCommentPath("atomic_review_detected.txt"),
+ "This review is part of a cross-repository change.\n"
+ + "It will be submitted once all related reviews are submittable.");
+ atomicReviewsSameRepo =
+ new PluginComment(
+ getCommentPath("atomic_review_same_repo.txt"),
+ "This cross-repo review depends on a not merged commit that must be merged first.");
+ cantMergeGitConflict =
+ new PluginComment(
+ getCommentPath("cantmerge_git_conflict.txt"),
+ "This cross-repo review is blocked by a git conflict on change #/c/%d.");
+ cantMergeDependsOnNonMerged =
+ new PluginComment(
+ getCommentPath("cantmerge_depends_on_non_merged.txt"),
+ "This cross-repo review is blocked by a non merged commit below #/c/%d.");
}
public final String getBotEmail() {
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeModule.java b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeModule.java
index 744bb2d..dda0aa5 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeModule.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/AutomergeModule.java
@@ -21,7 +21,7 @@
/**
* Main automerge Guice module.
*
- * Configures how all classes in the plugin are instantiated via Guice.
+ * <p>Configures how all classes in the plugin are instantiated via Guice.
*/
public class AutomergeModule extends AbstractModule {
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/Change.java b/src/main/java/com/criteo/gerrit/plugins/automerge/Change.java
index a3e91e5..3216cca 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/Change.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/Change.java
@@ -5,9 +5,9 @@
/**
* A change represented only with the fields that this plugin requires.
- * <p>
- * As a change can be a {@link ChangeAttribute} or a {@link ChangeInfo}, this intermediate class is
- * needed.
+ *
+ * <p>As a change can be a {@link ChangeAttribute} or a {@link ChangeInfo}, this intermediate class
+ * is needed.
*/
public class Change {
public final String project;
@@ -20,11 +20,11 @@
this.topic = topic;
}
- static public Change from(ChangeAttribute changeAttribute) {
+ public static Change from(ChangeAttribute changeAttribute) {
return new Change(changeAttribute.project, changeAttribute.number, changeAttribute.topic);
}
- static public Change from(ChangeInfo changeInfo) {
+ public static Change from(ChangeInfo changeInfo) {
return new Change(changeInfo.project, changeInfo._number, changeInfo.topic);
}
}
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/PluginComment.java b/src/main/java/com/criteo/gerrit/plugins/automerge/PluginComment.java
index a9c2cc0..4cacdd6 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/PluginComment.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/PluginComment.java
@@ -7,12 +7,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * A comment pushed by the plugin to a Gerrit patchset.
- */
+/** A comment pushed by the plugin to a Gerrit patchset. */
public class PluginComment {
- private final static Logger log = LoggerFactory.getLogger(PluginComment.class);
+ private static final Logger log = LoggerFactory.getLogger(PluginComment.class);
private final File templatePath;
private final String defaultMessage;
@@ -24,6 +22,7 @@
/**
* Returns the comment message, possibly with interpolation placeholders.
+ *
* @return a string
*/
String getContent() {
diff --git a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
index 691e1a1..d5f982f 100644
--- a/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
+++ b/src/main/java/com/criteo/gerrit/plugins/automerge/ReviewUpdater.java
@@ -2,19 +2,12 @@
import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.restapi.RestApiException;
-import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.change.PostReview;
import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.update.UpdateException;
-import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gerrit.server.query.change.ChangeData;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
public class ReviewUpdater {
@@ -25,13 +18,12 @@
*/
public static final String commentsPrefix = "[Autosubmitter] ";
- @Inject
- Provider<PostReview> reviewer;
+ @Inject Provider<PostReview> reviewer;
- @Inject
- private AtomicityHelper atomicityHelper;
+ @Inject private AtomicityHelper atomicityHelper;
- public void commentOnReview(String project, int number, String comment) throws RestApiException, OrmException, IOException, UpdateException {
+ public void commentOnReview(String project, int number, String comment)
+ throws RestApiException, OrmException, IOException, UpdateException {
ReviewInput reviewInput = createComment(comment);
applyComment(project, number, reviewInput);
}
@@ -40,7 +32,8 @@
return new ReviewInput().message(commentsPrefix + comment);
}
- private void applyComment(String project, int number, ReviewInput comment) throws RestApiException, OrmException, IOException, UpdateException {
+ private void applyComment(String project, int number, ReviewInput comment)
+ throws RestApiException, OrmException, IOException, UpdateException {
RevisionResource r = atomicityHelper.getRevisionResource(project, number);
reviewer.get().apply(r, comment);
}
diff --git a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
index 49535db..69e4ef9 100644
--- a/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
+++ b/src/test/java/com/criteo/gerrit/plugins/automerge/AutomergeConfigTest.java
@@ -4,13 +4,11 @@
import static org.junit.Assert.fail;
import com.google.gerrit.server.config.SitePaths;
-
-import org.eclipse.jgit.lib.Config;
-import org.junit.Test;
-
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Paths;
+import org.eclipse.jgit.lib.Config;
+import org.junit.Test;
public class AutomergeConfigTest {
@@ -35,8 +33,13 @@
try {
final SitePaths paths = new SitePaths(Paths.get("."));
- conf.setString(AutomergeConfig.AUTOMERGE_SECTION, null, AutomergeConfig.BOT_EMAIL_KEY, "Foo@bar.com");
- conf.setString(AutomergeConfig.AUTOMERGE_SECTION, null, AutomergeConfig.TOPIC_PREFIX_KEY, "fake_topic_prefix");
+ conf.setString(
+ AutomergeConfig.AUTOMERGE_SECTION, null, AutomergeConfig.BOT_EMAIL_KEY, "Foo@bar.com");
+ conf.setString(
+ AutomergeConfig.AUTOMERGE_SECTION,
+ null,
+ AutomergeConfig.TOPIC_PREFIX_KEY,
+ "fake_topic_prefix");
final AutomergeConfig amconf = new AutomergeConfig(conf, paths);
assertEquals(amconf.getBotEmail(), "Foo@bar.com");