use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.
the class JGitBlameCommandTest method dontFailOnSymlink.
@Test
public void dontFailOnSymlink() throws IOException {
assumeTrue(!System2.INSTANCE.isOsWindows());
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);
String relativePath = DUMMY_JAVA;
String relativePath2 = "src/main/java/org/dummy/Dummy2.java";
DefaultInputFile inputFile = new TestInputFileBuilder("foo", relativePath).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile);
DefaultInputFile inputFile2 = new TestInputFileBuilder("foo", relativePath2).setModuleBaseDir(baseDir.toPath()).build();
fs.add(inputFile2);
// Create symlink
Files.createSymbolicLink(inputFile2.file().toPath(), inputFile.file().toPath());
BlameOutput blameResult = mock(BlameOutput.class);
when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile, inputFile2));
jGitBlameCommand.blame(input, blameResult);
}
use of org.sonar.api.batch.scm.BlameCommand.BlameOutput in project sonarqube by SonarSource.
the class SvnBlameCommandTest method shouldNotFailIfFileContainsLocalModification.
@Test
public void shouldNotFailIfFileContainsLocalModification() 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(28).setModuleBaseDir(baseDir.toPath()).build();
Files.write(baseDir.toPath().resolve(DUMMY_JAVA), "\n//foo".getBytes(), StandardOpenOption.APPEND);
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 shouldNotFailOnWrongFilename.
// SONARSCSVN-7
@Test
public void shouldNotFailOnWrongFilename() 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.toLowerCase()).setLines(27).setModuleBaseDir(baseDir.toPath()).build();
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 blame_givenCredentialsSupplied_doNotlogWarning.
@Test
public void blame_givenCredentialsSupplied_doNotlogWarning() throws Exception {
BlameOutput output = mock(BlameOutput.class);
InputFile inputFile = mock(InputFile.class);
SvnConfiguration properties = mock(SvnConfiguration.class);
SvnBlameCommand svnBlameCommand = new SvnBlameCommand(properties);
SVNClientManager clientManager = mock(SVNClientManager.class);
SVNLogClient logClient = mock(SVNLogClient.class);
SVNStatusClient statusClient = mock(SVNStatusClient.class);
SVNStatus status = mock(SVNStatus.class);
when(properties.isEmpty()).thenReturn(true);
when(clientManager.getLogClient()).thenReturn(logClient);
when(clientManager.getStatusClient()).thenReturn(statusClient);
when(status.getContentsStatus()).thenReturn(SVNStatusType.STATUS_NORMAL);
when(inputFile.file()).thenReturn(mock(File.class));
when(statusClient.doStatus(any(File.class), anyBoolean())).thenReturn(status);
doThrow(SVNAuthenticationException.class).when(logClient).doAnnotate(any(File.class), any(SVNRevision.class), any(SVNRevision.class), any(SVNRevision.class), anyBoolean(), anyBoolean(), any(AnnotationHandler.class), eq(null));
assertThrows(IllegalStateException.class, () -> {
svnBlameCommand.blame(clientManager, inputFile, output);
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
});
}
use of org.sonar.api.batch.scm.BlameCommand.BlameOutput 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);
}
Aggregations