Search in sources :

Example 1 with Configuration

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;
}
Also used : ClientLogOutput(org.sonarsource.sonarlint.core.commons.log.ClientLogOutput) FileMatcher(org.sonarsource.sonarlint.core.container.storage.FileMatcher) Language(org.sonarsource.sonarlint.core.commons.Language) GlobalUpdateStatusReader(org.sonarsource.sonarlint.core.container.storage.GlobalUpdateStatusReader) DefaultClientIssue(org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue) IssueStoreReader(org.sonarsource.sonarlint.core.container.storage.IssueStoreReader) SonarLintRuleDefinition(org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition) Version(org.sonarsource.sonarlint.core.commons.Version) StringUtils(org.apache.commons.lang3.StringUtils) ProjectStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.ProjectStorageStatus) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) Map(java.util.Map) ConnectedRuleDetails(org.sonarsource.sonarlint.core.client.api.connected.ConnectedRuleDetails) GlobalStores(org.sonarsource.sonarlint.core.container.storage.GlobalStores) Path(java.nio.file.Path) ActiveRule(org.sonarsource.sonarlint.core.analysis.api.ActiveRule) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) EndpointParams(org.sonarsource.sonarlint.core.serverapi.EndpointParams) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) StorageFileExclusions(org.sonarsource.sonarlint.core.container.storage.StorageFileExclusions) Predicate(java.util.function.Predicate) DefaultRuleDetails(org.sonarsource.sonarlint.core.container.storage.DefaultRuleDetails) PluginInstancesRepository(org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository) Collection(java.util.Collection) ServerActiveRule(org.sonarsource.sonarlint.core.serverapi.rules.ServerActiveRule) Set(java.util.Set) ServerProject(org.sonarsource.sonarlint.core.serverapi.component.ServerProject) ProjectListDownloader(org.sonarsource.sonarlint.core.container.connected.update.ProjectListDownloader) Collectors(java.util.stream.Collectors) List(java.util.List) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalysisEngineConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisEngineConfiguration) HttpClient(org.sonarsource.sonarlint.core.commons.http.HttpClient) Optional(java.util.Optional) FilenameUtils(org.apache.commons.io.FilenameUtils) IssueStoreFactory(org.sonarsource.sonarlint.core.container.connected.IssueStoreFactory) AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) GlobalStorageUpdateExecutor(org.sonarsource.sonarlint.core.container.connected.update.perform.GlobalStorageUpdateExecutor) Configuration(org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository.Configuration) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) AnalysisEngine(org.sonarsource.sonarlint.core.analysis.AnalysisEngine) ProjectStorageStatusReader(org.sonarsource.sonarlint.core.container.storage.ProjectStorageStatusReader) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) ProjectStoragePaths.encodeForFs(org.sonarsource.sonarlint.core.container.storage.ProjectStoragePaths.encodeForFs) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) LocalStorageSynchronizer(org.sonarsource.sonarlint.core.storage.LocalStorageSynchronizer) ProjectStorageUpdateExecutor(org.sonarsource.sonarlint.core.container.connected.update.perform.ProjectStorageUpdateExecutor) Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) Objects.requireNonNull(java.util.Objects.requireNonNull) ProjectStorage(org.sonarsource.sonarlint.core.storage.ProjectStorage) IssueStorePaths(org.sonarsource.sonarlint.core.container.connected.update.IssueStorePaths) ProjectStoragePaths(org.sonarsource.sonarlint.core.container.storage.ProjectStoragePaths) DownloadException(org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException) Nullable(javax.annotation.Nullable) ProjectBranches(org.sonarsource.sonarlint.core.client.api.connected.ProjectBranches) AnalysisConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration) ProjectBinding(org.sonarsource.sonarlint.core.client.api.connected.ProjectBinding) StorageReader(org.sonarsource.sonarlint.core.container.storage.StorageReader) PluginDetails(org.sonarsource.sonarlint.core.client.api.common.PluginDetails) ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) PluginsStorage(org.sonarsource.sonarlint.core.storage.PluginsStorage) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) PartialUpdaterFactory(org.sonarsource.sonarlint.core.container.storage.partialupdate.PartialUpdaterFactory) Paths(java.nio.file.Paths) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerActiveRule(org.sonarsource.sonarlint.core.serverapi.rules.ServerActiveRule)

Example 2 with Configuration

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());
}
Also used : ClientLogOutput(org.sonarsource.sonarlint.core.commons.log.ClientLogOutput) AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) DefaultClientIssue(org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue) Configuration(org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository.Configuration) HashMap(java.util.HashMap) StandaloneRuleDetails(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleDetails) SonarLintRuleDefinition(org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition) AnalysisEngine(org.sonarsource.sonarlint.core.analysis.AnalysisEngine) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) ArrayList(java.util.ArrayList) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Nullable(javax.annotation.Nullable) ActiveRule(org.sonarsource.sonarlint.core.analysis.api.ActiveRule) StandaloneSonarLintEngine(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine) Collectors.toSet(java.util.stream.Collectors.toSet) AnalysisConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration) Predicate(java.util.function.Predicate) PluginInstancesRepository(org.sonarsource.sonarlint.core.plugin.commons.PluginInstancesRepository) Collection(java.util.Collection) PluginDetails(org.sonarsource.sonarlint.core.client.api.common.PluginDetails) Set(java.util.Set) ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) Collectors(java.util.stream.Collectors) StandaloneRule(org.sonarsource.sonarlint.core.container.standalone.rule.StandaloneRule) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalysisEngineConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisEngineConfiguration) RuleKey(org.sonarsource.sonarlint.core.client.api.common.RuleKey) Optional(java.util.Optional) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) SonarLintRuleDefinition(org.sonarsource.sonarlint.core.rule.extractor.SonarLintRuleDefinition) RuleKey(org.sonarsource.sonarlint.core.client.api.common.RuleKey) ActiveRule(org.sonarsource.sonarlint.core.analysis.api.ActiveRule) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 AnalysisEngine (org.sonarsource.sonarlint.core.analysis.AnalysisEngine)2 ActiveRule (org.sonarsource.sonarlint.core.analysis.api.ActiveRule)2 AnalysisConfiguration (org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration)2 AnalysisEngineConfiguration (org.sonarsource.sonarlint.core.analysis.api.AnalysisEngineConfiguration)2 AnalysisResults (org.sonarsource.sonarlint.core.analysis.api.AnalysisResults)2 AnalyzeCommand (org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)2 PluginDetails (org.sonarsource.sonarlint.core.client.api.common.PluginDetails)2 DefaultClientIssue (org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue)2 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)2 SonarLintWrappedException (org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException)2