use of org.sonar.api.server.rule.RulesDefinition.Context in project sonarlint-core by SonarSource.
the class RulesDownloaderTest method prepare.
@Before
public void prepare() {
Context context = new Context();
context.createRepository("javascript", "js").done();
context.createRepository("squid", "java").done();
}
use of org.sonar.api.server.rule.RulesDefinition.Context in project sonarqube by SonarSource.
the class RegisterRulesTest method mass_insert_then_remove_rule.
@Test
public void mass_insert_then_remove_rule() {
int numberOfRules = 5000;
// register many rules
execute(context -> {
NewRepository repo = context.createRepository("fake", "java");
IntStream.range(0, numberOfRules).mapToObj(i -> "rule-" + i).forEach(ruleKey -> repo.createRule(ruleKey).setName(randomAlphanumeric(20)).setHtmlDescription(randomAlphanumeric(20)));
repo.done();
});
// verify db
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(READY);
// verify index
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isNotEmpty();
// register no rule
execute(context -> context.createRepository("fake", "java").done());
// verify db
assertThat(dbClient.ruleDao().selectAllDefinitions(db.getSession())).hasSize(numberOfRules).extracting(RuleDefinitionDto::getStatus).containsOnly(REMOVED);
// verify index (documents are still in the index, but all are removed)
assertThat(es.countDocuments(RuleIndexDefinition.TYPE_RULE)).isEqualTo(numberOfRules);
assertThat(ruleIndex.search(new RuleQuery(), new SearchOptions()).getUuids()).isEmpty();
}
use of org.sonar.api.server.rule.RulesDefinition.Context in project sonarlint-core by SonarSource.
the class RulesDefinitionExtractor method extractRules.
public List<SonarLintRuleDefinition> extractRules(PluginInstancesRepository pluginInstancesRepository, Set<Language> enabledLanguages, boolean includeTemplateRules) {
Context context;
try {
var container = new RulesDefinitionExtractorContainer(pluginInstancesRepository);
container.execute();
context = container.getContext();
} catch (Exception e) {
throw new IllegalStateException("Unable to extract rules metadata", e);
}
List<SonarLintRuleDefinition> rules = new ArrayList<>();
for (RulesDefinition.Repository repoDef : context.repositories()) {
if (repoDef.isExternal()) {
continue;
}
var repoLanguage = Language.forKey(repoDef.language());
if (repoLanguage.isEmpty() || !enabledLanguages.contains(repoLanguage.get())) {
continue;
}
for (RulesDefinition.Rule ruleDef : repoDef.rules()) {
if (ruleDef.type() == RuleType.SECURITY_HOTSPOT || (ruleDef.template() && !includeTemplateRules)) {
continue;
}
rules.add(new SonarLintRuleDefinition(ruleDef));
}
}
return rules;
}
Aggregations