use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class JGitBlameCommandTest method testBlameOnNestedModule.
@Test
public void testBlameOnNestedModule() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("dummy-git-nested.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git-nested/dummy-project");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
jGitBlameCommand.blame(input, blameResult);
Date revisionDate = DateUtils.parseDateTime("2012-07-17T16:12:48+0200");
String revision = "6b3aab35a3ea32c1636fee56f996e677653c48ea";
String author = "david@gageot.net";
verify(blameResult).blameResult(inputFile, Arrays.asList(new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author)));
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class DefaultBlameOutputTest method shouldFailIfNullRevision.
@Test
public void shouldFailIfNullRevision() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
var blameOUtput = new DefaultBlameOutput(null, analysisWarnings, singletonList(file));
var lines = singletonList(new BlameLine().date(new Date()).author("guy"));
assertThatThrownBy(() -> blameOUtput.blameResult(file, lines)).isInstanceOf(IllegalArgumentException.class).hasMessage("Blame revision is blank for file " + file + " at line 1");
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class DefaultBlameOutputTest method shouldNotFailIfNotSameNumberOfLines.
@Test
public void shouldNotFailIfNotSameNumberOfLines() {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(10).build();
new DefaultBlameOutput(null, analysisWarnings, singletonList(file)).blameResult(file, singletonList(new BlameLine().revision("1").author("guy")));
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class SvnBlameCommandTest method testParsingOfOutputWithMergeHistory.
@Test
public void testParsingOfOutputWithMergeHistory() throws Exception {
File repoDir = unzip("repo-svn-with-merge.zip");
String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
File baseDir = new File(checkout(scmUrl), "dummy-svn/trunk");
when(fs.baseDir()).thenReturn(baseDir);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setLines(27).setModuleBaseDir(baseDir.toPath()).build();
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(singletonList(inputFile));
newSvnBlameCommand().blame(input, blameResult);
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
verify(blameResult).blameResult(eq(inputFile), captor.capture());
List<BlameLine> result = captor.getValue();
assertThat(result).hasSize(27);
Date commitDate = new Date(1342691097393L);
Date revision6Date = new Date(1415262184300L);
BlameLine[] expected = IntStream.rangeClosed(1, 27).mapToObj(i -> {
if (i == 2 || i == 24) {
return new BlameLine().date(revision6Date).revision("6").author("henryju");
} else {
return new BlameLine().date(commitDate).revision("2").author("dgageot");
}
}).toArray(BlameLine[]::new);
assertThat(result).containsExactly(expected);
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class XooBlameCommand method convertToBlameLine.
private static BlameLine convertToBlameLine(Date now, CSVRecord csvRecord) {
checkState(csvRecord.size() >= 3, "Not enough fields on line %s", csvRecord);
String revision = trimToNull(csvRecord.get(0));
String author = trimToNull(csvRecord.get(1));
BlameLine blameLine = new BlameLine().revision(revision).author(author);
String dateStr = trimToNull(csvRecord.get(2));
if (dateStr != null) {
// try to load a relative number of days
try {
int days = Integer.parseInt(dateStr);
blameLine.date(DateUtils.addDays(now, days));
} catch (NumberFormatException e) {
Date dateTime = DateUtils.parseDateTimeQuietly(dateStr);
if (dateTime != null) {
blameLine.date(dateTime);
} else {
// Will throw an exception, when date is not in format "yyyy-MM-dd"
blameLine.date(DateUtils.parseDate(dateStr));
}
}
}
return blameLine;
}
Aggregations