use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssueJsonReportTest method precise_issue_location.
@Test
public void precise_issue_location() throws IOException {
orchestrator.getServer().restoreProfile(getResource("multiline.xml"));
orchestrator.getServer().provisionProject("sample-multiline", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample-multiline", "xoo", "multiline");
File projectDir = ItUtils.projectDir("shared/xoo-precise-issues");
SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
BuildResult result = orchestrator.executeBuild(runner);
assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(2);
JSONObject obj = ItUtils.getJSONReport(result);
JSONArray issues = (JSONArray) obj.get("issues");
JSONObject issue1 = (JSONObject) issues.get(0);
JSONObject issue2 = (JSONObject) issues.get(1);
assertThat(issue1.get("startLine")).isIn(6L);
assertThat(issue1.get("line")).isIn(6L);
assertThat(issue1.get("endLine")).isIn(6L);
assertThat(issue1.get("startOffset")).isIn(27L);
assertThat(issue1.get("endOffset")).isIn(32L);
assertThat(issue2.get("startLine")).isIn(9L);
assertThat(issue2.get("line")).isIn(9L);
assertThat(issue2.get("endLine")).isIn(15L);
assertThat(issue2.get("startOffset")).isIn(20L);
assertThat(issue2.get("endOffset")).isIn(2L);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssueJsonReportTest method test_json_report_on_branch.
@Test
public void test_json_report_on_branch() throws Exception {
orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
orchestrator.getServer().provisionProject("sample:mybranch", "Sample");
orchestrator.getServer().associateProjectToQualityProfile("sample:mybranch", "xoo", "one-issue-per-line");
SonarScanner scan = SonarScanner.create(ItUtils.projectDir("analysis/tracking/v1")).setProperty("sonar.projectDate", "2013-05-01").setProperty("sonar.branch", "mybranch");
orchestrator.executeBuild(scan);
// issues mode scan -> 2 new issues and 13 existing issues
File projectDir = ItUtils.projectDir("analysis/tracking/v2");
SonarScanner issuesModeScan = SonarScanner.create(projectDir).setProperty("sonar.analysis.mode", "issues").setProperty("sonar.userHome", temp.newFolder().getAbsolutePath()).setProperty("sonar.report.export.path", "sonar-report.json").setProperty("sonar.issuesReport.console.enable", "true").setProperty("sonar.projectDate", "2013-05-02").setProperty("sonar.verbose", "true").setProperty("sonar.branch", "mybranch");
orchestrator.executeBuild(issuesModeScan);
File report = new File(projectDir, ".sonar/sonar-report.json");
assertThat(report).isFile().exists();
String json = sanitize(FileUtils.readFileToString(report));
String expectedJson = expected("report-on-single-module-branch.json");
JSONAssert.assertEquals(expectedJson, json, false);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssueJsonReportTest method issue_line.
@Test
public void issue_line() throws IOException {
orchestrator.getServer().restoreProfile(getResource("one-issue-per-line.xml"));
orchestrator.getServer().provisionProject("sample", "xoo-sample");
orchestrator.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line");
File projectDir = ItUtils.projectDir("shared/xoo-sample");
SonarScanner runner = SonarScanner.create(projectDir, "sonar.analysis.mode", "issues", "sonar.verbose", "true", "sonar.report.export.path", "sonar-report.json");
BuildResult result = orchestrator.executeBuild(runner);
assertThat(ItUtils.countIssuesInJsonReport(result, true)).isEqualTo(17);
JSONObject obj = ItUtils.getJSONReport(result);
JSONArray issues = (JSONArray) obj.get("issues");
for (Object issue : issues) {
JSONObject jsonIssue = (JSONObject) issue;
assertThat(jsonIssue.get("startLine")).isNotNull();
assertThat(jsonIssue.get("line")).isEqualTo(jsonIssue.get("startLine"));
assertThat(jsonIssue.get("endLine")).isEqualTo(jsonIssue.get("startLine"));
assertThat(jsonIssue.get("endOffset")).isNotNull();
assertThat(jsonIssue.get("startOffset")).isNotNull();
}
List<Long> lineNumbers = new ArrayList<>(16);
for (long i = 1L; i < 18; i++) {
lineNumbers.add(i);
}
assertThat(issues).extracting("startLine").containsAll(lineNumbers);
assertThat(issues).extracting("endLine").containsAll(lineNumbers);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class IssuesModeTest method runFirstAnalysisAndFlagIssueAsWontFix.
private File runFirstAnalysisAndFlagIssueAsWontFix() throws IOException {
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);
// First issues mode
File homeDir = temp.newFolder();
runner = configureRunnerIssues("shared/xoo-sample", homeDir);
BuildResult result = orchestrator.executeBuild(runner);
// 17 issues
assertThat(ItUtils.countIssuesInJsonReport(result, false)).isEqualTo(17);
// Flag one issue as false positive
JSONObject obj = ItUtils.getJSONReport(result);
String key = ((JSONObject) ((JSONArray) obj.get("issues")).get(0)).get("key").toString();
orchestrator.getServer().adminWsClient().issueClient().doTransition(key, "falsepositive");
return homeDir;
}
use of com.sonar.orchestrator.build.SonarScanner 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);
}
Aggregations