Search in sources :

Example 66 with SonarScanner

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

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

the class SincePreviousVersionHistoryTest method analyzeProject.

private static void analyzeProject(String version, @Nullable String exclusions, @Nullable String date) {
    SonarScanner build = SonarScanner.create(projectDir("shared/xoo-multi-modules-sample")).setProperties("sonar.projectVersion", version);
    if (exclusions != null) {
        build.setProperties("sonar.exclusions", exclusions);
    }
    if (date != null) {
        build.setProperty("sonar.projectDate", date);
    }
    orchestrator.executeBuild(build);
}
Also used : SonarScanner(com.sonar.orchestrator.build.SonarScanner)

Example 68 with SonarScanner

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

the class SinceXDaysHistoryTest method analyzeProject.

private static void analyzeProject(@Nullable String date, @Nullable String exclusions) {
    SonarScanner runner = SonarScanner.create(projectDir("measureHistory/xoo-multi-files-sample"));
    if (date != null) {
        runner.setProperty("sonar.projectDate", date);
    }
    if (exclusions != null) {
        runner.setProperties("sonar.exclusions", exclusions);
    }
    orchestrator.executeBuild(runner);
}
Also used : SonarScanner(com.sonar.orchestrator.build.SonarScanner)

Example 69 with SonarScanner

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

the class SettingsTestRestartingOrchestrator method property_relocation.

@Test
public void property_relocation() throws UnsupportedEncodingException {
    orchestrator = Orchestrator.builderEnv().addPlugin(pluginArtifact("property-relocation-plugin")).addPlugin(xooPlugin()).setServerProperty("sonar.deprecatedKey", "true").build();
    orchestrator.start();
    SonarScanner withDeprecatedKey = SonarScanner.create(projectDir("shared/xoo-sample")).setProperty("sonar.deprecatedKey", "true");
    SonarScanner withNewKey = SonarScanner.create(projectDir("shared/xoo-sample")).setProperty("sonar.newKey", "true");
    // should not fail
    orchestrator.executeBuilds(withDeprecatedKey, withNewKey);
    Navigation.get(orchestrator).openHomepage().logIn().asAdmin().openSettings(null).assertMenuContains("General").assertSettingDisplayed("sonar.newKey").assertSettingNotDisplayed("sonar.deprecatedKey");
}
Also used : SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 70 with SonarScanner

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

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