Search in sources :

Example 66 with DefaultFileSystem

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

the class PythonXUnitSensorTest method setUp.

@Before
public void setUp() {
    settings.clear();
    fs = new DefaultFileSystem(baseDir);
    sensor = new PythonXUnitSensor(new ConfigurationBridge(settings), fs, analysisWarnings);
}
Also used : ConfigurationBridge(org.sonar.api.config.internal.ConfigurationBridge) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 67 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-openedge by Riverside-Software.

the class InputFileUtilsTest method testDifferentFileSystem.

@Test
public void testDifferentFileSystem() throws Exception {
    // Only on Windows...
    if (!System.getProperty("os.name").toLowerCase().startsWith("win"))
        return;
    SensorContextTester context = TestProjectSensorContext.createContext();
    InputFile f1 = context.fileSystem().inputFile(context.fileSystem().predicates().hasFilename("test1.p"));
    // Different file system, we just return the file name
    // Will fail in the unexpected case when unit tests are executed on the X: drive
    Assert.assertEquals(InputFileUtils.getRelativePath(f1, new DefaultFileSystem(new File("X:\\"))), "test1.p");
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.testng.annotations.Test)

Example 68 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 69 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 70 with DefaultFileSystem

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

the class XooTokenizerTest method prepare.

@Before
public void prepare() throws IOException {
    baseDir = temp.newFolder();
    fileSystem = new DefaultFileSystem(baseDir.toPath());
    when(context.fileSystem()).thenReturn(fileSystem);
    settings = new MapSettings();
    when(context.settings()).thenReturn(settings);
}
Also used : MapSettings(org.sonar.api.config.MapSettings) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)126 File (java.io.File)79 InputFile (org.sonar.api.batch.fs.InputFile)70 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)55 Test (org.junit.Test)54 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)52 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)39 Test (org.junit.jupiter.api.Test)27 SonarComponents (org.sonar.java.SonarComponents)25 Before (org.junit.Before)23 MapSettings (org.sonar.api.config.internal.MapSettings)22 PathResolver (org.sonar.api.scan.filesystem.PathResolver)20 JavaCheck (org.sonar.plugins.java.api.JavaCheck)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 AnalyzerMessage (org.sonar.java.AnalyzerMessage)11 Path (java.nio.file.Path)10 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)10 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)8 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)8 FileLinesContext (org.sonar.api.measures.FileLinesContext)7