use of org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository.Configuration 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;
}
use of org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository.Configuration in project sonarlint-core by SonarSource.
the class StandaloneSonarLintEngineImpl method identifyActiveRules.
private Collection<ActiveRule> identifyActiveRules(StandaloneAnalysisConfiguration configuration) {
Set<String> excludedRules = configuration.excludedRules().stream().map(RuleKey::toString).collect(toSet());
Set<String> includedRules = configuration.includedRules().stream().map(RuleKey::toString).filter(r -> !excludedRules.contains(r)).collect(toSet());
Collection<SonarLintRuleDefinition> filteredActiveRules = new ArrayList<>();
filteredActiveRules.addAll(allRulesDefinitionsByKey.values().stream().filter(SonarLintRuleDefinition::isActiveByDefault).filter(isExcludedByConfiguration(excludedRules)).collect(Collectors.toList()));
filteredActiveRules.addAll(allRulesDefinitionsByKey.values().stream().filter(r -> !r.isActiveByDefault()).filter(isIncludedByConfiguration(includedRules)).collect(Collectors.toList()));
return filteredActiveRules.stream().map(rd -> {
var activeRule = new ActiveRule(rd.getKey(), rd.getLanguage().getLanguageKey());
Map<String, String> effectiveParams = new HashMap<>(rd.getDefaultParams());
Optional.ofNullable(configuration.ruleParameters().get(RuleKey.parse(rd.getKey()))).ifPresent(effectiveParams::putAll);
activeRule.setParams(effectiveParams);
return activeRule;
}).collect(Collectors.toList());
}
Aggregations