Factor out an arguments class for ChangeNotes
We do a semi-manual injection thing with ChangeNotes.Factory that makes adding new arguments painful. Limit the pain by encapsulating into an injectable Args class. This has more side benefits, like making DraftCommentNotes able to use straight assisted injection, and simplifying TestChanges. Change-Id: I747aefb8d6e16ad6488b2a686bd23304a0fe24f6
This commit is contained in:
@@ -24,10 +24,8 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.client.RevId;
|
||||
import com.google.gerrit.server.config.AllUsersName;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
@@ -43,45 +41,22 @@ import java.io.IOException;
|
||||
* its drafts branch.
|
||||
*/
|
||||
public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final NotesMigration migration;
|
||||
private final AllUsersName draftsProject;
|
||||
private final ChangeNoteUtil noteUtil;
|
||||
|
||||
@VisibleForTesting
|
||||
@Inject
|
||||
public Factory(GitRepositoryManager repoManager,
|
||||
NotesMigration migration,
|
||||
AllUsersName allUsers,
|
||||
ChangeNoteUtil noteUtil) {
|
||||
this.repoManager = repoManager;
|
||||
this.migration = migration;
|
||||
this.draftsProject = allUsers;
|
||||
this.noteUtil = noteUtil;
|
||||
}
|
||||
|
||||
public DraftCommentNotes create(Change.Id changeId, Account.Id accountId) {
|
||||
return new DraftCommentNotes(repoManager, migration, draftsProject,
|
||||
noteUtil, changeId, accountId);
|
||||
}
|
||||
public interface Factory {
|
||||
DraftCommentNotes create(Change.Id changeId, Account.Id accountId);
|
||||
}
|
||||
|
||||
private final AllUsersName draftsProject;
|
||||
private final ChangeNoteUtil noteUtil;
|
||||
private final Account.Id author;
|
||||
|
||||
private ImmutableListMultimap<RevId, PatchLineComment> comments;
|
||||
private RevisionNoteMap revisionNoteMap;
|
||||
|
||||
DraftCommentNotes(GitRepositoryManager repoManager, NotesMigration migration,
|
||||
AllUsersName draftsProject, ChangeNoteUtil noteUtil, Change.Id changeId,
|
||||
Account.Id author) {
|
||||
super(repoManager, migration, changeId);
|
||||
this.draftsProject = draftsProject;
|
||||
@AssistedInject
|
||||
DraftCommentNotes(
|
||||
Args args,
|
||||
@Assisted Change.Id changeId,
|
||||
@Assisted Account.Id author) {
|
||||
super(args, changeId);
|
||||
this.author = author;
|
||||
this.noteUtil = noteUtil;
|
||||
}
|
||||
|
||||
RevisionNoteMap getRevisionNoteMap() {
|
||||
@@ -123,7 +98,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
|
||||
RevCommit tipCommit = walk.parseCommit(rev);
|
||||
ObjectReader reader = walk.getObjectReader();
|
||||
revisionNoteMap = RevisionNoteMap.parse(
|
||||
noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit),
|
||||
args.noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit),
|
||||
true);
|
||||
Multimap<RevId, PatchLineComment> cs = ArrayListMultimap.create();
|
||||
for (RevisionNote rn : revisionNoteMap.revisionNotes.values()) {
|
||||
@@ -141,7 +116,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
|
||||
|
||||
@Override
|
||||
public Project.NameKey getProjectName() {
|
||||
return draftsProject;
|
||||
return args.allUsers;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
Reference in New Issue
Block a user