use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.
the class NotificationCheckerTest method testIsSupported.
@Test
public void testIsSupported() {
String expectedUrl = "api/developers/search_events?projects=&from=";
SonarLintWsClient client = WsClientTestUtils.createMock();
WsResponse wsResponse = mock(WsResponse.class);
when(client.rawGet(startsWith(expectedUrl))).thenReturn(wsResponse);
when(wsResponse.isSuccessful()).thenReturn(true);
NotificationChecker checker = new NotificationChecker(client);
assertThat(checker.isSupported()).isTrue();
}
use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.
the class SonarLintWsClient method rawPost.
/**
* Execute POST and don't check response
*/
public WsResponse rawPost(String path) {
long startTime = System2.INSTANCE.now();
PostRequest request = new PostRequest(path);
WsResponse response = client.call(request);
long duration = System2.INSTANCE.now() - startTime;
if (LOG.isDebugEnabled()) {
LOG.debug("{} {} {} | time={}ms", request.getMethod(), response.code(), response.requestUrl(), duration);
}
return response;
}
use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.
the class IssueDownloaderImpl method apply.
/**
* Fetch all issues of the component with specified key.
* If the component doesn't exist or it exists but has no issues, an empty iterator is returned.
* See also sonarqube:/web_api/batch
*
* @param key project key, module key, or file key.
* @return Iterator of issues. It can be empty but never null.
*/
@Override
public List<ScannerInput.ServerIssue> apply(String key) {
try (WsResponse response = wsClient.rawGet(getIssuesUrl(key))) {
if (response.code() == 403 || response.code() == 404) {
return Collections.emptyList();
} else if (response.code() != 200) {
throw SonarLintWsClient.handleError(response);
}
InputStream input = response.contentStream();
Parser<ScannerInput.ServerIssue> parser = ScannerInput.ServerIssue.parser();
return ProtobufUtil.readMessages(input, parser);
}
}
use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.
the class ModuleListDownloader method fetchModulesListBefore6dot3.
private void fetchModulesListBefore6dot3(Path dest) {
try (WsResponse response = wsClient.get("api/projects/index?format=json&subprojects=true")) {
try (Reader contentReader = response.contentReader()) {
DefaultModule[] results = new Gson().fromJson(contentReader, DefaultModule[].class);
ModuleList.Builder moduleListBuilder = ModuleList.newBuilder();
Builder moduleBuilder = ModuleList.Module.newBuilder();
for (DefaultModule module : results) {
moduleBuilder.clear();
moduleListBuilder.putModulesByKey(module.k, moduleBuilder.setKey(module.k).setName(module.nm).setQu(module.qu).build());
}
ProtobufUtil.writeToFile(moduleListBuilder.build(), dest.resolve(StoragePaths.MODULE_LIST_PB));
} catch (IOException e) {
throw new IllegalStateException("Failed to load module list", e);
}
}
}
use of org.sonarsource.sonarlint.core.util.ws.WsResponse in project sonarlint-core by SonarSource.
the class PluginListDownloader method downloadPluginListBefore66.
public List<SonarAnalyzer> downloadPluginListBefore66(Version serverVersion) {
List<SonarAnalyzer> analyzers = new LinkedList<>();
boolean compatibleFlagPresent = serverVersion.compareToIgnoreQualifier(Version.create("6.0")) >= 0;
String responseStr;
try (WsResponse response = wsClient.get(WS_PATH_LTS)) {
responseStr = response.content();
}
Scanner scanner = new Scanner(responseStr);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] fields = StringUtils.split(line, ",");
String[] nameAndHash = StringUtils.split(fields[fields.length - 1], "|");
String key = fields[0];
String filename = nameAndHash[0];
String hash = nameAndHash[1];
String version = VersionUtils.getJarVersion(filename);
String minVersion = pluginVersionChecker.getMinimumVersion(key);
boolean sonarlintCompatible = PluginCacheLoader.isWhitelisted(key) || !compatibleFlagPresent || "true".equals(fields[1]);
DefaultSonarAnalyzer analyzer = new DefaultSonarAnalyzer(key, filename, hash, version, sonarlintCompatible, minVersion);
analyzers.add(analyzer);
}
scanner.close();
return analyzers;
}
Aggregations