Search in sources :

Example 1 with Repository

use of org.sonar.api.server.rule.RulesDefinition.Repository in project sonarlint-core by SonarSource.

the class StandaloneGlobalContainer method getRuleDetails.

public RuleDetails getRuleDetails(String ruleKeyStr) {
    RuleKey ruleKey = RuleKey.parse(ruleKeyStr);
    DefaultRule rule = (DefaultRule) rules.find(ruleKey);
    if (rule == null) {
        throw new IllegalArgumentException("Unable to find rule with key " + ruleKey);
    }
    Repository repo = rulesDefinitions.repository(rule.key().repository());
    return new DefaultRuleDetails(ruleKeyStr, rule.name(), rule.description(), rule.severity(), rule.type(), repo.language(), repo.rule(rule.key().rule()).tags(), "");
}
Also used : DefaultRule(org.sonar.api.batch.rule.internal.DefaultRule) Repository(org.sonar.api.server.rule.RulesDefinition.Repository) PluginRepository(org.sonarsource.sonarlint.core.plugin.PluginRepository) RuleKey(org.sonar.api.rule.RuleKey) DefaultRuleDetails(org.sonarsource.sonarlint.core.container.model.DefaultRuleDetails)

Example 2 with Repository

use of org.sonar.api.server.rule.RulesDefinition.Repository 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();
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) Repository(org.sonar.api.server.rule.RulesDefinition.Repository) RulesProfile(org.sonar.api.profiles.RulesProfile) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) ActiveRuleParam(org.sonar.api.rules.ActiveRuleParam) Param(org.sonar.api.server.rule.RulesDefinition.Param) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) Rule(org.sonar.api.server.rule.RulesDefinition.Rule) ActiveRule(org.sonar.api.rules.ActiveRule)

Aggregations

Repository (org.sonar.api.server.rule.RulesDefinition.Repository)2 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 DefaultRule (org.sonar.api.batch.rule.internal.DefaultRule)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 RulesProfile (org.sonar.api.profiles.RulesProfile)1 RuleKey (org.sonar.api.rule.RuleKey)1 ActiveRule (org.sonar.api.rules.ActiveRule)1 ActiveRuleParam (org.sonar.api.rules.ActiveRuleParam)1 Param (org.sonar.api.server.rule.RulesDefinition.Param)1 Rule (org.sonar.api.server.rule.RulesDefinition.Rule)1 DefaultRuleDetails (org.sonarsource.sonarlint.core.container.model.DefaultRuleDetails)1 PluginRepository (org.sonarsource.sonarlint.core.plugin.PluginRepository)1