Search in sources :

Example 1 with QProfile

use of org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile 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 QProfile

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

the class SonarQubeActiveRulesProvider method provide.

public ActiveRules provide(Sonarlint.Rules storageRules, Sonarlint.QProfiles qProfiles, StorageReader storageReader, Rules rules, ConnectedAnalysisConfiguration analysisConfiguration, Languages languages) {
    if (activeRules == null) {
        Map<String, String> qProfilesByLanguage = loadQualityProfilesFromStorage(qProfiles, storageReader, analysisConfiguration);
        ActiveRulesBuilder builder = new ActiveRulesBuilder();
        for (Map.Entry<String, String> entry : qProfilesByLanguage.entrySet()) {
            String language = entry.getKey();
            if (languages.get(language) == null) {
                continue;
            }
            String qProfileKey = entry.getValue();
            QProfile qProfile = qProfiles.getQprofilesByKeyOrThrow(qProfileKey);
            if (qProfile.getActiveRuleCount() == 0) {
                LOG.debug("  * {}: {} (0 rules)", language, qProfileKey);
                continue;
            }
            Sonarlint.ActiveRules activeRulesFromStorage = storageReader.readActiveRules(qProfileKey);
            LOG.debug("  * {}: {} ({} rules)", language, qProfileKey, activeRulesFromStorage.getActiveRulesByKeyMap().size());
            for (ActiveRule activeRule : activeRulesFromStorage.getActiveRulesByKeyMap().values()) {
                createNewActiveRule(builder, activeRule, storageRules, language, rules);
            }
        }
        activeRules = builder.build();
    }
    return activeRules;
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRule(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule) Sonarlint(org.sonarsource.sonarlint.core.proto.Sonarlint) Map(java.util.Map) QProfile(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile)

Aggregations

Map (java.util.Map)2 QProfile (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles.QProfile)2 ValueDifference (com.google.common.collect.MapDifference.ValueDifference)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 Sonarlint (org.sonarsource.sonarlint.core.proto.Sonarlint)1 ActiveRule (org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule)1 QProfiles (org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles)1