Search in sources :

Example 36 with DefaultFileSystem

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

the class ClasspathForTestTest method empty_libraries_if_only_main_files.

@Test
void empty_libraries_if_only_main_files() throws Exception {
    fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
    fs.add(TestUtils.emptyInputFile("plop.java"));
    javaTestClasspath = createJavaClasspath();
    assertThat(javaTestClasspath.getElements()).isEmpty();
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.jupiter.api.Test)

Example 37 with DefaultFileSystem

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

the class GeneratedFileTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    expected = tmp.resolve("file.jsp");
    Files.write(expected, "content".getBytes(StandardCharsets.UTF_8));
    fs = new DefaultFileSystem(tmp);
    actual = new GeneratedFile(expected);
}
Also used : DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with DefaultFileSystem

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

the class SmapFileTest method test.

@Test
void test() throws Exception {
    String sourceMap = "SMAP\n" + "test_jsp.java\n" + "JSP\n" + "*S JSP\n" + "*F\n" + "+ 0 test.jsp\n" + "WEB-INF/test.jsp\n" + "2 Incl.xyz\n" + "*L\n" + "1,5:116,0\n" + "123:207\n" + "130,3:210\n" + "140:250,7\n" + "160,3:300,2\n" + "160#2,3:300,2\n" + "160,3:300,2\n" + "*E\n";
    DefaultFileSystem fs = new DefaultFileSystem(temporaryFolder);
    DefaultInputFile inputFile = TestInputFileBuilder.create("module", temporaryFolder.toFile(), temporaryFolder.resolve("WEB-INF/test.jsp").toFile()).build();
    fs.add(inputFile);
    SmapFile smap = new SmapFile(temporaryFolder, sourceMap, temporaryFolder, fs);
    assertThat(smap.getGeneratedFile()).isEqualTo(temporaryFolder.resolve("test_jsp.java"));
    assertThat(smap.getFileSection()).containsExactly(entry(0, new SmapFile.FileInfo(0, "test.jsp", "WEB-INF/test.jsp", null)), entry(2, new SmapFile.FileInfo(2, "Incl.xyz", null, null)));
    assertThat(smap.getLineSection()).containsExactly(new SmapFile.LineInfo(1, 0, 5, 116, 0), new SmapFile.LineInfo(123, 0, 1, 207, 1), new SmapFile.LineInfo(130, 0, 3, 210, 1), new SmapFile.LineInfo(140, 0, 1, 250, 7), new SmapFile.LineInfo(160, 0, 3, 300, 2), new SmapFile.LineInfo(160, 2, 3, 300, 2), new SmapFile.LineInfo(160, 2, 3, 300, 2));
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.jupiter.api.Test)

Example 39 with DefaultFileSystem

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

the class SurefireUtilsTest method return_default_value_if_property_unset.

@Test
void return_default_value_if_property_unset() throws Exception {
    MapSettings settings = new MapSettings();
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(1);
    File directory = directories.get(0);
    assertThat(directory.getCanonicalPath()).endsWith("target" + File.separator + "surefire-reports");
    assertThat(directory).doesNotExist();
    assertThat(directory.isDirectory()).isFalse();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.jupiter.api.Test)

Example 40 with DefaultFileSystem

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

the class SurefireUtilsTest method should_get_report_paths_from_property.

@Test
void should_get_report_paths_from_property() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(2);
    File directory1 = directories.get(0);
    assertThat(directory1).exists().isDirectory();
    File directory2 = directories.get(1);
    assertThat(directory2).exists().isDirectory();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)119 File (java.io.File)73 InputFile (org.sonar.api.batch.fs.InputFile)63 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)52 Test (org.junit.Test)49 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)45 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)38 Test (org.junit.jupiter.api.Test)27 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 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 ClasspathForMain (org.sonar.java.classpath.ClasspathForMain)7