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()));
}
}
}
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"));
}
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"));
}
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();
}
Aggregations