Search in sources :

Example 1 with ActiveRulesAdapter

use of org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter in project sonarlint-core by SonarSource.

the class SensorOptimizerTests method should_optimize_on_repository.

@Test
void should_optimize_on_repository() {
    var descriptor = new DefaultSensorDescriptor().createIssuesForRuleRepositories("squid");
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    var ruleAnotherRepo = mock(ActiveRuleAdapter.class);
    when(ruleAnotherRepo.ruleKey()).thenReturn(RuleKey.of("repo1", "foo"));
    ActiveRules activeRules = new ActiveRulesAdapter(List.of(ruleAnotherRepo));
    optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
    assertThat(optimizer.shouldExecute(descriptor)).isFalse();
    var ruleSquid = mock(ActiveRuleAdapter.class);
    when(ruleSquid.ruleKey()).thenReturn(RuleKey.of("squid", "rule"));
    activeRules = new ActiveRulesAdapter(asList(ruleSquid, ruleAnotherRepo));
    optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
    assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
Also used : DefaultSensorDescriptor(org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor) ActiveRules(org.sonar.api.batch.rule.ActiveRules) ActiveRulesAdapter(org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter) Test(org.junit.jupiter.api.Test)

Example 2 with ActiveRulesAdapter

use of org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter in project sonarlint-core by SonarSource.

the class ModuleContainer method analyze.

public AnalysisResults analyze(AnalysisConfiguration configuration, Consumer<Issue> issueListener, ProgressMonitor progress) {
    var analysisContainer = new AnalysisContainer(this, progress);
    analysisContainer.add(configuration);
    analysisContainer.add(new IssueListenerHolder(issueListener));
    analysisContainer.add(new ActiveRulesAdapter(configuration.activeRules().stream().map(ActiveRuleAdapter::new).collect(Collectors.toList())));
    var defaultAnalysisResult = new AnalysisResults();
    analysisContainer.add(defaultAnalysisResult);
    analysisContainer.execute();
    return defaultAnalysisResult;
}
Also used : AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) AnalysisContainer(org.sonarsource.sonarlint.core.analysis.container.analysis.AnalysisContainer) ActiveRulesAdapter(org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter) IssueListenerHolder(org.sonarsource.sonarlint.core.analysis.container.analysis.IssueListenerHolder)

Aggregations

ActiveRulesAdapter (org.sonarsource.sonarlint.core.analysis.sonarapi.ActiveRulesAdapter)2 Test (org.junit.jupiter.api.Test)1 ActiveRules (org.sonar.api.batch.rule.ActiveRules)1 AnalysisResults (org.sonarsource.sonarlint.core.analysis.api.AnalysisResults)1 AnalysisContainer (org.sonarsource.sonarlint.core.analysis.container.analysis.AnalysisContainer)1 IssueListenerHolder (org.sonarsource.sonarlint.core.analysis.container.analysis.IssueListenerHolder)1 DefaultSensorDescriptor (org.sonarsource.sonarlint.core.analysis.sonarapi.DefaultSensorDescriptor)1