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