Search in sources :

Example 71 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder 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 72 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class JGitBlameCommandTest method testBlameOnNestedModule.

@Test
public void testBlameOnNestedModule() throws IOException {
    File projectDir = temp.newFolder();
    javaUnzip("dummy-git-nested.zip", projectDir);
    JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
    File baseDir = new File(projectDir, "dummy-git-nested/dummy-project");
    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 revisionDate = DateUtils.parseDateTime("2012-07-17T16:12:48+0200");
    String revision = "6b3aab35a3ea32c1636fee56f996e677653c48ea";
    String author = "david@gageot.net";
    verify(blameResult).blameResult(inputFile, Arrays.asList(new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author), new BlameLine().revision(revision).date(revisionDate).author(author)));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) BlameLine(org.sonar.api.batch.scm.BlameLine) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) 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) Date(java.util.Date) Test(org.junit.Test)

Example 73 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class JGitBlameCommandTest method properFailureIfNotAGitProject.

@Test
public void properFailureIfNotAGitProject() throws IOException {
    File projectDir = temp.newFolder();
    javaUnzip("dummy-git.zip", projectDir);
    JGitBlameCommand jGitBlameCommand = newJGitBlameCommand();
    File baseDir = new File(projectDir, "dummy-git");
    // Delete .git
    FileUtils.forceDelete(new File(baseDir, ".git"));
    DefaultFileSystem fs = new DefaultFileSystem(baseDir);
    when(input.fileSystem()).thenReturn(fs);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", DUMMY_JAVA).build();
    fs.add(inputFile);
    BlameOutput blameResult = mock(BlameOutput.class);
    when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile));
    assertThatThrownBy(() -> jGitBlameCommand.blame(input, blameResult)).isInstanceOf(MessageException.class).hasMessageContaining("Not inside a Git work tree: ");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) MessageException(org.sonar.api.utils.MessageException) 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) Test(org.junit.Test)

Example 74 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder 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);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) 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) Test(org.junit.Test)

Example 75 with TestInputFileBuilder

use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method duplicateSignificantCode.

@Test(expected = UnsupportedOperationException.class)
public void duplicateSignificantCode() throws Exception {
    InputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.java").setModuleBaseDir(temp.newFolder().toPath()).build();
    DefaultSignificantCode h = new DefaultSignificantCode(null).onFile(inputFile);
    underTest.store(h);
    underTest.store(h);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultSignificantCode(org.sonar.api.batch.sensor.code.internal.DefaultSignificantCode) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)199 Test (org.junit.Test)163 File (java.io.File)89 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)88 InputFile (org.sonar.api.batch.fs.InputFile)87 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)41 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)23 Before (org.junit.Before)22 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)16 SonarComponents (org.sonar.java.SonarComponents)13 JavaCheck (org.sonar.plugins.java.api.JavaCheck)13 BlameLine (org.sonar.api.batch.scm.BlameLine)12 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)9 Path (java.nio.file.Path)8 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 AnalyzerMessage (org.sonar.java.AnalyzerMessage)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 IOException (java.io.IOException)6 ZipFile (java.util.zip.ZipFile)6 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)6