Merge branch stable-2.13 * stable-2.13: Adapt to the JGit v4.5.x Change-Id: I71d43089fc940af1f52067ebf1823264bd9c7fea
diff --git a/.gitignore b/.gitignore index 47617be..7b9a01e 100644 --- a/.gitignore +++ b/.gitignore
@@ -3,6 +3,4 @@ /.project /.settings/org.maven.ide.eclipse.prefs /.settings/org.eclipse.m2e.core.prefs -/.buckd -/buck-cache -/buck-out +*.iml
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 7bae62b..ef06de9 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs
@@ -1,16 +1,16 @@ #Thu Jul 28 11:02:36 PDT 2011 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/BUCK b/BUCK deleted file mode 100644 index b766ae2..0000000 --- a/BUCK +++ /dev/null
@@ -1,10 +0,0 @@ -gerrit_plugin( - name = 'reviewnotes', - srcs = glob(['src/main/java/**/*.java']), - resources = glob(['src/main/resources/**/*']), - manifest_entries = [ - 'Gerrit-PluginName: reviewnotes', - 'Gerrit-Module: com.googlesource.gerrit.plugins.reviewnotes.ReviewNotesModule', - 'Gerrit-SshModule: com.googlesource.gerrit.plugins.reviewnotes.SshModule' - ] -)
diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..b013399 --- /dev/null +++ b/BUILD
@@ -0,0 +1,12 @@ +load("//tools/bzl:plugin.bzl", "gerrit_plugin") + +gerrit_plugin( + name = "reviewnotes", + srcs = glob(["src/main/java/**/*.java"]), + manifest_entries = [ + "Gerrit-PluginName: reviewnotes", + "Gerrit-Module: com.googlesource.gerrit.plugins.reviewnotes.ReviewNotesModule", + "Gerrit-SshModule: com.googlesource.gerrit.plugins.reviewnotes.SshModule", + ], + resources = glob(["src/main/resources/**/*"]), +)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java index 249700a..504bfba 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java +++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/CreateReviewNotes.java
@@ -40,7 +40,9 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.assistedinject.Assisted; - +import java.io.IOException; +import java.util.Collections; +import java.util.List; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; @@ -58,18 +60,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.Collections; -import java.util.List; - class CreateReviewNotes { - private static final Logger log = - LoggerFactory.getLogger(CreateReviewNotes.class); + private static final Logger log = LoggerFactory.getLogger(CreateReviewNotes.class); interface Factory { - CreateReviewNotes create(ReviewDb reviewDb, Project.NameKey project, - Repository git); + CreateReviewNotes create(ReviewDb reviewDb, Project.NameKey project, Repository git); } private static final String REFS_NOTES_REVIEW = "refs/notes/review"; @@ -94,7 +90,8 @@ private StringBuilder message; @Inject - CreateReviewNotes(@GerritPersonIdent PersonIdent gerritIdent, + CreateReviewNotes( + @GerritPersonIdent PersonIdent gerritIdent, AccountCache accountCache, @AnonymousCowardName String anonymousCowardName, ProjectCache projectCache, @@ -113,9 +110,11 @@ this.anonymousCowardName = anonymousCowardName; ProjectState projectState = projectCache.get(project); if (projectState == null) { - log.error("Could not obtain available labels for project " - + project.get() + ". Expect missing labels in its review notes."); - this.labelTypes = new LabelTypes(Collections.<LabelType> emptyList()); + log.error( + "Could not obtain available labels for project {}." + + " Expect missing labels in its review notes.", + project.get()); + this.labelTypes = new LabelTypes(Collections.<LabelType>emptyList()); } else { this.labelTypes = projectState.getLabelTypes(); } @@ -131,8 +130,9 @@ this.git = git; } - void createNotes(String branch, ObjectId oldObjectId, ObjectId newObjectId, - ProgressMonitor monitor) throws OrmException, IOException { + void createNotes( + String branch, ObjectId oldObjectId, ObjectId newObjectId, ProgressMonitor monitor) + throws OrmException, IOException { if (ObjectId.zeroId().equals(newObjectId)) { return; } @@ -158,8 +158,7 @@ for (RevCommit c : rw) { PatchSet ps = loadPatchSet(c, branch); if (ps != null) { - ChangeNotes notes = notesFactory.create(reviewDb, project, - ps.getId().getParentKey()); + ChangeNotes notes = notesFactory.create(reviewDb, project, ps.getId().getParentKey()); ObjectId content = createNoteContent(notes, ps); if (content != null) { monitor.update(1); @@ -167,8 +166,11 @@ getMessage().append("* ").append(c.getShortMessage()).append("\n"); } } else { - log.debug("no note for this commit since it is a direct push: " - + c.getName().substring(0, 7)); + if (log.isDebugEnabled()) { + log.debug( + "no note for this commit since it is a direct push {}", + c.getName().substring(0, 7)); + } } } } @@ -183,8 +185,7 @@ for (ChangeNotes cn : notes) { monitor.update(1); - PatchSet ps = - reviewDb.patchSets().get(cn.getChange().currentPatchSetId()); + PatchSet ps = reviewDb.patchSets().get(cn.getChange().currentPatchSetId()); ObjectId commitId = ObjectId.fromString(ps.getRevision().get()); RevCommit commit = rw.parseCommit(commitId); getNotes().set(commitId, createNoteContent(cn, ps)); @@ -200,9 +201,9 @@ } message.insert(0, "Update notes for submitted changes\n\n"); - notesBranchUtilFactory.create(project, git, inserter) - .commitAllNotes(reviewNotes, REFS_NOTES_REVIEW, gerritServerIdent, - message.toString()); + notesBranchUtilFactory + .create(project, git, inserter) + .commitAllNotes(reviewNotes, REFS_NOTES_REVIEW, gerritServerIdent, message.toString()); } finally { if (inserter != null) { inserter.close(); @@ -210,8 +211,7 @@ } } - private void markUninteresting(Repository git, String branch, RevWalk rw, - ObjectId oldObjectId) { + private void markUninteresting(Repository git, String branch, RevWalk rw, ObjectId oldObjectId) { for (final Ref r : git.getAllRefs().values()) { try { if (r.getName().equals(branch)) { @@ -236,13 +236,11 @@ private ObjectId createNoteContent(ChangeNotes notes, PatchSet ps) throws OrmException, IOException { - HeaderFormatter fmt = - new HeaderFormatter(gerritServerIdent.getTimeZone(), anonymousCowardName); + HeaderFormatter fmt = new HeaderFormatter(gerritServerIdent.getTimeZone(), anonymousCowardName); if (ps != null) { try { createCodeReviewNote(notes, ps, fmt); - return getInserter().insert(Constants.OBJ_BLOB, - fmt.toString().getBytes("UTF-8")); + return getInserter().insert(Constants.OBJ_BLOB, fmt.toString().getBytes("UTF-8")); } catch (NoSuchChangeException e) { throw new IOException(e); } @@ -250,11 +248,9 @@ return null; } - private PatchSet loadPatchSet(RevCommit c, String destBranch) - throws OrmException { + private PatchSet loadPatchSet(RevCommit c, String destBranch) throws OrmException { String hash = c.name(); - for (ChangeData cd : queryProvider.get() - .byBranchCommit(project.get(), destBranch, hash)) { + for (ChangeData cd : queryProvider.get().byBranchCommit(project.get(), destBranch, hash)) { for (PatchSet ps : cd.patchSets()) { if (ps.getRevision().matches(hash)) { return ps; @@ -264,19 +260,18 @@ return null; // TODO: createNoCodeReviewNote(branch, c, fmt); } - private void createCodeReviewNote(ChangeNotes notes, PatchSet ps, - HeaderFormatter fmt) throws OrmException, NoSuchChangeException { + private void createCodeReviewNote(ChangeNotes notes, PatchSet ps, HeaderFormatter fmt) + throws OrmException, NoSuchChangeException { // This races with the label normalization/writeback done by MergeOp. It may // repeat some work, but results should be identical except in the case of // an additional race with a permissions change. // TODO(dborowitz): These will eventually be stamped in the ChangeNotes at // commit time so we will be able to skip this normalization step. Change change = notes.getChange(); - ChangeControl ctl = changeControlFactory.controlFor( - notes, userFactory.create(change.getOwner())); + ChangeControl ctl = + changeControlFactory.controlFor(notes, userFactory.create(change.getOwner())); PatchSetApproval submit = null; - for (PatchSetApproval a : - approvalsUtil.byPatchSet(reviewDb, ctl, ps.getId())) { + for (PatchSetApproval a : approvalsUtil.byPatchSet(reviewDb, ctl, ps.getId())) { if (a.getValue() == 0) { // Ignore 0 values. } else if (a.isLegacySubmit()) { @@ -284,8 +279,7 @@ } else { LabelType type = labelTypes.byLabel(a.getLabelId()); if (type != null) { - fmt.appendApproval(type, a.getValue(), - accountCache.get(a.getAccountId()).getAccount()); + fmt.appendApproval(type, a.getValue(), accountCache.get(a.getAccountId()).getAccount()); } } }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java index e62e1fc..520ae0a 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java +++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ExportReviewNotes.java
@@ -14,9 +14,9 @@ package com.googlesource.gerrit.plugins.reviewnotes; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; +import com.google.common.collect.Maps; import com.google.common.collect.MultimapBuilder; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Project; @@ -27,7 +27,9 @@ import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; - +import java.io.IOException; +import java.util.List; +import java.util.Map; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.Repository; @@ -35,26 +37,18 @@ import org.eclipse.jgit.lib.ThreadSafeProgressMonitor; import org.kohsuke.args4j.Option; -import java.io.IOException; -import java.util.List; -import java.util.Map; - /** Export review notes for all submitted changes in all projects. */ public class ExportReviewNotes extends SshCommand { @Option(name = "--threads", usage = "Number of concurrent threads to run") private int threads = 2; - @Inject - private GitRepositoryManager gitManager; + @Inject private GitRepositoryManager gitManager; - @Inject - private SchemaFactory<ReviewDb> database; + @Inject private SchemaFactory<ReviewDb> database; - @Inject - private CreateReviewNotes.Factory reviewNotesFactory; + @Inject private CreateReviewNotes.Factory reviewNotesFactory; - @Inject - private ChangeNotes.Factory notesFactory; + @Inject private ChangeNotes.Factory notesFactory; private ListMultimap<Project.NameKey, ChangeNotes> changes; private ThreadSafeProgressMonitor monitor; @@ -79,21 +73,19 @@ private ListMultimap<Project.NameKey, ChangeNotes> mergedChanges() { try (ReviewDb db = database.open()) { - return MultimapBuilder.hashKeys().arrayListValues() - .build(notesFactory.create(db, new Predicate<ChangeNotes>() { - @Override - public boolean apply(ChangeNotes notes) { - return notes.getChange().getStatus() == Change.Status.MERGED; - } - })); + return MultimapBuilder.hashKeys() + .arrayListValues() + .build( + notesFactory.create( + db, notes -> notes.getChange().getStatus() == Change.Status.MERGED)); } catch (OrmException | IOException e) { stderr.println("Cannot read changes from database " + e.getMessage()); return ImmutableListMultimap.of(); } } - private void export(ReviewDb db, Project.NameKey project, - List<ChangeNotes> notes) throws IOException, OrmException { + private void export(ReviewDb db, Project.NameKey project, List<ChangeNotes> notes) + throws IOException, OrmException { try (Repository git = gitManager.openRepository(project)) { CreateReviewNotes crn = reviewNotesFactory.create(db, project, git); crn.createNotes(notes, monitor); @@ -111,24 +103,8 @@ return null; } - final Project.NameKey name = changes.keySet().iterator().next(); - final List<ChangeNotes> list = changes.removeAll(name); - return new Map.Entry<Project.NameKey, List<ChangeNotes>>() { - @Override - public Project.NameKey getKey() { - return name; - } - - @Override - public List<ChangeNotes> getValue() { - return list; - } - - @Override - public List<ChangeNotes> setValue(List<ChangeNotes> value) { - throw new UnsupportedOperationException(); - } - }; + Project.NameKey name = changes.keySet().iterator().next(); + return Maps.immutableEntry(name, changes.removeAll(name)); } } @@ -136,7 +112,7 @@ @Override public void run() { try (ReviewDb db = database.open()) { - for (;;) { + for (; ; ) { Map.Entry<Project.NameKey, List<ChangeNotes>> next = next(); if (next != null) { try {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java index d5abf41..8633d5c 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/HeaderFormatter.java
@@ -18,7 +18,6 @@ import com.google.gerrit.common.data.LabelValue; import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Change; - import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -28,11 +27,10 @@ /** * Formatters for code review note headers. - * <p> - * This class provides a builder like interface for building the content of a - * code review note. After instantiation, call as many as necessary - * <code>append...(...)</code> methods and, at the end, call the - * {@link #toString()} method to get the built note content. + * + * <p>This class provides a builder like interface for building the content of a code review note. + * After instantiation, call as many as necessary <code>append...(...)</code> methods and, at the + * end, call the {@link #toString()} method to get the built note content. */ class HeaderFormatter { @@ -41,8 +39,7 @@ private final StringBuilder sb = new StringBuilder(); HeaderFormatter(TimeZone tz, String anonymousCowardName) { - rfc2822DateFormatter = - new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); + rfc2822DateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US); rfc2822DateFormatter.setCalendar(Calendar.getInstance(tz, Locale.US)); this.anonymousCowardName = anonymousCowardName; } @@ -51,7 +48,7 @@ sb.append("Change-Id: ").append(changeKey.get()).append("\n"); } - void appendApproval(LabelType label, short value, Account user) { + void appendApproval(LabelType label, short value, Account user) { sb.append(label.getName()); sb.append(LabelValue.formatValue(value)); sb.append(": "); @@ -63,13 +60,13 @@ boolean needSpace = false; boolean wroteData = false; - if (user.getFullName() != null && ! user.getFullName().isEmpty()) { + if (user.getFullName() != null && !user.getFullName().isEmpty()) { sb.append(user.getFullName()); needSpace = true; wroteData = true; } - if (user.getPreferredEmail() != null && ! user.getPreferredEmail().isEmpty()) { + if (user.getPreferredEmail() != null && !user.getPreferredEmail().isEmpty()) { if (needSpace) { sb.append(" "); } @@ -97,13 +94,11 @@ } void appendSubmittedAt(Date date) { - sb.append("Submitted-at: ").append(rfc2822DateFormatter.format(date)) - .append("\n"); + sb.append("Submitted-at: ").append(rfc2822DateFormatter.format(date)).append("\n"); } void appendReviewedOn(String canonicalWebUrl, Change.Id changeId) { - sb.append("Reviewed-on: ").append(canonicalWebUrl).append(changeId.get()) - .append("\n"); + sb.append("Reviewed-on: ").append(canonicalWebUrl).append(changeId.get()).append("\n"); } @Override
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java index d798648..46331ca 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java +++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/RefUpdateListener.java
@@ -24,7 +24,8 @@ import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.SchemaFactory; import com.google.inject.Inject; - +import java.io.IOException; +import java.util.concurrent.Future; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ObjectId; @@ -32,12 +33,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; - class RefUpdateListener implements GitReferenceUpdatedListener { - private static final Logger log = LoggerFactory - .getLogger(RefUpdateListener.class); + private static final Logger log = LoggerFactory.getLogger(RefUpdateListener.class); private final CreateReviewNotes.Factory reviewNotesFactory; private final SchemaFactory<ReviewDb> schema; @@ -46,9 +44,11 @@ private final boolean async; @Inject - RefUpdateListener(final CreateReviewNotes.Factory reviewNotesFactory, + RefUpdateListener( + final CreateReviewNotes.Factory reviewNotesFactory, final SchemaFactory<ReviewDb> schema, - final GitRepositoryManager repoManager, final WorkQueue workQueue, + final GitRepositoryManager repoManager, + final WorkQueue workQueue, @GerritServerConfig final Config config) { this.reviewNotesFactory = reviewNotesFactory; this.schema = schema; @@ -59,34 +59,36 @@ @Override public void onGitReferenceUpdated(final Event e) { - Runnable task = new ProjectRunnable() { - @Override - public void run() { - createReviewNotes(e); - } + Runnable task = + new ProjectRunnable() { + @Override + public void run() { + createReviewNotes(e); + } - @Override - public Project.NameKey getProjectNameKey() { - return new Project.NameKey(e.getProjectName()); - } + @Override + public Project.NameKey getProjectNameKey() { + return new Project.NameKey(e.getProjectName()); + } - @Override - public String getRemoteName() { - return null; - } + @Override + public String getRemoteName() { + return null; + } - @Override - public boolean hasCustomizedPrint() { - return true; - } + @Override + public boolean hasCustomizedPrint() { + return true; + } - @Override - public String toString() { - return "create-review-notes"; - } - }; + @Override + public String toString() { + return "create-review-notes"; + } + }; if (async) { - workQueue.getDefaultQueue().submit(task); + @SuppressWarnings("unused") // No assurance this completes. + Future<?> possiblyIgnoredError = workQueue.getDefaultQueue().submit(task); } else { task.run(); } @@ -96,10 +98,10 @@ Project.NameKey projectName = new Project.NameKey(e.getProjectName()); try (Repository git = repoManager.openRepository(projectName); ReviewDb reviewDb = schema.open()) { - CreateReviewNotes crn = reviewNotesFactory.create( - reviewDb, projectName, git); + CreateReviewNotes crn = reviewNotesFactory.create(reviewDb, projectName, git); if (e.getRefName().startsWith("refs/heads/")) { - crn.createNotes(e.getRefName(), + crn.createNotes( + e.getRefName(), ObjectId.fromString(e.getOldObjectId()), ObjectId.fromString(e.getNewObjectId()), null);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ReviewNotesModule.java b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ReviewNotesModule.java index a2d4f79..83c50d6 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ReviewNotesModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/reviewnotes/ReviewNotesModule.java
@@ -22,8 +22,7 @@ public class ReviewNotesModule extends AbstractModule { @Override protected void configure() { - DynamicSet.bind(binder(), GitReferenceUpdatedListener.class) - .to(RefUpdateListener.class); + DynamicSet.bind(binder(), GitReferenceUpdatedListener.class).to(RefUpdateListener.class); install(new FactoryModuleBuilder().build(CreateReviewNotes.Factory.class)); } }
diff --git a/src/main/resources/Documentation/cmd-export.md b/src/main/resources/Documentation/cmd-export.md index 7f4351d..011e51a 100644 --- a/src/main/resources/Documentation/cmd-export.md +++ b/src/main/resources/Documentation/cmd-export.md
@@ -3,7 +3,7 @@ NAME ---- -@PLUGIN@ export - Export successful reviews to [refs/notes/review](refs-notes-review.html) +@PLUGIN@ export - Export successful reviews to [refs/notes/review](refs-notes-review.md) SYNOPSIS --------