final List<Rule> rules = new ArrayList<Rule>();
final List<String> listLines = IOUtils.readLines(reader);
String previousLine = null;
Rule rule = null;
boolean inDescription = false;
for (String line : listLines) {
if (isLineIgnored(line)) {
inDescription = false;
} else if (line.matches("[\\-]{4,}.*")) {
LOGGER.debug("Rule found : {}", previousLine);
// remove the rule name from the description of the previous
// rule
if (rule != null) {
final int index = rule.getDescription().lastIndexOf(
previousLine);
if (index > 0) {
rule.setDescription(rule.getDescription().substring(0,
index));
}
}
rule = Rule.create();
rules.add(rule);
rule.setName(previousLine);
rule.setKey(previousLine);
} else if (line.matches("Summary:.*")) {
inDescription = true;
rule.setDescription(line.substring(line.indexOf(':') + 1));
} else if (line.matches("Category:.*")) {
inDescription = true;
} else if (line.matches("Severity:.*")) {
inDescription = false;
final String severity = line.substring("Severity: ".length());
// Rules are priority 1, 2 or 3 in OCLint files.
rule.setSeverity(RulePriority.values()[OCLINT_MINIMUM_PRIORITY
- Integer.valueOf(severity)]);
} else {
if (inDescription) {
line = ruleDescriptionLink(line);
rule.setDescription(rule.getDescription() + "<br>" + line);
}
}
previousLine = line;
}
return rules;