Search in sources :

Example 1 with QProfiles

use of org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles in project sonarlint-core by SonarSource.

the class QualityProfilesUpdateChecker method checkForUpdates.

public void checkForUpdates(DefaultStorageUpdateCheckResult result) {
    QProfiles serverQualityProfiles = qualityProfilesDownloader.fetchQualityProfiles();
    QProfiles storageQProfiles = storageReader.readQProfiles();
    Map<String, QProfile> serverPluginHashes = serverQualityProfiles.getQprofilesByKeyMap();
    Map<String, QProfile> storagePluginHashes = storageQProfiles.getQprofilesByKeyMap();
    MapDifference<String, QProfile> pluginDiff = Maps.difference(storagePluginHashes, serverPluginHashes);
    if (!pluginDiff.areEqual()) {
        for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnLeft().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' removed", entry.getValue().getName(), entry.getValue().getLanguageName()));
        }
        for (Map.Entry<String, QProfile> entry : pluginDiff.entriesOnlyOnRight().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' added", entry.getValue().getName(), entry.getValue().getLanguageName()));
        }
        for (Map.Entry<String, ValueDifference<QProfile>> entry : pluginDiff.entriesDiffering().entrySet()) {
            result.appendToChangelog(String.format("Quality profile '%s' for language '%s' updated", entry.getValue().rightValue().getName(), entry.getValue().rightValue().getLanguageName()));
        }
    }
}
Also used : ValueDifference(com.google.common.collect.MapDifference.ValueDifference) Map(java.util.Map) QProfile(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)

Example 2 with QProfiles

use of org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles in project sonarlint-core by SonarSource.

the class QualityProfilesDownloaderTest method test.

@Test
public void test() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse("/api/qualityprofiles/search.protobuf", "/update/qualityprofiles.pb");
    qProfilesDownloader = new QualityProfilesDownloader(wsClient);
    qProfilesDownloader.fetchQualityProfilesTo(temp.getRoot().toPath());
    QProfiles qProfiles = ProtobufUtil.readFile(temp.getRoot().toPath().resolve(StoragePaths.QUALITY_PROFILES_PB), QProfiles.parser());
    assertThat(qProfiles.getQprofilesByKeyMap()).containsOnlyKeys("cs-sonar-way-58886", "java-sonar-way-74592", "java-empty-74333", "js-sonar-security-way-70539", "js-sonar-way-60746");
    assertThat(qProfiles.getDefaultQProfilesByLanguageMap()).containsOnly(entry("cs", "cs-sonar-way-58886"), entry("java", "java-sonar-way-74592"), entry("js", "js-sonar-way-60746"));
}
Also used : SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Test(org.junit.Test)

Example 3 with QProfiles

use of org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles in project sonarlint-core by SonarSource.

the class QualityProfilesDownloaderTest method testWithOrg.

@Test
public void testWithOrg() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse("/api/qualityprofiles/search.protobuf?organization=myOrg", "/update/qualityprofiles.pb");
    when(wsClient.getOrganizationKey()).thenReturn("myOrg");
    qProfilesDownloader = new QualityProfilesDownloader(wsClient);
    qProfilesDownloader.fetchQualityProfilesTo(temp.getRoot().toPath());
    QProfiles qProfiles = ProtobufUtil.readFile(temp.getRoot().toPath().resolve(StoragePaths.QUALITY_PROFILES_PB), QProfiles.parser());
    assertThat(qProfiles.getQprofilesByKeyMap()).containsOnlyKeys("cs-sonar-way-58886", "java-sonar-way-74592", "java-empty-74333", "js-sonar-security-way-70539", "js-sonar-way-60746");
    assertThat(qProfiles.getDefaultQProfilesByLanguageMap()).containsOnly(entry("cs", "cs-sonar-way-58886"), entry("java", "java-sonar-way-74592"), entry("js", "js-sonar-way-60746"));
}
Also used : SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Test(org.junit.Test)

Example 4 with QProfiles

use of org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles in project sonarlint-core by SonarSource.

the class QualityProfilesDownloader method fetchQualityProfiles.

public QProfiles fetchQualityProfiles() {
    QProfiles.Builder qProfileBuilder = QProfiles.newBuilder();
    String searchUrl = DEFAULT_QP_SEARCH_URL;
    if (wsClient.getOrganizationKey() != null) {
        searchUrl += "?organization=" + StringUtils.urlEncode(wsClient.getOrganizationKey());
    }
    try (InputStream contentStream = wsClient.get(searchUrl).contentStream()) {
        SearchWsResponse qpResponse = QualityProfiles.SearchWsResponse.parseFrom(contentStream);
        for (QualityProfile qp : qpResponse.getProfilesList()) {
            QProfile.Builder qpBuilder = QProfile.newBuilder();
            qpBuilder.setKey(qp.getKey());
            qpBuilder.setName(qp.getName());
            qpBuilder.setLanguage(qp.getLanguage());
            qpBuilder.setLanguageName(qp.getLanguageName());
            qpBuilder.setActiveRuleCount(qp.getActiveRuleCount());
            qpBuilder.setRulesUpdatedAt(qp.getRulesUpdatedAt());
            qpBuilder.setUserUpdatedAt(qp.getUserUpdatedAt());
            qProfileBuilder.putQprofilesByKey(qp.getKey(), qpBuilder.build());
            if (qp.getIsDefault()) {
                qProfileBuilder.putDefaultQProfilesByLanguage(qp.getLanguage(), qp.getKey());
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Failed to load default quality profiles", e);
    }
    return qProfileBuilder.build();
}
Also used : InputStream(java.io.InputStream) QualityProfile(org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile) SearchWsResponse(org.sonarqube.ws.QualityProfiles.SearchWsResponse) IOException(java.io.IOException) QProfile(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)

Aggregations

QProfiles (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)4 Test (org.junit.Test)2 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)2 QProfile (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile)2 ValueDifference (com.google.common.collect.MapDifference.ValueDifference)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 SearchWsResponse (org.sonarqube.ws.QualityProfiles.SearchWsResponse)1 QualityProfile (org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile)1