Search in sources :

Example 56 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method scanProjectWithTestDir.

@Test
public void scanProjectWithTestDir() throws IOException {
    File test = new File(baseDir, "test");
    test.mkdir();
    writeFile(test, "sampleTest.xoo", "Sample test xoo\ncontent");
    AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "").put("sonar.tests", "test").build()).execute();
    assertThat(result.inputFiles()).hasSize(1);
    assertThat(result.inputFile("test/sampleTest.xoo").type()).isEqualTo(InputFile.Type.TEST);
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 57 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method indexAnyFile.

@Test
public void indexAnyFile() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
    writeFile(srcDir, "sample.other", "Sample other\ncontent");
    AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
    assertThat(result.inputFiles()).hasSize(2);
    assertThat(result.inputFile("src/sample.other").type()).isEqualTo(InputFile.Type.MAIN);
    assertThat(result.inputFile("src/sample.other").relativePath()).isEqualTo("src/sample.other");
    assertThat(result.inputFile("src/sample.other").language()).isNull();
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 58 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method log_all_exclusions_properties_per_modules.

@Test
public void log_all_exclusions_properties_per_modules() throws IOException {
    File baseDir = temp.getRoot();
    File baseDirModuleA = new File(baseDir, "moduleA");
    File baseDirModuleB = new File(baseDir, "moduleB");
    File srcDirA = new File(baseDirModuleA, "src");
    srcDirA.mkdirs();
    File srcDirB = new File(baseDirModuleB, "src");
    srcDirB.mkdirs();
    writeFile(srcDirA, "sample.xoo", "Sample xoo\ncontent");
    writeFile(srcDirB, "sample.xoo", "Sample xoo\ncontent");
    AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").put("sonar.inclusions", "**/global.inclusions").put("sonar.test.inclusions", "**/global.test.inclusions").put("sonar.exclusions", "**/global.exclusions").put("sonar.test.exclusions", "**/global.test.exclusions").put("sonar.coverage.exclusions", "**/coverage.exclusions").put("sonar.cpd.exclusions", "**/cpd.exclusions").build()).execute();
    assertThat(logTester.logs(LoggerLevel.INFO)).containsSequence("Project configuration:", "  Included sources: **/global.inclusions", "  Excluded sources: **/global.exclusions, **/global.test.inclusions", "  Included tests: **/global.test.inclusions", "  Excluded tests: **/global.test.exclusions", "  Excluded sources for coverage: **/coverage.exclusions", "  Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'moduleA'", "  Base dir: " + baseDirModuleA.getAbsolutePath(), "  Source paths: src", "  Included sources: **/global.inclusions", "  Excluded sources: **/global.exclusions, **/global.test.inclusions", "  Included tests: **/global.test.inclusions", "  Excluded tests: **/global.test.exclusions", "  Excluded sources for coverage: **/coverage.exclusions", "  Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'moduleB'", "  Base dir: " + baseDirModuleB.getAbsolutePath(), "  Source paths: src", "  Included sources: **/global.inclusions", "  Excluded sources: **/global.exclusions, **/global.test.inclusions", "  Included tests: **/global.test.inclusions", "  Excluded tests: **/global.test.exclusions", "  Excluded sources for coverage: **/coverage.exclusions", "  Excluded sources for duplication: **/cpd.exclusions", "Indexing files of module 'com.foo.project'", "  Base dir: " + baseDir.getAbsolutePath(), "  Included sources: **/global.inclusions", "  Excluded sources: **/global.exclusions, **/global.test.inclusions", "  Included tests: **/global.test.inclusions", "  Excluded tests: **/global.test.exclusions", "  Excluded sources for coverage: **/coverage.exclusions", "  Excluded sources for duplication: **/cpd.exclusions");
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 59 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method dont_publish_files_without_detected_language.

@Test
public void dont_publish_files_without_detected_language() throws IOException {
    Path mainDir = baseDir.toPath().resolve("src").resolve("main");
    Files.createDirectories(mainDir);
    Path testDir = baseDir.toPath().resolve("src").resolve("test");
    Files.createDirectories(testDir);
    writeFile(testDir.toFile(), "sample.java", "Sample xoo\ncontent");
    writeFile(mainDir.toFile(), "sample.xoo", "Sample xoo\ncontent");
    writeFile(mainDir.toFile(), "sample.java", "Sample xoo\ncontent");
    logTester.setLevel(LoggerLevel.DEBUG);
    AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src/main").put("sonar.tests", "src/test").build()).execute();
    assertThat(logTester.logs()).containsAnyOf("'src/main/sample.java' indexed with no language", "'src\\main\\sample.java' indexed with no language");
    assertThat(logTester.logs()).contains("3 files indexed");
    assertThat(logTester.logs()).contains("'src/main/sample.xoo' generated metadata with charset 'UTF-8'");
    assertThat(logTester.logs()).doesNotContain("'src/main/sample.java' generated metadata", "'src\\main\\sample.java' generated metadata");
    assertThat(logTester.logs()).doesNotContain("'src/test/sample.java' generated metadata", "'src\\test\\sample.java' generated metadata");
    DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
    assertThatThrownBy(() -> result.getReportComponent(javaInputFile)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find report for component");
}
Also used : Path(java.nio.file.Path) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 60 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method support_global_server_side_exclusions_for_multi_module_project.

@Test
public void support_global_server_side_exclusions_for_multi_module_project() throws IOException {
    File baseDir = temp.getRoot();
    File baseDirModuleA = new File(baseDir, "moduleA");
    File baseDirModuleB = new File(baseDir, "moduleB");
    File srcDirA = new File(baseDirModuleA, "src");
    srcDirA.mkdirs();
    File srcDirB = new File(baseDirModuleB, "src");
    srcDirB.mkdirs();
    writeFile(srcDirA, "sample.xoo", "Sample xoo\ncontent");
    writeFile(srcDirB, "sample.xoo", "Sample xoo\ncontent");
    tester.addGlobalServerSettings(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*.xoo");
    AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").build()).execute();
    InputFile fileA = result.inputFile("moduleA/src/sample.xoo");
    assertThat(fileA).isNull();
    InputFile fileB = result.inputFile("moduleB/src/sample.xoo");
    assertThat(fileB).isNull();
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)86 AnalysisResult (org.sonar.scanner.mediumtest.AnalysisResult)86 File (java.io.File)80 InputFile (org.sonar.api.batch.fs.InputFile)54 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)33 ExternalIssue (org.sonar.scanner.protocol.output.ScannerReport.ExternalIssue)15 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)15 List (java.util.List)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Rule (org.junit.Rule)6 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)6 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 XooPlugin (org.sonar.xoo.XooPlugin)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 ArrayList (java.util.ArrayList)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)3 AnalysisBuilder (org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2