use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockReader.
public static void mockReader(ScannerWsClient mock, String path, Reader reader) {
WsResponse response = mock(WsResponse.class);
when(response.contentReader()).thenReturn(reader);
when(mock.call(argThat(new RequestMatcher(path)))).thenReturn(response);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class UpgradeTest method checkUrlIsReturningNotFound.
private void checkUrlIsReturningNotFound(String url) {
WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest(url));
assertThat(response.code()).isEqualTo(HttpURLConnection.HTTP_NOT_FOUND);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class QualityGateCheck method getQualityGateStatus.
private Status getQualityGateStatus(String analysisId) {
GetRequest getQualityGateReq = new GetRequest("api/qualitygates/project_status").setMediaType(MediaTypes.PROTOBUF).setParam("analysisId", analysisId);
try {
WsResponse getTaskResultResponse = wsClient.call(getQualityGateReq).failIfNotSuccessful();
Qualitygates.ProjectStatusResponse.ProjectStatus status = parseQualityGateResponse(getTaskResultResponse);
return status.getStatus();
} catch (HttpException e) {
throw MessageException.of(String.format("Failed to get Quality Gate status - %s", DefaultScannerWsClient.createErrorMessage(e)));
}
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class QualityGateCheck method waitForCeTaskToFinish.
private Ce.Task waitForCeTaskToFinish(String taskId) {
GetRequest getTaskResultReq = new GetRequest("api/ce/task").setMediaType(MediaTypes.PROTOBUF).setParam("id", taskId);
long currentTime = 0;
while (qualityGateTimeoutInMs > currentTime) {
try {
WsResponse getTaskResultResponse = wsClient.call(getTaskResultReq).failIfNotSuccessful();
Ce.Task task = parseCeTaskResponse(getTaskResultResponse);
if (TASK_TERMINAL_STATUSES.contains(task.getStatus())) {
return task;
}
Thread.sleep(POLLING_INTERVAL_IN_MS);
currentTime += POLLING_INTERVAL_IN_MS;
} catch (HttpException e) {
throw MessageException.of(String.format("Failed to get CE Task status - %s", DefaultScannerWsClient.createErrorMessage(e)));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Quality Gate check has been interrupted", e);
}
}
throw MessageException.of("Quality Gate check timeout exceeded - View details on " + ceTaskReportDataHolder.getDashboardUrl());
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ReportPublisher method upload.
/**
* Uploads the report file to server and returns the generated task id
*/
String upload(File report) {
LOG.debug("Upload report");
long startTime = System.currentTimeMillis();
PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
PostRequest post = new PostRequest("api/ce/submit").setMediaType(MediaTypes.PROTOBUF).setParam("projectKey", moduleHierarchy.root().key()).setParam("projectName", moduleHierarchy.root().getOriginalName()).setPart("report", filePart);
String branchName = branchConfiguration.branchName();
if (branchName != null) {
if (branchConfiguration.branchType() != PULL_REQUEST) {
post.setParam(CHARACTERISTIC, "branch=" + branchName);
post.setParam(CHARACTERISTIC, "branchType=" + branchConfiguration.branchType().name());
} else {
post.setParam(CHARACTERISTIC, "pullRequest=" + branchConfiguration.pullRequestKey());
}
}
WsResponse response;
try {
post.setWriteTimeOutInMs(DEFAULT_WRITE_TIMEOUT);
response = wsClient.call(post);
} catch (Exception e) {
throw new IllegalStateException("Failed to upload report: " + e.getMessage(), e);
}
try {
response.failIfNotSuccessful();
} catch (HttpException e) {
throw MessageException.of(String.format("Server failed to process report. Please check server logs: %s", DefaultScannerWsClient.createErrorMessage(e)));
}
try (InputStream protobuf = response.contentStream()) {
return Ce.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
long stopTime = System.currentTimeMillis();
LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
}
}
Aggregations