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;
}
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);
}
}
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(), "");
}
Aggregations