Search in sources :

Example 46 with BuildResult

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

the class QualityGateTest method test_status_warning.

@Test
public void test_status_warning() throws IOException {
    QualityGate simple = qgClient().create("SimpleWithLowThreshold");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").warningThreshold("10"));
    try {
        SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_WARN);
        assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
    } 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 47 with BuildResult

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

the class QualityGateTest method status_ok_if_empty_gate.

@Test
public void status_ok_if_empty_gate() throws IOException {
    QualityGate empty = qgClient().create("Empty");
    qgClient().setDefault(empty.id());
    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(empty.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 48 with BuildResult

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

the class QualityGateTest method do_not_compute_status_if_no_gate.

@Test
public void do_not_compute_status_if_no_gate() throws IOException {
    SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
    BuildResult buildResult = orchestrator.executeBuild(build);
    verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_NO_QG);
    assertThat(getGateStatusMeasure()).isNull();
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 49 with BuildResult

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

the class QualityGateTest method use_server_settings_instead_of_default_gate.

@Test
public void use_server_settings_instead_of_default_gate() throws IOException {
    QualityGate alert = qgClient().create("AlertWithLowThreshold");
    qgClient().createCondition(NewCondition.create(alert.id()).metricKey("ncloc").operator("GT").warningThreshold("10"));
    QualityGate error = qgClient().create("ErrorWithLowThreshold");
    qgClient().createCondition(NewCondition.create(error.id()).metricKey("ncloc").operator("GT").errorThreshold("10"));
    qgClient().setDefault(alert.id());
    associateQualityGateToProject(error.id(), PROJECT_KEY);
    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(alert.id());
        qgClient().destroy(error.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 50 with BuildResult

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

the class BootstrappingTest method analyzeProjectWith100FlatModules.

@Test
public void analyzeProjectWith100FlatModules() throws IOException {
    SonarScanner scanner = SonarScanner.create().setProperties("sonar.projectKey", "many-flat-modules", "sonar.projectName", "Many Flat Modules", "sonar.projectVersion", "1.0", "sonar.sources", "", "sonar.showProfiling", "true");
    scanner.setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx512m -server").setProjectDir(manyFlatModulesBaseDir);
    BuildResult result = orchestrator.executeBuild(scanner);
    // First analysis
    perfRule.assertDurationAround(MavenLogs.extractTotalTime(result.getLogs()), 22800L);
    result = orchestrator.executeBuild(scanner);
    // Second analysis is longer since we load project referential
    perfRule.assertDurationAround(MavenLogs.extractTotalTime(result.getLogs()), 27200L);
}
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