Search in sources :

Example 51 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssueJsonReportTest method precise_issue_location.

@Test
public void precise_issue_location() throws IOException {
    orchestrator.getServer().restoreProfile(getResource("multiline.xml"));
    orchestrator.getServer().provisionProject("sample-multiline", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample-multiline", "xoo", "multiline");
    File projectDir = ItUtils.projectDir("shared/xoo-precise-issues");
    SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
    BuildResult result = orchestrator.executeBuild(runner);
    assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(2);
    JSONObject obj = ItUtils.getJSONReport(result);
    JSONArray issues = (JSONArray) obj.get("issues");
    JSONObject issue1 = (JSONObject) issues.get(0);
    JSONObject issue2 = (JSONObject) issues.get(1);
    assertThat(issue1.get("startLine")).isIn(6L);
    assertThat(issue1.get("line")).isIn(6L);
    assertThat(issue1.get("endLine")).isIn(6L);
    assertThat(issue1.get("startOffset")).isIn(27L);
    assertThat(issue1.get("endOffset")).isIn(32L);
    assertThat(issue2.get("startLine")).isIn(9L);
    assertThat(issue2.get("line")).isIn(9L);
    assertThat(issue2.get("endLine")).isIn(15L);
    assertThat(issue2.get("startOffset")).isIn(20L);
    assertThat(issue2.get("endOffset")).isIn(2L);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 52 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssueJsonReportTest method test_json_report_on_branch.

@Test
public void test_json_report_on_branch() throws Exception {
    orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
    orchestrator.getServer().provisionProject("sample:mybranch", "Sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample:mybranch", "xoo", "one-issue-per-line");
    SonarScanner scan = SonarScanner.create(ItUtils.projectDir("analysis/tracking/v1")).setProperty("sonar.projectDate", "2013-05-01").setProperty("sonar.branch", "mybranch");
    orchestrator.executeBuild(scan);
    // issues mode scan -> 2 new issues and 13 existing issues
    File projectDir = ItUtils.projectDir("analysis/tracking/v2");
    SonarScanner issuesModeScan = SonarScanner.create(projectDir).setProperty("sonar.analysis.mode", "issues").setProperty("sonar.userHome", temp.newFolder().getAbsolutePath()).setProperty("sonar.report.export.path", "sonar-report.json").setProperty("sonar.issuesReport.console.enable", "true").setProperty("sonar.projectDate", "2013-05-02").setProperty("sonar.verbose", "true").setProperty("sonar.branch", "mybranch");
    orchestrator.executeBuild(issuesModeScan);
    File report = new File(projectDir, ".sonar/sonar-report.json");
    assertThat(report).isFile().exists();
    String json = sanitize(FileUtils.readFileToString(report));
    String expectedJson = expected("report-on-single-module-branch.json");
    JSONAssert.assertEquals(expectedJson, json, false);
}
Also used : File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 53 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssueJsonReportTest method issue_line.

@Test
public void issue_line() throws IOException {
    orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    File projectDir = ItUtils.projectDir("shared/xoo-sample");
    SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
    BuildResult result = orchestrator.executeBuild(runner);
    assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
    JSONObject obj = ItUtils.getJSONReport(result);
    JSONArray issues = (JSONArray) obj.get("issues");
    for (Object issue : issues) {
        JSONObject jsonIssue = (JSONObject) issue;
        assertThat(jsonIssue.get("startLine")).isNotNull();
        assertThat(jsonIssue.get("line")).isEqualTo(jsonIssue.get("startLine"));
        assertThat(jsonIssue.get("endLine")).isEqualTo(jsonIssue.get("startLine"));
        assertThat(jsonIssue.get("endOffset")).isNotNull();
        assertThat(jsonIssue.get("startOffset")).isNotNull();
    }
    List<Long> lineNumbers = new ArrayList<>(16);
    for (long i = 1L; i < 18; i++) {
        lineNumbers.add(i);
    }
    assertThat(issues).extracting("startLine").containsAll(lineNumbers);
    assertThat(issues).extracting("endLine").containsAll(lineNumbers);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 54 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssuesModeTest method runFirstAnalysisAndFlagIssueAsWontFix.

private File runFirstAnalysisAndFlagIssueAsWontFix() throws IOException {
    restoreProfile("one-issue-per-line.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    // First run (publish mode)
    SonarScanner runner = configureRunner("shared/xoo-sample");
    orchestrator.executeBuild(runner);
    // First issues mode
    File homeDir = temp.newFolder();
    runner = configureRunnerIssues("shared/xoo-sample", homeDir);
    BuildResult result = orchestrator.executeBuild(runner);
    // 17 issues
    assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(17);
    // Flag one issue as false positive
    JSONObject obj = ItUtils.getJSONReport(result);
    String key = ((JSONObject) ((JSONArray) obj.get("issues")).get(0)).get("key").toString();
    orchestrator.getServer().adminWsClient().issueClient().doTransition(key, "falsepositive");
    return homeDir;
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner)

Example 55 with SonarScanner

use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.

the class IssuesModeTest method no_issues_mode_cache_by_default.

// SONAR-4602
@Test
public void no_issues_mode_cache_by_default() throws Exception {
    File homeDir = runFirstAnalysisAndFlagIssueAsWontFix();
    // Second issues mode using same cache dir but cache disabled by default
    SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir);
    BuildResult result = orchestrator.executeBuild(runner);
    // False positive is not returned
    assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Aggregations

SonarScanner (com.sonar.orchestrator.build.SonarScanner)84 Test (org.junit.Test)65 BuildResult (com.sonar.orchestrator.build.BuildResult)38 File (java.io.File)21 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)8 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 Issue (org.sonar.wsclient.issue.Issue)4 Favorites (org.sonarqube.ws.Favorites)3 SearchRequest (org.sonarqube.ws.client.favorite.SearchRequest)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 BeforeClass (org.junit.BeforeClass)2 SonarClient (org.sonar.wsclient.SonarClient)2 IssueClient (org.sonar.wsclient.issue.IssueClient)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WebTestSuite.createSonarScanner (com.sonar.it.web.WebTestSuite.createSonarScanner)1 BuildFailureException (com.sonar.orchestrator.build.BuildFailureException)1 SonarScannerInstaller (com.sonar.orchestrator.build.SonarScannerInstaller)1 FileSystem (com.sonar.orchestrator.config.FileSystem)1