use of org.sonarsource.sonarlint.core.serverapi.rules.ServerActiveRule in project sonarlint-core by SonarSource.
the class ConnectedSonarLintEngineImpl method buildActiveRulesContext.
private ActiveRulesContext buildActiveRulesContext(ConnectedAnalysisConfiguration configuration) {
var analysisRulesContext = new ActiveRulesContext();
// could be empty before the first sync
var projectKey = configuration.projectKey();
if (projectKey == null) {
// this should be forbidden by client side
LOG.debug("No project key provided, no rules will be used for analysis");
return analysisRulesContext;
}
var allRulesDefinitionsByKey = analysisContext.get().allRulesDefinitionsByKey;
projectStorage.getAnalyzerConfiguration(projectKey).getRuleSetByLanguageKey().entrySet().stream().filter(e -> Language.forKey(e.getKey()).filter(l -> globalConfig.getEnabledLanguages().contains(l)).isPresent()).forEach(e -> {
var languageKey = e.getKey();
var ruleSet = e.getValue();
LOG.debug(" * {}: '{}' ({} active rules)", languageKey, ruleSet.getProfileKey(), ruleSet.getRules().size());
for (ServerActiveRule activeRuleFromStorage : ruleSet.getRules()) {
var ruleDefinitionKey = StringUtils.isNotBlank(activeRuleFromStorage.getTemplateKey()) ? activeRuleFromStorage.getTemplateKey() : activeRuleFromStorage.getRuleKey();
var ruleDefinition = allRulesDefinitionsByKey.get(ruleDefinitionKey);
if (ruleDefinition == null) {
LOG.debug("Rule {} is enabled on the server, but not available in SonarLint", activeRuleFromStorage.getRuleKey());
continue;
}
analysisRulesContext.includeRule(ruleDefinition, activeRuleFromStorage);
}
});
allRulesDefinitionsByKey.values().stream().filter(ruleDefinition -> isRuleFromExtraPlugin(ruleDefinition.getLanguage(), globalConfig)).forEach(analysisRulesContext::includeRule);
return analysisRulesContext;
}
Aggregations