use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.
the class DefaultSensorContextTest method prepare.
@Before
public void prepare() throws Exception {
activeRules = new ActiveRulesBuilder().build();
fs = new DefaultFileSystem(temp.newFolder().toPath());
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
settings = new MapSettings();
sensorStorage = mock(SensorStorage.class);
analysisMode = mock(AnalysisMode.class);
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER);
adaptor = new DefaultSensorContext(mock(InputModule.class), settings, fs, activeRules, analysisMode, sensorStorage, runtime);
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarqube by SonarSource.
the class SensorOptimizerTest method should_optimize_on_repository.
@Test
public void should_optimize_on_repository() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
ActiveRules activeRules = new ActiveRulesBuilder().create(RuleKey.of("repo1", "foo")).activate().build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
activeRules = new ActiveRulesBuilder().create(RuleKey.of("repo1", "foo")).activate().create(RuleKey.of("squid", "rule")).activate().build();
optimizer = new SensorOptimizer(fs, activeRules, settings);
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder 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;
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarlint-core by SonarSource.
the class SensorOptimizerTest method should_optimize_on_repository.
@Test
public void should_optimize_on_repository() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().createIssuesForRuleRepositories("squid");
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
ActiveRules activeRules = new ActiveRulesBuilder().create(RuleKey.of("repo1", "foo")).activate().build();
optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
activeRules = new ActiveRulesBuilder().create(RuleKey.of("repo1", "foo")).activate().create(RuleKey.of("squid", "rule")).activate().build();
optimizer = new SensorOptimizer(fs, activeRules, settings.asConfig());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonar.api.batch.rule.internal.ActiveRulesBuilder in project sonarlint-core by SonarSource.
the class StandaloneActiveRulesProvider method createActiveRules.
private ActiveRules createActiveRules() {
ActiveRulesBuilder builder = new ActiveRulesBuilder();
ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage(profileDefinitions);
for (String language : profilesByLanguage.keySet()) {
List<RulesProfile> defs = profilesByLanguage.get(language);
registerProfilesForLanguage(builder, language, defs);
}
for (Repository repo : ruleDefsLoader.getContext().repositories()) {
for (Rule rule : repo.rules()) {
if (rule.activatedByDefault()) {
NewActiveRule newAr = builder.create(RuleKey.of(repo.key(), rule.key())).setLanguage(repo.language()).setName(rule.name()).setSeverity(rule.severity()).setInternalKey(rule.internalKey());
for (Param param : rule.params()) {
newAr.setParam(param.key(), param.defaultValue());
}
newAr.activate();
}
}
}
return builder.build();
}
Aggregations