use of org.sonarqube.ws.client.GetRequest 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.GetRequest 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.GetRequest in project sonarqube by SonarSource.
the class DefaultGlobalSettingsLoaderTest method loadGlobalSettings.
@Test
public void loadGlobalSettings() throws IOException {
WsResponse response = mock(WsResponse.class);
PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(out);
Settings.ValuesWsResponse.newBuilder().addSettings(Settings.Setting.newBuilder().setKey("abc").setValue("def").build()).addSettings(Settings.Setting.newBuilder().setKey("123").setValue("456").build()).build().writeTo(out);
out.close();
when(response.contentStream()).thenReturn(in);
when(wsClient.call(any())).thenReturn(response);
Map<String, String> result = underTest.loadGlobalSettings();
ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class);
verify(wsClient, times(1)).call(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf");
assertThat(result).isNotNull().hasSize(2).containsEntry("abc", "def").containsEntry("123", "456");
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class ScannerPluginInstaller method listInstalledPlugins.
/**
* Gets information about the plugins installed on server (filename, checksum)
*/
private InstalledPlugin[] listInstalledPlugins() {
Profiler profiler = Profiler.create(LOG).startInfo("Load plugins index");
GetRequest getRequest = new GetRequest(PLUGINS_WS_URL);
InstalledPlugins installedPlugins;
try (Reader reader = wsClient.call(getRequest).contentReader()) {
installedPlugins = new Gson().fromJson(reader, InstalledPlugins.class);
} catch (Exception e) {
throw new IllegalStateException("Fail to parse response of " + PLUGINS_WS_URL, e);
}
profiler.stopInfo();
return installedPlugins.plugins;
}
Aggregations