use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class DefaultProjectSettingsLoaderTest method loadProjectSettings.
@Test
public void loadProjectSettings() 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);
when(properties.getProjectKey()).thenReturn("project_key");
Map<String, String> result = underTest.loadProjectSettings();
ArgumentCaptor<GetRequest> argumentCaptor = ArgumentCaptor.forClass(GetRequest.class);
verify(wsClient, times(1)).call(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getPath()).isEqualTo("api/settings/values.protobuf?component=project_key");
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 DefaultQualityProfileLoader method call.
private Map<String, QualityProfile> call(String url) throws IOException {
GetRequest getRequest = new GetRequest(url);
try (InputStream is = wsClient.call(getRequest).contentStream()) {
SearchWsResponse profiles = SearchWsResponse.parseFrom(is);
List<QualityProfile> profilesList = profiles.getProfilesList();
return profilesList.stream().collect(toMap(QualityProfile::getLanguage, identity(), throwingMerger(), LinkedHashMap::new));
}
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class DefaultRulesLoader method load.
@Override
public List<Rule> load() {
GetRequest getRequest = new GetRequest(RULES_SEARCH_URL);
ListResponse list = loadFromStream(wsClient.call(getRequest).contentStream());
return list.getRulesList();
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class DefaultActiveRulesLoader method load.
@Override
public List<LoadedActiveRule> load(String qualityProfileKey) {
List<LoadedActiveRule> ruleList = new LinkedList<>();
int page = 1;
int pageSize = 500;
long loaded = 0;
while (true) {
GetRequest getRequest = new GetRequest(getUrl(qualityProfileKey, page, pageSize));
SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream());
List<LoadedActiveRule> pageRules = readPage(response);
ruleList.addAll(pageRules);
loaded += response.getPs();
if (response.getTotal() <= loaded) {
break;
}
page++;
}
return ruleList;
}
use of org.sonarqube.ws.client.GetRequest in project sonarqube by SonarSource.
the class AbstractSettingsLoader method load.
Map<String, String> load(@Nullable String componentKey) {
String url = "api/settings/values.protobuf";
Profiler profiler = Profiler.create(LOG);
if (componentKey != null) {
url += "?component=" + ScannerUtils.encodeForUrl(componentKey);
profiler.startInfo(String.format("Load project settings for component key: '%s'", componentKey));
} else {
profiler.startInfo("Load global settings");
}
try (InputStream is = wsClient.call(new GetRequest(url)).contentStream()) {
Settings.ValuesWsResponse values = Settings.ValuesWsResponse.parseFrom(is);
profiler.stopInfo();
return toMap(values.getSettingsList());
} catch (HttpException e) {
if (e.code() == HttpURLConnection.HTTP_NOT_FOUND) {
return Collections.emptyMap();
}
throw e;
} catch (IOException e) {
throw new IllegalStateException("Unable to load settings", e);
}
}
Aggregations