Search in sources :

Example 61 with DefaultFileSystem

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

the class PostAnalysisIssueFilterTest method setUp.

@Before
public void setUp() {
    File absoluteBaseDir = new File(MODULE_BASE_DIR).getAbsoluteFile();
    DefaultFileSystem fileSystem = new DefaultFileSystem(absoluteBaseDir);
    DefaultInputFile inputFile = new TestInputFileBuilder("", absoluteBaseDir, new File(absoluteBaseDir, FILE_KEY)).setLanguage("java").setType(InputFile.Type.MAIN).build();
    fileSystem.add(inputFile);
    postAnalysisIssueFilter = new PostAnalysisIssueFilter(fileSystem);
    context = mock(JavaFileScannerContext.class);
    when(context.getFile()).thenReturn(inputFile.file());
    when(context.getFileKey()).thenReturn(inputFile.key());
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) JavaFileScannerContext(org.sonar.plugins.java.api.JavaFileScannerContext) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) 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) Before(org.junit.Before)

Example 62 with DefaultFileSystem

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

the class ModuleSensorOptimizerTest method prepare.

@Before
public void prepare() throws Exception {
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    settings = new MapSettings();
    optimizer = new ModuleSensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 63 with DefaultFileSystem

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

the class ModuleSensorContextTest method prepare.

@Before
public void prepare() throws Exception {
    activeRules = new ActiveRulesBuilder().build();
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    MetricFinder metricFinder = mock(MetricFinder.class);
    when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
    when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
    settings = new MapSettings();
    sensorStorage = mock(SensorStorage.class);
    branchConfiguration = mock(BranchConfiguration.class);
    runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) MapSettings(org.sonar.api.config.internal.MapSettings) MetricFinder(org.sonar.api.batch.measure.MetricFinder) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Before(org.junit.Before)

Example 64 with DefaultFileSystem

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

Example 65 with DefaultFileSystem

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

the class SensorContextTesterTest method testFs.

@Test
public void testFs() throws Exception {
    DefaultFileSystem fs = new DefaultFileSystem(temp.newFolder());
    tester.setFileSystem(fs);
    assertThat(tester.fileSystem().baseDir()).isNotEqualTo(baseDir);
}
Also used : 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