Search in sources :

Example 41 with BuildResult

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

the class SettingsEncryptionTest method testEncryptedProperty.

/**
   * SONAR-2084
   * SONAR-4061
   */
@Test
public void testEncryptedProperty() throws Exception {
    SonarScanner build = SonarScanner.create(ItUtils.projectDir("shared/xoo-sample")).setProperty("sonar.secretKeyPath", pathToValidSecretKey()).setProperty("sonar.login", "admin").setProperty("sonar.password", // wrong password
    "{aes}wrongencryption==").setProperty("encryptedProperty", "{aes}9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=");
    BuildResult result = orchestrator.executeBuildQuietly(build);
    assertThat(result.getStatus()).isNotEqualTo(0);
    assertThat(result.getLogs()).contains("Fail to decrypt the property sonar.password. Please check your secret key");
    build = SonarScanner.create(ItUtils.projectDir("shared/xoo-sample")).setProperty("sonar.secretKeyPath", pathToValidSecretKey()).setProperty("sonar.login", "{aes}evRHXHsEyPr5RjEuxUJcHA==").setProperty("sonar.password", "{aes}evRHXHsEyPr5RjEuxUJcHA==").setProperty("encryptedProperty", "{aes}9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY=");
    // no error
    orchestrator.executeBuild(build);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 42 with BuildResult

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

the class TempFolderTest method should_create_in_temp_folder.

// SONAR-4748
@Test
public void should_create_in_temp_folder() throws IOException {
    File projectDir = ItUtils.projectDir("shared/xoo-sample");
    BuildResult result = scan();
    assertThat(result.getLogs()).doesNotContain("Creating temp directory:");
    assertThat(result.getLogs()).doesNotContain("Creating temp file:");
    result = scan("sonar.createTempFiles", "true");
    assertThat(result.getLogs()).contains("Creating temp directory: " + projectDir.getCanonicalPath() + File.separator + ".sonar" + File.separator + ".sonartmp" + File.separator + "sonar-it");
    assertThat(result.getLogs()).contains("Creating temp file: " + projectDir.getCanonicalPath() + File.separator + ".sonar" + File.separator + ".sonartmp" + File.separator + "sonar-it");
    // Verify temp folder is deleted after analysis
    assertThat(new File(projectDir, ".sonar/.sonartmp/sonar-it")).doesNotExist();
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) File(java.io.File) Test(org.junit.Test)

Example 43 with BuildResult

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

the class MultiLanguageTest method test_sonar_runner_inspection.

/**
   * SONAR-926
   * SONAR-5069
   */
@Test
public void test_sonar_runner_inspection() {
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line.xml"));
    orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/analysis/MultiLanguageTest/one-issue-per-line-xoo2.xml"));
    orchestrator.getServer().provisionProject("multi-language-sample", "multi-language-sample");
    orchestrator.getServer().associateProjectToQualityProfile("multi-language-sample", "xoo", "one-issue-per-line");
    orchestrator.getServer().associateProjectToQualityProfile("multi-language-sample", "xoo2", "one-issue-per-line-xoo2");
    SonarScanner build = SonarScanner.create().setProjectDir(ItUtils.projectDir("analysis/xoo-multi-languages"));
    BuildResult result = orchestrator.executeBuild(build);
    // 4 files: 1 .xoo, 1.xoo2, 2 .measures
    assertThat(result.getLogs()).contains("4 files indexed");
    assertThat(result.getLogs()).contains("Quality profile for xoo: one-issue-per-line");
    assertThat(result.getLogs()).contains("Quality profile for xoo2: one-issue-per-line-xoo2");
    // modules
    Map<String, Double> measures = getMeasuresAsDoubleByMetricKey(orchestrator, "multi-language-sample", "files", "violations");
    assertThat(measures.get("files")).isEqualTo(2);
    assertThat(measures.get("violations")).isEqualTo(26);
    assertThat(getMeasureAsDouble(orchestrator, "multi-language-sample:src/sample/Sample.xoo", "violations")).isEqualTo(13);
    assertThat(getMeasureAsDouble(orchestrator, "multi-language-sample:src/sample/Sample.xoo2", "violations")).isEqualTo(13);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) ItUtils.getMeasureAsDouble(util.ItUtils.getMeasureAsDouble) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 44 with BuildResult

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

the class PermissionTest method scanner_can_authenticate_with_authentication_token.

@Test
public void scanner_can_authenticate_with_authentication_token() {
    createUserWithProvisioningAndScanPermissions();
    String tokenName = "For test";
    WsUserTokens.GenerateWsResponse generateWsResponse = userTokensWsClient.generate(new GenerateWsRequest().setLogin(A_LOGIN).setName(tokenName));
    SonarScanner sampleProject = SonarScanner.create(projectDir("shared/xoo-sample"));
    sampleProject.setProperties("sonar.login", generateWsResponse.getToken(), "sonar.password", "");
    BuildResult buildResult = orchestrator.executeBuild(sampleProject);
    assertThat(buildResult.isSuccess()).isTrue();
    userTokensWsClient.revoke(new RevokeWsRequest().setLogin(A_LOGIN).setName(tokenName));
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) RevokeWsRequest(org.sonarqube.ws.client.usertoken.RevokeWsRequest) GenerateWsRequest(org.sonarqube.ws.client.usertoken.GenerateWsRequest) WsUserTokens(org.sonarqube.ws.WsUserTokens) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 45 with BuildResult

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

the class QualityGateTest method conditions_on_multiple_metric_types.

@Test
public void conditions_on_multiple_metric_types() throws IOException {
    QualityGate allTypes = qgClient().create("AllMetricTypes");
    qgClient().createCondition(NewCondition.create(allTypes.id()).metricKey("ncloc").operator("GT").warningThreshold("10"));
    qgClient().createCondition(NewCondition.create(allTypes.id()).metricKey("duplicated_lines_density").operator("GT").warningThreshold("20"));
    qgClient().setDefault(allTypes.id());
    try {
        SonarScanner build = SonarScanner.create(projectDir("qualitygate/xoo-sample")).setProperty("sonar.cpd.xoo.minimumLines", "2").setProperty("sonar.cpd.xoo.minimumTokens", "5");
        BuildResult buildResult = orchestrator.executeBuild(build);
        verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_WARN);
        Measure alertStatus = getGateStatusMeasure();
        assertThat(alertStatus.getValue()).isEqualTo("WARN");
        String qualityGateDetailJson = ItUtils.getMeasure(orchestrator, PROJECT_KEY, "quality_gate_details").getValue();
        assertThat(QualityGateDetails.parse(qualityGateDetailJson).getConditions()).extracting(QualityGateDetails.Conditions::getMetric, QualityGateDetails.Conditions::getOp, QualityGateDetails.Conditions::getWarning).contains(tuple("ncloc", "GT", "10"), tuple("duplicated_lines_density", "GT", "20"));
    } finally {
        qgClient().unsetDefault();
        qgClient().destroy(allTypes.id());
    }
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) Measure(org.sonarqube.ws.WsMeasures.Measure) ItUtils.getMeasure(util.ItUtils.getMeasure) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) 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