Search in sources :

Example 1 with NotFoundException

use of org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException in project sonarlint-core by SonarSource.

the class ModuleQualityProfilesDownloader method fetchModuleQualityProfiles.

public List<QualityProfile> fetchModuleQualityProfiles(String moduleKey, String serverVersion) {
    SearchWsResponse qpResponse;
    String param;
    if (Version.create(serverVersion).compareToIgnoreQualifier(Version.create("6.5")) >= 0) {
        param = "project";
    } else {
        param = "projectKey";
    }
    String baseUrl = "/api/qualityprofiles/search.protobuf?" + param + "=" + StringUtils.urlEncode(moduleKey);
    String organizationKey = wsClient.getOrganizationKey();
    if (organizationKey != null) {
        baseUrl += "&organization=" + StringUtils.urlEncode(organizationKey);
    }
    try (InputStream contentStream = wsClient.get(baseUrl).contentStream()) {
        qpResponse = QualityProfiles.SearchWsResponse.parseFrom(contentStream);
    } catch (NotFoundException e) {
        throw new ProjectNotFoundException(moduleKey, organizationKey);
    } catch (IOException e) {
        throw new IllegalStateException("Failed to load module quality profiles", e);
    }
    return qpResponse.getProfilesList();
}
Also used : ProjectNotFoundException(org.sonarsource.sonarlint.core.client.api.exceptions.ProjectNotFoundException) InputStream(java.io.InputStream) NotFoundException(org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException) ProjectNotFoundException(org.sonarsource.sonarlint.core.client.api.exceptions.ProjectNotFoundException) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SearchWsResponse (org.sonarqube.ws.QualityProfiles.SearchWsResponse)1 ProjectNotFoundException (org.sonarsource.sonarlint.core.client.api.exceptions.ProjectNotFoundException)1 NotFoundException (org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException)1