Search in sources :

Example 16 with BlameOutput

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Path(java.nio.file.Path) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 17 with BlameOutput

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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) Date(java.util.Date) SVNStatus(org.tmatesoft.svn.core.wc.SVNStatus) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BlameInput(org.sonar.api.batch.scm.BlameCommand.BlameInput) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) Mockito.doThrow(org.mockito.Mockito.doThrow) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Parameterized(org.junit.runners.Parameterized) StandardOpenOption(java.nio.file.StandardOpenOption) FileSystem(org.sonar.api.batch.fs.FileSystem) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) List(java.util.List) SVNStatusClient(org.tmatesoft.svn.core.wc.SVNStatusClient) Mockito.any(org.mockito.Mockito.any) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) InputFile(org.sonar.api.batch.fs.InputFile) SVNWCUtil(org.tmatesoft.svn.core.wc.SVNWCUtil) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) SVNDepth(org.tmatesoft.svn.core.SVNDepth) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) SvnCodec(org.tmatesoft.svn.core.internal.wc2.compat.SvnCodec) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) ArgumentCaptor(org.mockito.ArgumentCaptor) Before(org.junit.Before) ISVNOptions(org.tmatesoft.svn.core.wc.ISVNOptions) Files(java.nio.file.Files) SVNStatusType(org.tmatesoft.svn.core.wc.SVNStatusType) SvnCheckout(org.tmatesoft.svn.core.wc2.SvnCheckout) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) File(java.io.File) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) Mockito.verify(org.mockito.Mockito.verify) ISVNAuthenticationManager(org.tmatesoft.svn.core.auth.ISVNAuthenticationManager) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Paths(java.nio.file.Paths) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNUpdateClient(org.tmatesoft.svn.core.wc.SVNUpdateClient) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) TemporaryFolder(org.junit.rules.TemporaryFolder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 18 with BlameOutput

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"));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) PathResolver(org.sonar.api.scan.filesystem.PathResolver) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) AnalysisWarnings(org.sonar.api.notifications.AnalysisWarnings) Test(org.junit.Test)

Aggregations

File (java.io.File)18 Test (org.junit.Test)18 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)18 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)18 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)16 InputFile (org.sonar.api.batch.fs.InputFile)15 ZipFile (java.util.zip.ZipFile)8 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)8 BlameLine (org.sonar.api.batch.scm.BlameLine)7 Date (java.util.Date)5 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 Arrays (java.util.Arrays)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3