use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class XooBlameCommandTest method testBlameWithRelativeDate.
@Test
public void testBlameWithRelativeDate() throws IOException {
File source = new File(baseDir, "src/foo.xoo");
FileUtils.write(source, "sample content");
File scm = new File(baseDir, "src/foo.xoo.scm");
FileUtils.write(scm, "123,julien,-10\n234,julien,-10");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput result = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
new XooBlameCommand().blame(input, result);
Predicate<Date> datePredicate = argument -> {
Date approximate = DateUtils.addDays(new Date(), -10);
return argument.getTime() > approximate.getTime() - 5000 && argument.getTime() < approximate.getTime() + 5000;
};
ArgumentCaptor<List<BlameLine>> blameLinesCaptor = ArgumentCaptor.forClass(List.class);
verify(result).blameResult(eq(inputFile), blameLinesCaptor.capture());
assertThat(blameLinesCaptor.getValue()).extracting(BlameLine::date).allMatch(datePredicate);
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class XooBlameCommandTest method blame_containing_author_with_comma.
@Test
public void blame_containing_author_with_comma() throws IOException {
File source = new File(baseDir, "src/foo.xoo");
FileUtils.write(source, "sample content");
File scm = new File(baseDir, "src/foo.xoo.scm");
FileUtils.write(scm, "\"123\",\"john,doe\",\"2019-01-22\"");
DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage(Xoo.KEY).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
BlameOutput result = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
new XooBlameCommand().blame(input, result);
verify(result).blameResult(inputFile, singletonList(new BlameLine().revision("123").author("john,doe").date(DateUtils.parseDate("2019-01-22"))));
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class XooBlameCommand method processFile.
@VisibleForTesting
protected void processFile(InputFile inputFile, BlameOutput result) {
File ioFile = inputFile.file();
File scmDataFile = new File(ioFile.getParentFile(), ioFile.getName() + SCM_EXTENSION);
if (!scmDataFile.exists()) {
return;
}
try {
List<BlameLine> blame = readFile(scmDataFile);
result.blameResult(inputFile, blame);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class JGitBlameCommandTest method testBlame.
@Test
public void testBlame() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("dummy-git.zip", projectDir);
JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
File baseDir = new File(projectDir, "dummy-git");
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 revisionDate1 = DateUtils.parseDateTime("2012-07-17T16:12:48+0200");
String revision1 = "6b3aab35a3ea32c1636fee56f996e677653c48ea";
String author1 = "david@gageot.net";
// second commit, which has a commit date different than the author date
Date revisionDate2 = DateUtils.parseDateTime("2015-05-19T13:31:09+0200");
String revision2 = "0d269c1acfb8e6d4d33f3c43041eb87e0df0f5e7";
String author2 = "duarte.meneses@sonarsource.com";
List<BlameLine> expectedBlame = new LinkedList<>();
for (int i = 0; i < 25; i++) {
expectedBlame.add(new BlameLine().revision(revision1).date(revisionDate1).author(author1));
}
for (int i = 0; i < 3; i++) {
expectedBlame.add(new BlameLine().revision(revision2).date(revisionDate2).author(author2));
}
for (int i = 0; i < 1; i++) {
expectedBlame.add(new BlameLine().revision(revision1).date(revisionDate1).author(author1));
}
verify(blameResult).blameResult(inputFile, expectedBlame);
}
use of org.sonar.api.batch.scm.BlameLine in project sonarqube by SonarSource.
the class JGitBlameCommandTest method return_early_when_clone_with_reference_detected.
@Test
public void return_early_when_clone_with_reference_detected() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("dummy-git-reference-clone.zip", projectDir);
Path baseDir = projectDir.toPath().resolve("dummy-git2");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).setModuleBaseDir(baseDir).build();
when(input.filesToBlame()).thenReturn(Collections.singleton(inputFile));
// register warning
AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
JGitBlameCommand jGitBlameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings);
TestBlameOutput output = new TestBlameOutput();
jGitBlameCommand.blame(input, output);
assertThat(logTester.logs()).first().matches(s -> s.contains("This git repository references another local repository which is not well supported"));
// contains commits referenced from the old clone and commits in the new clone
assertThat(output.blame).containsKey(inputFile);
assertThat(output.blame.get(inputFile).stream().map(BlameLine::revision)).containsOnly("6b3aab35a3ea32c1636fee56f996e677653c48ea", "843c7c30d7ebd9a479e8f1daead91036c75cbc4e", "0d269c1acfb8e6d4d33f3c43041eb87e0df0f5e7");
verifyZeroInteractions(analysisWarnings);
}
Aggregations