Search in sources :

Example 1 with AnalysisWarnings

use of org.sonar.api.notifications.AnalysisWarnings 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);
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) PathResolver(org.sonar.api.scan.filesystem.PathResolver) 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)

Example 2 with AnalysisWarnings

use of org.sonar.api.notifications.AnalysisWarnings 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)2 Test (org.junit.Test)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 AnalysisWarnings (org.sonar.api.notifications.AnalysisWarnings)2 PathResolver (org.sonar.api.scan.filesystem.PathResolver)2 Path (java.nio.file.Path)1 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)1 BlameLine (org.sonar.api.batch.scm.BlameLine)1