Search in sources :

Example 1 with AnalysisBuilder

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

the class HighlightingMediumTest method computeInvalidOffsets.

@Test
public void computeInvalidOffsets() throws IOException {
    File baseDir = temp.newFolder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
    FileUtils.write(xooFile, "Sample xoo\ncontent plop");
    FileUtils.write(xoohighlightingFile, "1:0:1:10:s\n2:18:2:18:k");
    AnalysisBuilder analysisBuilder = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build());
    assertThatThrownBy(() -> analysisBuilder.execute()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Error processing line 2").hasCauseInstanceOf(IllegalArgumentException.class);
}
Also used : AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Test(org.junit.Test)

Example 2 with AnalysisBuilder

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

the class ScmMediumTest method forceReload.

@Test
public void forceReload() throws IOException, URISyntaxException {
    File baseDir = prepareProject();
    File xooFileNoScm = new File(baseDir, SAME_CONTENT_SCM_ON_SERVER_XOO);
    FileUtils.write(xooFileNoScm, SAMPLE_XOO_CONTENT, StandardCharsets.UTF_8);
    File xooScmFile = new File(baseDir, SAME_CONTENT_SCM_ON_SERVER_XOO + ".scm");
    FileUtils.write(xooScmFile, // revision,author,dateTime
    "1,foo,2013-01-04\n" + "1,bar,2013-01-04\n", StandardCharsets.UTF_8);
    AnalysisBuilder analysisBuilder = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.scm.provider", "xoo").put("sonar.scm.forceReloadAll", "true").build());
    analysisBuilder.execute();
    ScannerReport.Changesets file1Scm = getChangesets(baseDir, "src/sample.xoo");
    assertThat(file1Scm).isNotNull();
    ScannerReport.Changesets file2Scm = getChangesets(baseDir, SAME_CONTENT_SCM_ON_SERVER_XOO);
    assertThat(file2Scm).isNotNull();
}
Also used : ScannerReport(org.sonar.scanner.protocol.output.ScannerReport) AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) File(java.io.File) Test(org.junit.Test)

Example 3 with AnalysisBuilder

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

the class FileSystemMediumTest method scanProjectWithWrongCase.

// SONAR-6719
@Test
public void scanProjectWithWrongCase() {
    // To please the quality gate, don't use assumeTrue, or the test will be reported as skipped
    File projectDir = new File("test-resources/mediumtest/xoo/sample");
    AnalysisBuilder analysis = tester.newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.sources", "XOURCES").property("sonar.tests", "TESTX").property("sonar.scm.exclusions.disabled", "true");
    if (System2.INSTANCE.isOsWindows()) {
        // Windows is file path case-insensitive
        AnalysisResult result = analysis.execute();
        assertThat(result.inputFiles()).hasSize(8);
        assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly("testx/ClassOneTest.xoo.measures", "xources/hello/helloscala.xoo.measures", "xources/hello/HelloJava.xoo.measures", "testx/ClassOneTest.xoo", "xources/hello/HelloJava.xoo.scm", "xources/hello/helloscala.xoo", "testx/ClassOneTest.xoo.scm", "xources/hello/HelloJava.xoo");
    } else if (System2.INSTANCE.isOsMac()) {
        AnalysisResult result = analysis.execute();
        assertThat(result.inputFiles()).hasSize(8);
        assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly("TESTX/ClassOneTest.xoo.measures", "XOURCES/hello/helloscala.xoo.measures", "XOURCES/hello/HelloJava.xoo.measures", "TESTX/ClassOneTest.xoo", "XOURCES/hello/HelloJava.xoo.scm", "XOURCES/hello/helloscala.xoo", "TESTX/ClassOneTest.xoo.scm", "XOURCES/hello/HelloJava.xoo");
    } else {
        assertThatThrownBy(() -> analysis.execute()).isInstanceOf(MessageException.class).hasMessageContaining("The folder 'TESTX' does not exist for 'sample'");
    }
}
Also used : AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) 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 4 with AnalysisBuilder

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

the class FileSystemMediumTest method two_languages_with_same_extension.

@Test
public void two_languages_with_same_extension() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
    writeFile(srcDir, "sample.xoo2", "Sample xoo 2\ncontent");
    AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
    assertThat(result.inputFiles()).hasSize(2);
    AnalysisBuilder analysisBuilder = tester.newAnalysis().properties(builder.put("sonar.lang.patterns.xoo2", "**/*.xoo").build());
    assertThatThrownBy(analysisBuilder::execute).isInstanceOf(MessageException.class).hasMessage("Language of file 'src" + File.separator + "sample.xoo' can not be decided as the file matches patterns of both sonar.lang.patterns.xoo : **/*.xoo and sonar.lang.patterns.xoo2 : **/*.xoo");
    // SONAR-9561
    result = tester.newAnalysis().properties(builder.put("sonar.exclusions", "**/sample.xoo").build()).execute();
    assertThat(result.inputFiles()).hasSize(1);
}
Also used : MessageException(org.sonar.api.utils.MessageException) AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) 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 5 with AnalysisBuilder

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

the class HighlightingMediumTest method saveTwice.

@Test
public void saveTwice() throws IOException {
    File baseDir = temp.newFolder();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent plop");
    AnalysisBuilder analysisBuilder = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").put("sonar.it.savedatatwice", "true").build());
    ;
    assertThatThrownBy(() -> analysisBuilder.execute()).isInstanceOf(UnsupportedOperationException.class).hasMessageContaining("Trying to save highlighting twice for the same file is not supported");
}
Also used : AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)5 Test (org.junit.Test)5 AnalysisBuilder (org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder)5 InputFile (org.sonar.api.batch.fs.InputFile)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 AnalysisResult (org.sonar.scanner.mediumtest.AnalysisResult)2 MessageException (org.sonar.api.utils.MessageException)1 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)1