Search in sources :

Example 11 with BuildResult

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

the class ScmTest method scm_optimization.

@Test
public void scm_optimization() throws Exception {
    SonarScanner build = SonarScanner.create(projectDir("scm/xoo-sample-with-scm")).setProperty("sonar.scm.provider", "xoo").setProperty("sonar.scm.disabled", "false");
    // First run
    BuildResult buildResult = orchestrator.executeBuild(build);
    assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).containsExactly(MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto")));
    assertThat(buildResult.getLogs()).containsSequence("1 files to be analyzed", "1/1 files analyzed");
    // Second run with same file should not trigger blame but SCM data are copied from previous analysis
    buildResult = orchestrator.executeBuild(build);
    assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).containsExactly(MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto")));
    assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
    assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
    // Now if SCM is explicitely disabled it should clear SCM data on server side
    buildResult = orchestrator.executeBuild(build.setProperty("sonar.scm.disabled", "true"));
    assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).isEmpty();
    assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
    assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 12 with BuildResult

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

the class QualityGateTest method test_status_error.

@Test
public void test_status_error() throws IOException {
    QualityGate simple = qgClient().create("SimpleWithLowThreshold");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("10"));
    try {
        SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
        assertThat(getGateStatusMeasure().getValue()).isEqualTo("ERROR");
    } finally {
        qgClient().unsetDefault();
        qgClient().destroy(simple.id());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 13 with BuildResult

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

the class QualityGateTest method ad_hoc_build_break_strategy.

@Test
public void ad_hoc_build_break_strategy() throws IOException {
    QualityGate simple = qgClient().create("SimpleWithLowThresholdForBuildBreakStrategy");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("7"));
    try {
        File projectDir = projectDir("qualitygate/xoo-sample");
        SonarScanner build = SonarScanner.create(projectDir);
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
        String taskId = getTaskIdInLocalReport(projectDir);
        String analysisId = getAnalysisId(taskId);
        ProjectStatusWsResponse projectStatusWsResponse = wsClient.qualityGates().projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId));
        ProjectStatusWsResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus();
        assertThat(projectStatus.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR);
        assertThat(projectStatus.getConditionsCount()).isEqualTo(1);
        ProjectStatusWsResponse.Condition condition = projectStatus.getConditionsList().get(0);
        assertThat(condition.getMetricKey()).isEqualTo("ncloc");
        assertThat(condition.getErrorThreshold()).isEqualTo("7");
    } finally {
        qgClient().unsetDefault();
        qgClient().destroy(simple.id());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) ProjectStatusWsResponse(org.sonarqube.ws.WsQualityGates.ProjectStatusWsResponse) ProjectStatusWsRequest(org.sonarqube.ws.client.qualitygate.ProjectStatusWsRequest) File(java.io.File) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 14 with BuildResult

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

the class QualityGateTest method test_status_ok.

@Test
public void test_status_ok() throws IOException {
    QualityGate simple = qgClient().create("SimpleWithHighThreshold");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").warningThreshold("40"));
    try {
        SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_OK);
        assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
    } finally {
        qgClient().unsetDefault();
        qgClient().destroy(simple.id());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 15 with BuildResult

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

the class IssuesModeTest method issues_analysis_on_new_project.

@Test
public void issues_analysis_on_new_project() throws IOException {
    restoreProfile("one-issue-per-line.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
    SonarScanner runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.verbose", "true");
    BuildResult result = orchestrator.executeBuild(runner);
    assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

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