Format all Java files with google-java-format
Change-Id: I050f714acab216d5a85a0fb447d02541f534558c
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
index 49e2ec6..3b5156f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ChangeUpdatedListener.java
@@ -35,7 +35,7 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
-
+import java.io.IOException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -43,12 +43,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
class ChangeUpdatedListener implements EventListener {
- private static final Logger log = LoggerFactory
- .getLogger(ChangeUpdatedListener.class);
+ private static final Logger log = LoggerFactory.getLogger(ChangeUpdatedListener.class);
private final ReviewersByBlame.Factory reviewersByBlameFactory;
private final GitRepositoryManager repoManager;
@@ -61,8 +58,10 @@
private ReviewDb db;
@Inject
- ChangeUpdatedListener(final ReviewersByBlame.Factory reviewersByBlameFactory,
- final GitRepositoryManager repoManager, final WorkQueue workQueue,
+ ChangeUpdatedListener(
+ final ReviewersByBlame.Factory reviewersByBlameFactory,
+ final GitRepositoryManager repoManager,
+ final WorkQueue workQueue,
final IdentifiedUser.GenericFactory identifiedUserFactory,
final ThreadLocalRequestContext tl,
final SchemaFactory<ReviewDb> schemaFactory,
@@ -93,7 +92,7 @@
try {
maxReviewers =
cfg.getFromProjectConfigWithInheritance(projectName, pluginName)
- .getInt("maxReviewers", 3);
+ .getInt("maxReviewers", 3);
ignoreDrafts =
cfg.getFromProjectConfigWithInheritance(projectName, pluginName)
.getBoolean("ignoreDrafts", false);
@@ -115,7 +114,8 @@
RevWalk rw = new RevWalk(git);
ReviewDb reviewDb = schemaFactory.open()) {
Change.Id changeId = new Change.Id(Integer.parseInt(Integer.toString(e.change.get().number)));
- PatchSet.Id psId = new PatchSet.Id(changeId, Integer.parseInt(Integer.toString(e.patchSet.get().number)));
+ PatchSet.Id psId =
+ new PatchSet.Id(changeId, Integer.parseInt(Integer.toString(e.patchSet.get().number)));
PatchSet ps = reviewDb.patchSets().get(psId);
if (ps == null) {
log.warn("Patch set " + psId.get() + " not found.");
@@ -132,59 +132,60 @@
return;
}
- final RevCommit commit =
- rw.parseCommit(ObjectId.fromString(e.patchSet.get().revision));
+ final RevCommit commit = rw.parseCommit(ObjectId.fromString(e.patchSet.get().revision));
- if (!ignoreSubjectRegEx.isEmpty()
- && commit.getShortMessage().matches(ignoreSubjectRegEx)) {
+ if (!ignoreSubjectRegEx.isEmpty() && commit.getShortMessage().matches(ignoreSubjectRegEx)) {
return;
}
final Runnable task =
- reviewersByBlameFactory.create(commit, change, ps, maxReviewers,
- git, ignoreFileRegEx);
+ reviewersByBlameFactory.create(commit, change, ps, maxReviewers, git, ignoreFileRegEx);
- workQueue.getDefaultQueue().submit(new Runnable() {
- @Override
- public void run() {
- RequestContext old = tl.setContext(new RequestContext() {
-
- @Override
- public CurrentUser getUser() {
- return identifiedUserFactory.create(change.getOwner());
- }
-
- @Override
- public Provider<ReviewDb> getReviewDbProvider() {
- return new Provider<ReviewDb>() {
+ workQueue
+ .getDefaultQueue()
+ .submit(
+ new Runnable() {
@Override
- public ReviewDb get() {
- if (db == null) {
- try {
- db = schemaFactory.open();
- } catch (OrmException e) {
- throw new ProvisionException("Cannot open ReviewDb", e);
+ public void run() {
+ RequestContext old =
+ tl.setContext(
+ new RequestContext() {
+
+ @Override
+ public CurrentUser getUser() {
+ return identifiedUserFactory.create(change.getOwner());
+ }
+
+ @Override
+ public Provider<ReviewDb> getReviewDbProvider() {
+ return new Provider<ReviewDb>() {
+ @Override
+ public ReviewDb get() {
+ if (db == null) {
+ try {
+ db = schemaFactory.open();
+ } catch (OrmException e) {
+ throw new ProvisionException("Cannot open ReviewDb", e);
+ }
+ }
+ return db;
+ }
+ };
+ }
+ });
+ try {
+ task.run();
+ } finally {
+ tl.setContext(old);
+ if (db != null) {
+ db.close();
+ db = null;
}
}
- return db;
}
- };
- }
- });
- try {
- task.run();
- } finally {
- tl.setContext(old);
- if (db != null) {
- db.close();
- db = null;
- }
- }
- }
- });
- } catch (OrmException|IOException x) {
+ });
+ } catch (OrmException | IOException x) {
log.error(x.getMessage(), x);
}
}
-
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlame.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlame.java
index 5f8ebef..a807f29 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlame.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlame.java
@@ -34,7 +34,12 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
-
+import java.io.IOException;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.eclipse.jgit.api.BlameCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.blame.BlameResult;
@@ -44,18 +49,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-
public class ReviewersByBlame implements Runnable {
- private static final Logger log = LoggerFactory
- .getLogger(ReviewersByBlame.class);
+ private static final Logger log = LoggerFactory.getLogger(ReviewersByBlame.class);
private final RevCommit commit;
private final Change change;
@@ -71,18 +67,26 @@
private final ChangesCollection changes;
public interface Factory {
- ReviewersByBlame create(RevCommit commit, Change change, PatchSet ps,
- int maxReviewers, Repository repo, String ignoreFileRegEx);
+ ReviewersByBlame create(
+ RevCommit commit,
+ Change change,
+ PatchSet ps,
+ int maxReviewers,
+ Repository repo,
+ String ignoreFileRegEx);
}
@Inject
- public ReviewersByBlame(final AccountByEmailCache byEmailCache,
+ public ReviewersByBlame(
+ final AccountByEmailCache byEmailCache,
final AccountCache accountCache,
final ChangesCollection changes,
final Provider<PostReviewers> reviewersProvider,
final PatchListCache patchListCache,
- @Assisted final RevCommit commit, @Assisted final Change change,
- @Assisted final PatchSet ps, @Assisted final int maxReviewers,
+ @Assisted final RevCommit commit,
+ @Assisted final Change change,
+ @Assisted final PatchSet ps,
+ @Assisted final int maxReviewers,
@Assisted final Repository repo,
@Assisted final String ignoreFileRegEx) {
this.byEmailCache = byEmailCache;
@@ -114,10 +118,9 @@
}
for (PatchListEntry entry : patchList.getPatches()) {
BlameResult blameResult;
- if ((entry.getChangeType() == ChangeType.MODIFIED ||
- entry.getChangeType() == ChangeType.DELETED)
- && (ignoreFileRegEx.isEmpty() ||
- !entry.getNewName().matches(ignoreFileRegEx))
+ if ((entry.getChangeType() == ChangeType.MODIFIED
+ || entry.getChangeType() == ChangeType.DELETED)
+ && (ignoreFileRegEx.isEmpty() || !entry.getNewName().matches(ignoreFileRegEx))
&& (blameResult = computeBlame(entry, commit.getParent(0))) != null) {
List<Edit> edits = entry.getEdits();
reviewers.putAll(getReviewersForPatch(edits, blameResult));
@@ -147,27 +150,26 @@
}
}
-
/**
- * Create a set of reviewers based on data collected from line annotations,
- * the reviewers are ordered by their weight and n greatest of the entries
- * are chosen, where n is the maximum number of reviewers
+ * Create a set of reviewers based on data collected from line annotations, the reviewers are
+ * ordered by their weight and n greatest of the entries are chosen, where n is the maximum number
+ * of reviewers
*
- * @param reviewers A set of reviewers with their weight mapped to their
- * {@link Account}
- * @return Reviewers that are best matches for this change, empty if none,
- * never <code>null</code>
+ * @param reviewers A set of reviewers with their weight mapped to their {@link Account}
+ * @return Reviewers that are best matches for this change, empty if none, never <code>null</code>
*/
private Set<Account.Id> findTopReviewers(final Map<Account, Integer> reviewers) {
Set<Account.Id> topReviewers = Sets.newHashSet();
List<Entry<Account, Integer>> entries =
- Ordering.from(new Comparator<Entry<Account, Integer>>() {
- @Override
- public int compare(Entry<Account, Integer> first,
- Entry<Account, Integer> second) {
- return first.getValue() - second.getValue();
- }
- }).greatestOf(reviewers.entrySet(), this.maxReviewers);
+ Ordering.from(
+ new Comparator<Entry<Account, Integer>>() {
+ @Override
+ public int compare(
+ Entry<Account, Integer> first, Entry<Account, Integer> second) {
+ return first.getValue() - second.getValue();
+ }
+ })
+ .greatestOf(reviewers.entrySet(), this.maxReviewers);
for (Entry<Account, Integer> entry : entries) {
topReviewers.add(entry.getKey().getId());
}
@@ -179,17 +181,15 @@
*
* @param edits List of edits that were made for this patch
* @param blameResult Result of blame computation
- * @return a set of all possible reviewers, empty if none, never
- * <code>null</code>
+ * @return a set of all possible reviewers, empty if none, never <code>null</code>
*/
- private Map<Account, Integer> getReviewersForPatch(final List<Edit> edits,
- final BlameResult blameResult) {
+ private Map<Account, Integer> getReviewersForPatch(
+ final List<Edit> edits, final BlameResult blameResult) {
Map<Account, Integer> reviewers = Maps.newHashMap();
for (Edit edit : edits) {
for (int i = edit.getBeginA(); i < edit.getEndA(); i++) {
RevCommit commit = blameResult.getSourceCommit(i);
- Set<Account.Id> ids =
- byEmailCache.get(commit.getAuthorIdent().getEmailAddress());
+ Set<Account.Id> ids = byEmailCache.get(commit.getAuthorIdent().getEmailAddress());
for (Account.Id id : ids) {
Account account = accountCache.get(id).getAccount();
if (account.isActive() && !change.getOwner().equals(account.getId())) {
@@ -203,16 +203,14 @@
}
/**
- * Compute the blame data for the parent, we are not interested in the
- * specific commit but the parent, since we only want to know the last person
- * that edited this specific part of the code.
+ * Compute the blame data for the parent, we are not interested in the specific commit but the
+ * parent, since we only want to know the last person that edited this specific part of the code.
*
* @param entry {@link PatchListEntry}
* @param parent Parent {@link RevCommit}
* @return Result of blame computation, null if the computation fails
*/
- private BlameResult computeBlame(final PatchListEntry entry,
- final RevCommit parent) {
+ private BlameResult computeBlame(final PatchListEntry entry, final RevCommit parent) {
BlameCommand blameCommand = new BlameCommand(repo);
blameCommand.setStartCommit(parent);
blameCommand.setFilePath(entry.getNewName());
@@ -223,10 +221,8 @@
} catch (GitAPIException ex) {
log.error("Couldn't execute blame for commit {}", parent.getName(), ex);
} catch (IOException err) {
- log.error("Error while computing blame for commit {}", parent.getName(),
- err);
+ log.error("Error while computing blame for commit {}", parent.getName(), err);
}
return null;
}
-
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
index 4d61984..8a08c0c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/reviewersbyblame/ReviewersByBlameModule.java
@@ -23,22 +23,29 @@
public class ReviewersByBlameModule extends FactoryModule {
@Override
protected void configure() {
- DynamicSet.bind(binder(), EventListener.class).to(
- ChangeUpdatedListener.class);
+ DynamicSet.bind(binder(), EventListener.class).to(ChangeUpdatedListener.class);
factory(ReviewersByBlame.Factory.class);
bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named("maxReviewers"))
- .toInstance(new ProjectConfigEntry("Max Reviewers", 3, true,
- "The maximum number of reviewers that should be automatically added"
- + " to a change based on the git blame computation on the changed files."));
- bind(ProjectConfigEntry.class).annotatedWith(Exports.named("ignoreDrafts"))
.toInstance(
- new ProjectConfigEntry("Ignore Drafts", false,
- "Ignore draft commits when adding reviewers"));
+ new ProjectConfigEntry(
+ "Max Reviewers",
+ 3,
+ true,
+ "The maximum number of reviewers that should be automatically added"
+ + " to a change based on the git blame computation on the changed files."));
+ bind(ProjectConfigEntry.class)
+ .annotatedWith(Exports.named("ignoreDrafts"))
+ .toInstance(
+ new ProjectConfigEntry(
+ "Ignore Drafts", false, "Ignore draft commits when adding reviewers"));
bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named("ignoreSubjectRegEx"))
.toInstance(
- new ProjectConfigEntry("Ignore Regex", "", true,
+ new ProjectConfigEntry(
+ "Ignore Regex",
+ "",
+ true,
"Ignore commits where the subject matches the given regular expression"));
bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named("ignoreFileRegEx"))