Search in sources :

Example 1 with RulePriority

use of org.sonar.api.rules.RulePriority in project sonarqube by SonarSource.

the class AnnotationProfileParser method addRule.

private void addRule(Class aClass, BelongsToProfile annotation, RulesProfile profile, String repositoryKey, ValidationMessages messages) {
    if ((annotation != null) && StringUtils.equals(annotation.title(), profile.getName())) {
        String ruleKey = RuleAnnotationUtils.getRuleKey(aClass);
        Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey);
        if (rule == null) {
            messages.addWarningText("Rule not found: [repository=" + repositoryKey + ", key=" + ruleKey + "]");
        } else {
            RulePriority priority = null;
            if (annotation.priority() != null) {
                priority = RulePriority.fromCheckPriority(annotation.priority());
            }
            profile.activateRule(rule, priority);
        }
    }
}
Also used : Rule(org.sonar.api.rules.Rule) RulePriority(org.sonar.api.rules.RulePriority)

Example 2 with RulePriority

use of org.sonar.api.rules.RulePriority in project sonarqube by SonarSource.

the class XMLProfileParser method processRules.

private void processRules(SMInputCursor rulesCursor, RulesProfile profile, ValidationMessages messages) throws XMLStreamException {
    Map<String, String> parameters = new HashMap<>();
    while (rulesCursor.getNext() != null) {
        SMInputCursor ruleCursor = rulesCursor.childElementCursor();
        String repositoryKey = null;
        String key = null;
        RulePriority priority = null;
        parameters.clear();
        while (ruleCursor.getNext() != null) {
            String nodeName = ruleCursor.getLocalName();
            if (StringUtils.equals("repositoryKey", nodeName)) {
                repositoryKey = StringUtils.trim(ruleCursor.collectDescendantText(false));
            } else if (StringUtils.equals("key", nodeName)) {
                key = StringUtils.trim(ruleCursor.collectDescendantText(false));
            } else if (StringUtils.equals("priority", nodeName)) {
                priority = RulePriority.valueOf(StringUtils.trim(ruleCursor.collectDescendantText(false)));
            } else if (StringUtils.equals("parameters", nodeName)) {
                SMInputCursor propsCursor = ruleCursor.childElementCursor("parameter");
                processParameters(propsCursor, parameters);
            }
        }
        Rule rule = ruleFinder.findByKey(repositoryKey, key);
        if (rule == null) {
            messages.addWarningText("Rule not found: " + ruleToString(repositoryKey, key));
        } else {
            ActiveRule activeRule = profile.activateRule(rule, priority);
            for (Map.Entry<String, String> entry : parameters.entrySet()) {
                if (rule.getParam(entry.getKey()) == null) {
                    messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: " + ruleToString(repositoryKey, key));
                } else {
                    activeRule.setParameter(entry.getKey(), entry.getValue());
                }
            }
        }
    }
}
Also used : SMInputCursor(org.codehaus.staxmate.in.SMInputCursor) HashMap(java.util.HashMap) ActiveRule(org.sonar.api.rules.ActiveRule) RulePriority(org.sonar.api.rules.RulePriority) Rule(org.sonar.api.rules.Rule) ActiveRule(org.sonar.api.rules.ActiveRule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RulePriority

use of org.sonar.api.rules.RulePriority in project sonarqube by SonarSource.

the class IssuesReportBuilder method processIssues.

private void processIssues(IssuesReport issuesReport, Iterable<TrackedIssue> issues) {
    for (TrackedIssue issue : issues) {
        Rule rule = findRule(issue);
        RulePriority severity = RulePriority.valueOf(issue.severity());
        InputComponent resource = inputComponentStore.getByKey(issue.componentKey());
        if (!validate(issue, rule, resource)) {
            continue;
        }
        if (issue.resolution() != null) {
            issuesReport.addResolvedIssueOnResource(resource, rule, severity);
        } else {
            issuesReport.addIssueOnResource(resource, issue, rule, severity);
        }
    }
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) InputComponent(org.sonar.api.batch.fs.InputComponent) Rule(org.sonar.api.batch.rule.Rule) RulePriority(org.sonar.api.rules.RulePriority)

Aggregations

RulePriority (org.sonar.api.rules.RulePriority)3 Rule (org.sonar.api.rules.Rule)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SMInputCursor (org.codehaus.staxmate.in.SMInputCursor)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 Rule (org.sonar.api.batch.rule.Rule)1 ActiveRule (org.sonar.api.rules.ActiveRule)1 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)1