public RailsNotesResults parse(ByteArrayOutputStream output) {
return parse(output.toString());
}
public RailsNotesResults parse(String output) {
RailsNotesResults response = new RailsNotesResults();
String[] aux = output.split("[\n\r]");
Collection<String> lines = new LinkedHashSet<String>(Arrays.asList(aux));
lines = removeSeparators(lines);
// Fortunately a LinkedHashSet has a predictable order, so this can use the filenames
Iterator<String> linesIterator = lines.iterator();
String lastFile = "";
while (linesIterator.hasNext()) {
String line = linesIterator.next();
if (StringUtils.isEmpty(line.trim())) continue;
// Filename lines don't start with a space. Annotation lines do.
if (line.charAt(0) != ' ') {
lastFile = line.substring(0, line.length() - 1); // remove colon from end of line
} else {
for (RailsNotesMetrics metric : RailsNotesMetrics.values()) {
// Match " * [line#] [ANNOTATION]"
Pattern metricPattern = Pattern.compile("^ \\* \\[[\\s\\d]+\\] \\[" + metric.toString() + "\\]");
if (metricPattern.matcher(line).find()) {
response.addAnnotationFor(lastFile, metric);
break; // next line
}
}
}
}
response.setOutput(output);
return response;
}