Search in sources :

Example 1 with DefaultRule

use of org.sonar.api.batch.rule.internal.DefaultRule in project sonarlint-core by SonarSource.

the class DefaultSensorStorage method validateRule.

private DefaultRule validateRule(Issue issue) {
    RuleKey ruleKey = issue.ruleKey();
    Rule rule = rules.find(ruleKey);
    if (rule == null) {
        throw MessageException.of(String.format("The rule '%s' does not exist.", ruleKey));
    }
    if (Strings.isNullOrEmpty(rule.name()) && Strings.isNullOrEmpty(issue.primaryLocation().message())) {
        throw MessageException.of(String.format("The rule '%s' has no name and the related issue has no message.", ruleKey));
    }
    return (DefaultRule) rule;
}
Also used : DefaultRule(org.sonar.api.batch.rule.internal.DefaultRule) RuleKey(org.sonar.api.rule.RuleKey) ActiveRule(org.sonar.api.batch.rule.ActiveRule) Rule(org.sonar.api.batch.rule.Rule) DefaultRule(org.sonar.api.batch.rule.internal.DefaultRule)

Example 2 with DefaultRule

use of org.sonar.api.batch.rule.internal.DefaultRule in project sonarlint-core by SonarSource.

the class DefaultSensorStorage method store.

@Override
public void store(Issue issue) {
    InputComponent inputComponent = issue.primaryLocation().inputComponent();
    DefaultRule rule = validateRule(issue);
    ActiveRule activeRule = activeRules.find(issue.ruleKey());
    if (activeRule == null) {
        // rule does not exist or is not enabled -> ignore the issue
        return;
    }
    String primaryMessage = Strings.isNullOrEmpty(issue.primaryLocation().message()) ? rule.name() : issue.primaryLocation().message();
    org.sonar.api.batch.rule.Severity overriddenSeverity = issue.overriddenSeverity();
    String severity = overriddenSeverity != null ? overriddenSeverity.name() : activeRule.severity();
    String type = rule.type();
    DefaultClientIssue newIssue = new DefaultClientIssue(severity, type, activeRule, rules.find(activeRule.ruleKey()), primaryMessage, issue.primaryLocation().textRange(), inputComponent.isFile() ? ((SonarLintInputFile) inputComponent).getClientInputFile() : null, issue.flows());
    if (filters.accept(inputComponent, newIssue)) {
        issueListener.handle(newIssue);
    }
}
Also used : DefaultRule(org.sonar.api.batch.rule.internal.DefaultRule) SonarLintInputFile(org.sonarsource.sonarlint.core.container.analysis.filesystem.SonarLintInputFile) InputComponent(org.sonar.api.batch.fs.InputComponent) ActiveRule(org.sonar.api.batch.rule.ActiveRule) DefaultClientIssue(org.sonarsource.sonarlint.core.analyzer.issue.DefaultClientIssue)

Example 3 with DefaultRule

use of org.sonar.api.batch.rule.internal.DefaultRule 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)

Aggregations

DefaultRule (org.sonar.api.batch.rule.internal.DefaultRule)3 ActiveRule (org.sonar.api.batch.rule.ActiveRule)2 RuleKey (org.sonar.api.rule.RuleKey)2 InputComponent (org.sonar.api.batch.fs.InputComponent)1 Rule (org.sonar.api.batch.rule.Rule)1 Repository (org.sonar.api.server.rule.RulesDefinition.Repository)1 DefaultClientIssue (org.sonarsource.sonarlint.core.analyzer.issue.DefaultClientIssue)1 SonarLintInputFile (org.sonarsource.sonarlint.core.container.analysis.filesystem.SonarLintInputFile)1 DefaultRuleDetails (org.sonarsource.sonarlint.core.container.model.DefaultRuleDetails)1 PluginRepository (org.sonarsource.sonarlint.core.plugin.PluginRepository)1