Search in sources :

Example 31 with BuildResult

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

the class ScannerTest method module_should_load_own_settings_from_database.

// SONAR-4680
@Test
public void module_should_load_own_settings_from_database() {
    String rootModuleKey = "com.sonarsource.it.samples:multi-modules-sample";
    orchestrator.getServer().provisionProject(rootModuleKey, "Sonar :: Integration Tests :: Multi-modules Sample");
    String propKey = "myFakeProperty";
    String moduleBKey = rootModuleKey + ":module_b";
    resetSettings(orchestrator, rootModuleKey, propKey);
    BuildResult result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
    assertThat(result.getLogs()).doesNotContain(rootModuleKey + ":" + propKey);
    assertThat(result.getLogs()).doesNotContain(moduleBKey + ":" + propKey);
    // Set property only on root project
    setServerProperty(orchestrator, rootModuleKey, propKey, "project");
    result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
    assertThat(result.getLogs()).contains(rootModuleKey + ":" + propKey + " = project");
    assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = project");
    // Override property on moduleB
    setServerProperty(orchestrator, moduleBKey, propKey, "moduleB");
    result = scan("shared/xoo-multi-modules-sample", "sonar.showSettings", propKey);
    assertThat(result.getLogs()).contains(rootModuleKey + ":" + propKey + " = project");
    assertThat(result.getLogs()).contains(moduleBKey + ":" + propKey + " = moduleB");
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Example 32 with BuildResult

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

the class ScannerTest method should_create_project_without_name_version.

@Test
public void should_create_project_without_name_version() {
    // some of the sub-modules have a name defined, others don't
    BuildResult buildResult = scan("shared/xoo-multi-module-sample-without-project-name-version");
    assertThat(buildResult.isSuccess()).isTrue();
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b", "module_b", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b1", "module_b1", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_b:module_b2", "Sub-module B2", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a", "Module A", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a1", "Sub-module A1", "not provided");
    assertNameAndVersion("com.sonarsource.it.samples:multi-modules-sample:module_a:module_a2", "Sub-module A2", "not provided");
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Example 33 with BuildResult

use of com.sonar.orchestrator.build.BuildResult 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 34 with BuildResult

use of com.sonar.orchestrator.build.BuildResult 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 35 with BuildResult

use of com.sonar.orchestrator.build.BuildResult 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)

Aggregations

BuildResult (com.sonar.orchestrator.build.BuildResult)53 Test (org.junit.Test)49 SonarScanner (com.sonar.orchestrator.build.SonarScanner)38 File (java.io.File)12 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)7 JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 Issue (org.sonar.wsclient.issue.Issue)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 BuildFailureException (com.sonar.orchestrator.build.BuildFailureException)1 SonarScannerInstaller (com.sonar.orchestrator.build.SonarScannerInstaller)1 FileSystem (com.sonar.orchestrator.config.FileSystem)1 AbapCheck (it.plugins.checks.AbapCheck)1 CCheck (it.plugins.checks.CCheck)1 Check (it.plugins.checks.Check)1 CobolCheck (it.plugins.checks.CobolCheck)1 CppCheck (it.plugins.checks.CppCheck)1 FlexCheck (it.plugins.checks.FlexCheck)1 GroovyCheck (it.plugins.checks.GroovyCheck)1