Search in sources :

Example 36 with BuildResult

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

the class IssuesModeTest method no_issues_mode_cache_by_default.

// SONAR-4602
@Test
public void no_issues_mode_cache_by_default() throws Exception {
    File homeDir = runFirstAnalysisAndFlagIssueAsWontFix();
    // Second issues mode using same cache dir but cache disabled by default
    SonarScanner runner = configureRunnerIssues("shared/xoo-sample", homeDir);
    BuildResult result = orchestrator.executeBuild(runner);
    // False positive is not returned
    assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(16);
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) File(java.io.File) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 37 with BuildResult

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

the class IssuesModeTest method test_issues_mode_on_project_with_space_in_filename.

// SONAR-5715
@Test
public void test_issues_mode_on_project_with_space_in_filename() throws IOException {
    restoreProfile("with-many-rules.xml");
    orchestrator.getServer().provisionProject("sample", "xoo-sample-with-spaces");
    orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "with-many-rules");
    SonarScanner runner = configureRunner("analysis/xoo-sample-with-spaces/v2");
    orchestrator.executeBuild(runner);
    assertThat(getComponent(orchestrator, "sample:my sources/main/xoo/sample/My Sample.xoo")).isNotNull();
    runner = configureRunnerIssues("analysis/xoo-sample-with-spaces/v2", null);
    BuildResult result = orchestrator.executeBuild(runner);
    // Analysis is not persisted in database
    assertThat(getComponent(orchestrator, "com.sonarsource.it.samples:simple-sample")).isNull();
    assertThat(result.getLogs()).contains("Issues");
    assertThat(result.getLogs()).contains("ANALYSIS SUCCESSFUL");
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 38 with BuildResult

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

the class IssuesModeTest method invalid_incremental_mode.

@Test
public void invalid_incremental_mode() 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 = configureRunner("shared/xoo-sample");
    runner.setProperty("sonar.analysis.mode", "incremental");
    thrown.expect(BuildFailureException.class);
    BuildResult res = orchestrator.executeBuild(runner);
    assertThat(res.getLogs()).contains("Invalid analysis mode: incremental. This mode was removed in SonarQube 5.2");
}
Also used : BuildResult(com.sonar.orchestrator.build.BuildResult) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 39 with BuildResult

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

the class IssuesModeTest method project_key_with_slash.

@Test
public void project_key_with_slash() throws IOException {
    restoreProfile("one-issue-per-line.xml");
    setDefaultQualityProfile("xoo", "one-issue-per-line");
    SonarScanner runner = configureRunner("shared/xoo-sample");
    runner.setProjectKey("sample/project");
    runner.setProperty("sonar.analysis.mode", "issues");
    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)

Example 40 with BuildResult

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

the class IssuesModeTest method load_user_name_in_json_report.

// SONAR-6522
@Test
public void load_user_name_in_json_report() throws Exception {
    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);
    SonarClient client = orchestrator.getServer().adminWsClient();
    Issues issues = client.issueClient().find(IssueQuery.create());
    Issue issue = issues.list().get(0);
    UserParameters creationParameters = UserParameters.create().login("julien").name("Julien H").password("password").passwordConfirmation("password");
    client.userClient().create(creationParameters);
    // Assign issue
    client.issueClient().assign(issue.key(), "julien");
    // Issues
    runner = configureRunnerIssues("shared/xoo-sample", null, "sonar.login", "julien", "sonar.password", "password");
    BuildResult result = orchestrator.executeBuild(runner);
    JSONObject obj = ItUtils.getJSONReport(result);
    Map<String, String> userNameByLogin = Maps.newHashMap();
    final JSONArray users = (JSONArray) obj.get("users");
    if (users != null) {
        for (Object user : users) {
            String login = ObjectUtils.toString(((JSONObject) user).get("login"));
            String name = ObjectUtils.toString(((JSONObject) user).get("name"));
            userNameByLogin.put(login, name);
        }
    }
    assertThat(userNameByLogin.get("julien")).isEqualTo("Julien H");
    for (Object issueJson : (JSONArray) obj.get("issues")) {
        JSONObject jsonObject = (JSONObject) issueJson;
        if (issue.key().equals(jsonObject.get("key"))) {
            assertThat(jsonObject.get("assignee")).isEqualTo("julien");
            return;
        }
    }
    fail("Issue not found");
}
Also used : UserParameters(org.sonar.wsclient.user.UserParameters) BuildResult(com.sonar.orchestrator.build.BuildResult) Issue(org.sonar.wsclient.issue.Issue) JSONObject(org.json.simple.JSONObject) Issues(org.sonar.wsclient.issue.Issues) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject) SonarClient(org.sonar.wsclient.SonarClient) 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