Search in sources :

Example 1 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList.Module.Builder in project sonarlint-core by SonarSource.

the class ModuleListDownloader method fetchModulesListAfter6dot3.

private void fetchModulesListAfter6dot3(Path dest, ProgressWrapper progress) {
    ModuleList.Builder moduleListBuilder = ModuleList.newBuilder();
    Builder moduleBuilder = ModuleList.Module.newBuilder();
    String baseUrl = "api/components/search.protobuf?qualifiers=TRK,BRC";
    if (wsClient.getOrganizationKey() != null) {
        baseUrl += "&organization=" + StringUtils.urlEncode(wsClient.getOrganizationKey());
    }
    SonarLintWsClient.getPaginated(wsClient, baseUrl, WsComponents.SearchWsResponse::parseFrom, WsComponents.SearchWsResponse::getPaging, WsComponents.SearchWsResponse::getComponentsList, module -> {
        moduleBuilder.clear();
        moduleListBuilder.putModulesByKey(module.getKey(), moduleBuilder.setProjectKey(module.getProject()).setKey(module.getKey()).setName(module.getName()).setQu(module.getQualifier()).build());
    }, progress);
    ProtobufUtil.writeToFile(moduleListBuilder.build(), dest.resolve(StoragePaths.MODULE_LIST_PB));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList.Module.Builder) ModuleList(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList)

Example 2 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList.Module.Builder 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);
        }
    }
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList.Module.Builder) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) Reader(java.io.Reader) Gson(com.google.gson.Gson) ModuleList(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList) IOException(java.io.IOException)

Aggregations

ModuleList (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList)2 Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList.Module.Builder)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)1