use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class QualityGateUiTest method scanSample.
private void scanSample(@Nullable String date, @Nullable String profile) {
SonarScanner scan = SonarScanner.create(projectDir("shared/xoo-sample")).setProperty("sonar.cpd.exclusions", "**/*");
if (date != null) {
scan.setProperty("sonar.projectDate", date);
}
if (profile != null) {
scan.setProfile(profile);
}
orchestrator.executeBuild(scan);
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class ScmTest method scm_optimization.
@Test
public void scm_optimization() throws Exception {
SonarScanner build = SonarScanner.create(projectDir("scm/xoo-sample-with-scm")).setProperty("sonar.scm.provider", "xoo").setProperty("sonar.scm.disabled", "false");
// First run
BuildResult buildResult = orchestrator.executeBuild(build);
assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).containsExactly(MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto")));
assertThat(buildResult.getLogs()).containsSequence("1 files to be analyzed", "1/1 files analyzed");
// Second run with same file should not trigger blame but SCM data are copied from previous analysis
buildResult = orchestrator.executeBuild(build);
assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).containsExactly(MapEntry.entry(1, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(3, new LineData("2", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(4, new LineData("1", "2013-01-04T00:00:00+0000", "jhenry")), MapEntry.entry(8, new LineData("3", "2014-01-04T00:00:00+0000", "toto")));
assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
// Now if SCM is explicitely disabled it should clear SCM data on server side
buildResult = orchestrator.executeBuild(build.setProperty("sonar.scm.disabled", "true"));
assertThat(getScmData("sample-scm:src/main/xoo/sample/Sample.xoo")).isEmpty();
assertThat(buildResult.getLogs()).doesNotContain("1 files to be analyzed");
assertThat(buildResult.getLogs()).doesNotContain("1/1 files analyzed");
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class QualityGateNotificationTest method status_on_metric_variation_and_send_notifications.
@Test
public void status_on_metric_variation_and_send_notifications() throws Exception {
setServerProperty(orchestrator, "email.smtp_host.secured", "localhost");
setServerProperty(orchestrator, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
// Create user, who will receive notifications for new violations
userRule.createUser("tester", "Tester", "tester@example.org", "tester");
// Send test email to the test user
newAdminWsClient(orchestrator).wsConnector().call(new PostRequest("api/emails/send").setParam("to", "test@example.org").setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
// Add notifications to the test user
WsClient wsClient = newUserWsClient(orchestrator, "tester", "tester");
wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewAlerts").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
// Create quality gate with conditions on variations
QualityGate simple = qgClient().create("SimpleWithDifferential");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").period(1).operator("EQ").warningThreshold("0"));
SonarScanner analysis = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
orchestrator.executeBuild(analysis);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
orchestrator.executeBuild(analysis);
assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
qgClient().unsetDefault();
qgClient().destroy(simple.id());
waitUntilAllNotificationsAreDelivered(smtpServer);
Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
MimeMessage message = emails.next().getMimeMessage();
assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
assertThat(emails.hasNext()).isTrue();
message = emails.next().getMimeMessage();
assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
assertThat((String) message.getContent()).contains("Quality gate status: Orange (was Green)");
assertThat((String) message.getContent()).contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis");
assertThat((String) message.getContent()).contains("/dashboard/index/sample");
assertThat(emails.hasNext()).isFalse();
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class QualityGateTest method test_status_error.
@Test
public void test_status_error() throws IOException {
QualityGate simple = qgClient().create("SimpleWithLowThreshold");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("10"));
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(simple.id());
}
}
use of com.sonar.orchestrator.build.SonarScanner in project sonarqube by SonarSource.
the class QualityGateTest method ad_hoc_build_break_strategy.
@Test
public void ad_hoc_build_break_strategy() throws IOException {
QualityGate simple = qgClient().create("SimpleWithLowThresholdForBuildBreakStrategy");
qgClient().setDefault(simple.id());
qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").operator("GT").errorThreshold("7"));
try {
File projectDir = projectDir("qualitygate/xoo-sample");
SonarScanner build = SonarScanner.create(projectDir);
BuildResult buildResult = orchestrator.executeBuild(build);
verifyQGStatusInPostTask(buildResult, TASK_STATUS_SUCCESS, QG_STATUS_ERROR);
String taskId = getTaskIdInLocalReport(projectDir);
String analysisId = getAnalysisId(taskId);
ProjectStatusWsResponse projectStatusWsResponse = wsClient.qualityGates().projectStatus(new ProjectStatusWsRequest().setAnalysisId(analysisId));
ProjectStatusWsResponse.ProjectStatus projectStatus = projectStatusWsResponse.getProjectStatus();
assertThat(projectStatus.getStatus()).isEqualTo(ProjectStatusWsResponse.Status.ERROR);
assertThat(projectStatus.getConditionsCount()).isEqualTo(1);
ProjectStatusWsResponse.Condition condition = projectStatus.getConditionsList().get(0);
assertThat(condition.getMetricKey()).isEqualTo("ncloc");
assertThat(condition.getErrorThreshold()).isEqualTo("7");
} finally {
qgClient().unsetDefault();
qgClient().destroy(simple.id());
}
}
Aggregations