@Test public void testParseEmpty() throws Exception { String output = ""; History result = instance.parseContents(new BufferedReader(new StringReader(output))); assertEquals(0, result.getHistoryEntries().size()); }
protected History parseContents(BufferedReader contents) throws IOException { String line; ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); HistoryEntry entry = null; boolean ignoreEntry = false; boolean seenActionType = false; boolean lastWasTitle = true; Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher(""); Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher(""); while ((line = contents.readLine()) != null) { parseDebug("Processing '" + line + "'"); if (StringUtils.isOnlyWhitespace(line)) { if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); ignoreEntry = false; seenActionType = false; } else if (!ignoreEntry) { if (seenActionType) { infoMatcher.reset(line); if (infoMatcher.find()) { String infoType = infoMatcher.group(1); String details = infoMatcher.group(2); if ("TITLE".equals(infoType)) { parseDebug("Setting Message : '" + details + "'"); entry.setMessage(details); lastWasTitle = true; } else { parseDebug("Ignoring Info Type Line '" + line + "'"); } } else { if (!line.startsWith("##") && line.charAt(0) == '#') { parseDebug("Seen Comment : '" + line + "'"); if (lastWasTitle) { entry.appendMessage(""); lastWasTitle = false; } entry.appendMessage(line.substring(1)); } else { parseProblem("Expecting addlInfo and got '" + line + "'"); } } } else { actionMatcher.reset(line); if (actionMatcher.find()) { seenActionType = true; if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); String actionType = actionMatcher.group(1); String userName = actionMatcher.group(2); String revision = actionMatcher.group(3); String state = actionMatcher.group(4); String dateTime = actionMatcher.group(5); parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime); if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) { entry.setAuthor(userName); entry.setRevision(revision); entry.setActive("Active".equals(state)); Date date = null; try { date = repository.parse(dateTime); } catch (ParseException pe) { throw new IOException("Could not parse date: " + dateTime, pe); } entry.setDate(date); ignoreEntry = false; } else { ignoreEntry = true; } } else { parseProblem("Expecting actionType and got '" + line + "'"); } } } } if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } History history = new History(); history.setHistoryEntries(entries); return history; }
RazorHistoryParser { protected History parseContents(BufferedReader contents) throws IOException { String line; ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); HistoryEntry entry = null; boolean ignoreEntry = false; boolean seenActionType = false; boolean lastWasTitle = true; Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher(""); Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher(""); while ((line = contents.readLine()) != null) { parseDebug("Processing '" + line + "'"); if (StringUtils.isOnlyWhitespace(line)) { if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); ignoreEntry = false; seenActionType = false; } else if (!ignoreEntry) { if (seenActionType) { infoMatcher.reset(line); if (infoMatcher.find()) { String infoType = infoMatcher.group(1); String details = infoMatcher.group(2); if ("TITLE".equals(infoType)) { parseDebug("Setting Message : '" + details + "'"); entry.setMessage(details); lastWasTitle = true; } else { parseDebug("Ignoring Info Type Line '" + line + "'"); } } else { if (!line.startsWith("##") && line.charAt(0) == '#') { parseDebug("Seen Comment : '" + line + "'"); if (lastWasTitle) { entry.appendMessage(""); lastWasTitle = false; } entry.appendMessage(line.substring(1)); } else { parseProblem("Expecting addlInfo and got '" + line + "'"); } } } else { actionMatcher.reset(line); if (actionMatcher.find()) { seenActionType = true; if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); String actionType = actionMatcher.group(1); String userName = actionMatcher.group(2); String revision = actionMatcher.group(3); String state = actionMatcher.group(4); String dateTime = actionMatcher.group(5); parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime); if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) { entry.setAuthor(userName); entry.setRevision(revision); entry.setActive("Active".equals(state)); Date date = null; try { date = repository.parse(dateTime); } catch (ParseException pe) { throw new IOException("Could not parse date: " + dateTime, pe); } entry.setDate(date); ignoreEntry = false; } else { ignoreEntry = true; } } else { parseProblem("Expecting actionType and got '" + line + "'"); } } } } if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } History history = new History(); history.setHistoryEntries(entries); return history; } }
RazorHistoryParser { protected History parseContents(BufferedReader contents) throws IOException { String line; ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); HistoryEntry entry = null; boolean ignoreEntry = false; boolean seenActionType = false; boolean lastWasTitle = true; Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher(""); Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher(""); while ((line = contents.readLine()) != null) { parseDebug("Processing '" + line + "'"); if (StringUtils.isOnlyWhitespace(line)) { if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); ignoreEntry = false; seenActionType = false; } else if (!ignoreEntry) { if (seenActionType) { infoMatcher.reset(line); if (infoMatcher.find()) { String infoType = infoMatcher.group(1); String details = infoMatcher.group(2); if ("TITLE".equals(infoType)) { parseDebug("Setting Message : '" + details + "'"); entry.setMessage(details); lastWasTitle = true; } else { parseDebug("Ignoring Info Type Line '" + line + "'"); } } else { if (!line.startsWith("##") && line.charAt(0) == '#') { parseDebug("Seen Comment : '" + line + "'"); if (lastWasTitle) { entry.appendMessage(""); lastWasTitle = false; } entry.appendMessage(line.substring(1)); } else { parseProblem("Expecting addlInfo and got '" + line + "'"); } } } else { actionMatcher.reset(line); if (actionMatcher.find()) { seenActionType = true; if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); String actionType = actionMatcher.group(1); String userName = actionMatcher.group(2); String revision = actionMatcher.group(3); String state = actionMatcher.group(4); String dateTime = actionMatcher.group(5); parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime); if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) { entry.setAuthor(userName); entry.setRevision(revision); entry.setActive("Active".equals(state)); Date date = null; try { date = repository.parse(dateTime); } catch (ParseException pe) { throw new IOException("Could not parse date: " + dateTime, pe); } entry.setDate(date); ignoreEntry = false; } else { ignoreEntry = true; } } else { parseProblem("Expecting actionType and got '" + line + "'"); } } } } if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } History history = new History(); history.setHistoryEntries(entries); return history; }  }
RazorHistoryParser { protected History parseContents(BufferedReader contents) throws IOException { String line; ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); HistoryEntry entry = null; boolean ignoreEntry = false; boolean seenActionType = false; boolean lastWasTitle = true; Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher(""); Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher(""); while ((line = contents.readLine()) != null) { parseDebug("Processing '" + line + "'"); if (StringUtils.isOnlyWhitespace(line)) { if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); ignoreEntry = false; seenActionType = false; } else if (!ignoreEntry) { if (seenActionType) { infoMatcher.reset(line); if (infoMatcher.find()) { String infoType = infoMatcher.group(1); String details = infoMatcher.group(2); if ("TITLE".equals(infoType)) { parseDebug("Setting Message : '" + details + "'"); entry.setMessage(details); lastWasTitle = true; } else { parseDebug("Ignoring Info Type Line '" + line + "'"); } } else { if (!line.startsWith("##") && line.charAt(0) == '#') { parseDebug("Seen Comment : '" + line + "'"); if (lastWasTitle) { entry.appendMessage(""); lastWasTitle = false; } entry.appendMessage(line.substring(1)); } else { parseProblem("Expecting addlInfo and got '" + line + "'"); } } } else { actionMatcher.reset(line); if (actionMatcher.find()) { seenActionType = true; if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); String actionType = actionMatcher.group(1); String userName = actionMatcher.group(2); String revision = actionMatcher.group(3); String state = actionMatcher.group(4); String dateTime = actionMatcher.group(5); parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime); if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) { entry.setAuthor(userName); entry.setRevision(revision); entry.setActive("Active".equals(state)); Date date = null; try { date = repository.parse(dateTime); } catch (ParseException pe) { throw new IOException("Could not parse date: " + dateTime, pe); } entry.setDate(date); ignoreEntry = false; } else { ignoreEntry = true; } } else { parseProblem("Expecting actionType and got '" + line + "'"); } } } } if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } History history = new History(); history.setHistoryEntries(entries); return history; }   }
RazorHistoryParser { protected History parseContents(BufferedReader contents) throws IOException { String line; ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); HistoryEntry entry = null; boolean ignoreEntry = false; boolean seenActionType = false; boolean lastWasTitle = true; Matcher actionMatcher = ACTION_TYPE_PATTERN.matcher(""); Matcher infoMatcher = ADDITIONAL_INFO_PATTERN.matcher(""); while ((line = contents.readLine()) != null) { parseDebug("Processing '" + line + "'"); if (StringUtils.isOnlyWhitespace(line)) { if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); ignoreEntry = false; seenActionType = false; } else if (!ignoreEntry) { if (seenActionType) { infoMatcher.reset(line); if (infoMatcher.find()) { String infoType = infoMatcher.group(1); String details = infoMatcher.group(2); if ("TITLE".equals(infoType)) { parseDebug("Setting Message : '" + details + "'"); entry.setMessage(details); lastWasTitle = true; } else { parseDebug("Ignoring Info Type Line '" + line + "'"); } } else { if (!line.startsWith("##") && line.charAt(0) == '#') { parseDebug("Seen Comment : '" + line + "'"); if (lastWasTitle) { entry.appendMessage(""); lastWasTitle = false; } entry.appendMessage(line.substring(1)); } else { parseProblem("Expecting addlInfo and got '" + line + "'"); } } } else { actionMatcher.reset(line); if (actionMatcher.find()) { seenActionType = true; if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } entry = new HistoryEntry(); String actionType = actionMatcher.group(1); String userName = actionMatcher.group(2); String revision = actionMatcher.group(3); String state = actionMatcher.group(4); String dateTime = actionMatcher.group(5); parseDebug("New History Event Seen : actionType = " + actionType + ", userName = " + userName + ", revision = " + revision + ", state = " + state + ", dateTime = " + dateTime); if (actionType.startsWith("INTRODUCE") || actionType.contains("CHECK-IN") || "CHECK-POINT".equals(actionType) || "REVERT".equals(actionType)) { entry.setAuthor(userName); entry.setRevision(revision); entry.setActive("Active".equals(state)); Date date = null; try { date = repository.parse(dateTime); } catch (ParseException pe) { throw new IOException("Could not parse date: " + dateTime, pe); } entry.setDate(date); ignoreEntry = false; } else { ignoreEntry = true; } } else { parseProblem("Expecting actionType and got '" + line + "'"); } } } } if (entry != null && entry.getDate() != null) { entries.add(entry); dumpEntry(entry); } History history = new History(); history.setHistoryEntries(entries); return history; }    }