use of com.google.gerrit.reviewdb.client.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreter method toTreeModifications.
/**
* Transforms the given {@code FixReplacement}s into {@code TreeModification}s.
*
* @param repository the affected Git repository
* @param projectState the affected project
* @param patchSetCommitId the patch set which should be modified
* @param fixReplacements the replacements which should be applied
* @return a list of {@code TreeModification}s representing the given replacements
* @throws ResourceNotFoundException if a file to which one of the replacements refers doesn't
* exist
* @throws ResourceConflictException if the replacements can't be transformed into {@code
* TreeModification}s
*/
public List<TreeModification> toTreeModifications(Repository repository, ProjectState projectState, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceNotFoundException, IOException, ResourceConflictException {
checkNotNull(fixReplacements, "Fix replacements must not be null");
Map<String, List<FixReplacement>> fixReplacementsPerFilePath = fixReplacements.stream().collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
List<TreeModification> treeModifications = new ArrayList<>();
for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
TreeModification treeModification = toTreeModification(repository, projectState, patchSetCommitId, entry.getKey(), entry.getValue());
treeModifications.add(treeModification);
}
return treeModifications;
}
use of com.google.gerrit.reviewdb.client.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreterTest method lineSeparatorCanBeChanged.
@Test
public void lineSeparatorCanBeChanged() throws Exception {
FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(2, 11, 3, 0), "\r");
mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
replay(fileContentUtil);
List<TreeModification> treeModifications = toTreeModifications(fixReplacement);
assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First line\nSecond line\rThird line\n");
}
use of com.google.gerrit.reviewdb.client.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreterTest method replacementsMayTouch.
@Test
public void replacementsMayTouch() throws Exception {
FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 6, 2, 7), "modified ");
FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(2, 7, 3, 5), "content");
mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
replay(fileContentUtil);
List<TreeModification> treeModifications = toTreeModifications(fixReplacement1, fixReplacement2);
assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("First modified content line\n");
}
use of com.google.gerrit.reviewdb.client.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreterTest method replacementsMustNotReferToNotExistingOffsetOfLastLine.
@Test
public void replacementsMustNotReferToNotExistingOffsetOfLastLine() throws Exception {
FixReplacement fixReplacement = new FixReplacement(filePath1, new Range(3, 0, 3, 11), "modified");
mockFileContent(filePath1, "First line\nSecond line\nThird line\n");
replay(fileContentUtil);
expectedException.expect(ResourceConflictException.class);
toTreeModifications(fixReplacement);
}
use of com.google.gerrit.reviewdb.client.FixReplacement in project gerrit by GerritCodeReview.
the class FixReplacementInterpreterTest method replacementsDoNotNeedToBeOrderedAccordingToRange.
@Test
public void replacementsDoNotNeedToBeOrderedAccordingToRange() throws Exception {
FixReplacement fixReplacement1 = new FixReplacement(filePath1, new Range(1, 0, 2, 0), "1st modification\n");
FixReplacement fixReplacement2 = new FixReplacement(filePath1, new Range(3, 0, 4, 0), "2nd modification\n");
FixReplacement fixReplacement3 = new FixReplacement(filePath1, new Range(4, 0, 5, 0), "3rd modification\n");
mockFileContent(filePath1, "First line\nSecond line\nThird line\nFourth line\nFifth line\n");
replay(fileContentUtil);
List<TreeModification> treeModifications = toTreeModifications(fixReplacement2, fixReplacement1, fixReplacement3);
assertThatList(treeModifications).onlyElement().asChangeFileContentModification().newContent().isEqualTo("1st modification\nSecond line\n2nd modification\n3rd modification\nFifth line\n");
}
Aggregations