use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.
the class SvnBlameCommandTest method shouldNotFailOnUncommitedDir.
@Test
public void shouldNotFailOnUncommitedDir() throws Exception {
File repoDir = unzip("repo-svn.zip");
String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
File baseDir = new File(checkout(scmUrl), "dummy-svn");
when(fs.baseDir()).thenReturn(baseDir);
String relativePath = "src/main/java/org/dummy2/dummy/Dummy.java";
DefaultInputFile inputFile = new TestInputFileBuilder("foo", relativePath).setLines(28).setModuleBaseDir(baseDir.toPath()).build();
Path filepath = new File(baseDir, relativePath).toPath();
Files.createDirectories(filepath.getParent());
Files.write(filepath, "package org.dummy;\npublic class Dummy {}".getBytes());
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(singletonList(inputFile));
newSvnBlameCommand().blame(input, blameResult);
verifyNoInteractions(blameResult);
}
use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.
the class SvnBlameCommandTest method testParsingOfOutput.
@Test
public void testParsingOfOutput() throws Exception {
File repoDir = unzip("repo-svn.zip");
String scmUrl = "file:///" + unixPath(new File(repoDir, "repo-svn"));
File baseDir = new File(checkout(scmUrl), "dummy-svn");
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);
BlameLine[] expected = IntStream.rangeClosed(1, 27).mapToObj(i -> new BlameLine().date(commitDate).revision("2").author("dgageot")).toArray(BlameLine[]::new);
assertThat(result).containsExactly(expected);
}
use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.
the class JGitBlameCommandTest method return_early_when_shallow_clone_detected.
@Test
public void return_early_when_shallow_clone_detected() throws IOException {
File projectDir = temp.newFolder();
javaUnzip("shallow-git.zip", projectDir);
File baseDir = new File(projectDir, "shallow-git");
DefaultFileSystem fs = new DefaultFileSystem(baseDir);
when(input.fileSystem()).thenReturn(fs);
DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).build();
when(input.filesToBlame()).thenReturn(Collections.singleton(inputFile));
// register warning with default wrapper
AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class);
JGitBlameCommand jGitBlameCommand = new JGitBlameCommand(new PathResolver(), analysisWarnings);
BlameOutput output = mock(BlameOutput.class);
jGitBlameCommand.blame(input, output);
assertThat(logTester.logs()).first().matches(s -> s.contains("Shallow clone detected, no blame information will be provided."));
verifyZeroInteractions(output);
verify(analysisWarnings).addUnique(startsWith("Shallow clone detected"));
}
Aggregations