Search in sources :

Example 11 with DefaultFileSystem

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

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

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

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

the class XooBlameCommandTest method prepare.

@Before
public void prepare() throws IOException {
    baseDir = temp.newFolder();
    fs = new DefaultFileSystem(baseDir.toPath());
    input = mock(BlameInput.class);
    when(input.fileSystem()).thenReturn(fs);
}
Also used : BlameInput(org.sonar.api.batch.scm.BlameCommand.BlameInput) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 15 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.

the class XmlAnalyzerTest method should_interrupt_analysis_when_InterruptedException_is_thrown.

@Test
public void should_interrupt_analysis_when_InterruptedException_is_thrown() {
    DefaultFileSystem fs = new DefaultFileSystem(new File(""));
    File pomFile = new File(VALID_POM);
    fs.add(new TestInputFileBuilder("", pomFile.getAbsolutePath()).build());
    XmlCheckThrowingException check = new XmlCheckThrowingException(new RuntimeException("Analysis cancelled"));
    SonarComponents sonarComponents = createSonarComponentsMock(fs, check);
    thrown.expectMessage("Analysis cancelled");
    thrown.expect(RuntimeException.class);
    XmlAnalyzer analyzer = new XmlAnalyzer(sonarComponents, check);
    analyzer.scan(Lists.newArrayList(pomFile));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SonarComponents(org.sonar.java.SonarComponents) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)113 File (java.io.File)70 InputFile (org.sonar.api.batch.fs.InputFile)58 Test (org.junit.Test)46 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)46 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)38 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)37 Test (org.junit.jupiter.api.Test)26 SonarComponents (org.sonar.java.SonarComponents)24 Before (org.junit.Before)22 MapSettings (org.sonar.api.config.internal.MapSettings)21 PathResolver (org.sonar.api.scan.filesystem.PathResolver)20 JavaCheck (org.sonar.plugins.java.api.JavaCheck)14 AnalyzerMessage (org.sonar.java.AnalyzerMessage)11 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)10 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)8 Path (java.nio.file.Path)7 ClasspathForMain (org.sonar.java.classpath.ClasspathForMain)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6