use of org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule in project sonarlint-core by SonarSource.
the class SonarQubeActiveRulesProvider method createNewActiveRule.
private static void createNewActiveRule(ActiveRulesBuilder builder, ActiveRule activeRule, Sonarlint.Rules storageRules, String language, Rules rules) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepo(), activeRule.getKey());
Rule rule = rules.find(ruleKey);
Sonarlint.Rules.Rule storageRule;
try {
storageRule = storageRules.getRulesByKeyOrThrow(ruleKey.toString());
} catch (IllegalArgumentException e) {
throw new MessageException("Unknown active rule in the quality profile of the project. Please update the SonarQube server binding.");
}
NewActiveRule newActiveRule = builder.create(ruleKey).setLanguage(language).setName(rule.name()).setInternalKey(rule.internalKey()).setSeverity(activeRule.getSeverity());
if (!StringUtils.isEmpty(storageRule.getTemplateKey())) {
RuleKey templateRuleKey = RuleKey.parse(storageRule.getTemplateKey());
newActiveRule.setTemplateRuleKey(templateRuleKey.rule());
}
for (Map.Entry<String, String> param : activeRule.getParamsMap().entrySet()) {
newActiveRule.setParam(param.getKey(), param.getValue());
}
newActiveRule.activate();
}
use of org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules.ActiveRule 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;
}
Aggregations