@Test public void parseFileLog() throws Exception { String output = " "\n" + "... #4 change 1234 edit on 2008/08/19 11:30:00 by User@UserWorkspaceName (text)\n" + "\n" + "\tComment for the change number 4\n" + "\n" + "... #3 change 5678 edit on 2008/08/19 18:25:38 by ADMIN@UserWorkspaceName (text)\n" + "\n" + "\tComment for the change\n" + "\n" + "... #2 change 8765 edit on 2008/08/01 01:00:01 by ADMIN@UserWorkspaceName (text)\n" + "\n" + "\tComment for the change\n" + "\n" + "... #1 change 1 add on 2008/07/30 17:45:33 by ADMIN@UserWorkspaceName (text)\n" + "\n" + "\tComment for the change"; PerforceHistoryParser parser = new PerforceHistoryParser(new PerforceRepository()); History result = parser.parseFileLog(new StringReader(output)); assertNotNull(result); assertEquals(4, result.getHistoryEntries().size()); HistoryEntry e1 = result.getHistoryEntries().get(0); assertEquals("1234", e1.getRevision()); assertEquals("User", e1.getAuthor()); assertEquals(1, e1.getFiles().size()); assertTrue(e1.getMessage().contains("number 4")); HistoryEntry e2 = result.getHistoryEntries().get(1); assertNotNull(e2); HistoryEntry e3 = result.getHistoryEntries().get(2); assertNotNull(e3); HistoryEntry e4 = result.getHistoryEntries().get(3); assertEquals("1", e4.getRevision()); assertDate(e1, 2008, Calendar.AUGUST, 19); assertDate(e2, 2008, Calendar.AUGUST, 19); assertDate(e3, 2008, Calendar.AUGUST, 1); assertDate(e4, 2008, Calendar.JULY, 30); }
History parseFileLog(Reader fileLog) throws IOException { List<HistoryEntry> entries = new ArrayList<>(); HistoryEntry entry = null; String fileName = null; StringBuilder messageBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(fileLog)) { String line; while ((line = reader.readLine()) != null) { Matcher matcher = FILENAME_PATTERN.matcher(line); if (matcher.find()) { fileName = repo.getDirectoryNameRelative() + File.separator + unprotectPerforceFilename(matcher.group(1)); continue; } matcher = REVISION_PATTERN.matcher(line); if (matcher.find()) { entry = parseEntryLine(entries, entry, messageBuilder, matcher); if (fileName != null) { entry.addFile(fileName); } continue; } if (line.startsWith("\t")) { messageBuilder.append(line.substring(1)); messageBuilder.append("\n"); } else if (line.startsWith("... ...")) { if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); entry = null; } messageBuilder.setLength(0); } } } if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); } History history = new History(); history.setHistoryEntries(entries); return history; }
PerforceHistoryParser { History parseFileLog(Reader fileLog) throws IOException { List<HistoryEntry> entries = new ArrayList<>(); HistoryEntry entry = null; String fileName = null; StringBuilder messageBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(fileLog)) { String line; while ((line = reader.readLine()) != null) { Matcher matcher = FILENAME_PATTERN.matcher(line); if (matcher.find()) { fileName = repo.getDirectoryNameRelative() + File.separator + unprotectPerforceFilename(matcher.group(1)); continue; } matcher = REVISION_PATTERN.matcher(line); if (matcher.find()) { entry = parseEntryLine(entries, entry, messageBuilder, matcher); if (fileName != null) { entry.addFile(fileName); } continue; } if (line.startsWith("\t")) { messageBuilder.append(line.substring(1)); messageBuilder.append("\n"); } else if (line.startsWith("... ...")) { if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); entry = null; } messageBuilder.setLength(0); } } } if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); } History history = new History(); history.setHistoryEntries(entries); return history; } }
PerforceHistoryParser { History parseFileLog(Reader fileLog) throws IOException { List<HistoryEntry> entries = new ArrayList<>(); HistoryEntry entry = null; String fileName = null; StringBuilder messageBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(fileLog)) { String line; while ((line = reader.readLine()) != null) { Matcher matcher = FILENAME_PATTERN.matcher(line); if (matcher.find()) { fileName = repo.getDirectoryNameRelative() + File.separator + unprotectPerforceFilename(matcher.group(1)); continue; } matcher = REVISION_PATTERN.matcher(line); if (matcher.find()) { entry = parseEntryLine(entries, entry, messageBuilder, matcher); if (fileName != null) { entry.addFile(fileName); } continue; } if (line.startsWith("\t")) { messageBuilder.append(line.substring(1)); messageBuilder.append("\n"); } else if (line.startsWith("... ...")) { if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); entry = null; } messageBuilder.setLength(0); } } } if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); } History history = new History(); history.setHistoryEntries(entries); return history; } PerforceHistoryParser(PerforceRepository repo); }
PerforceHistoryParser { History parseFileLog(Reader fileLog) throws IOException { List<HistoryEntry> entries = new ArrayList<>(); HistoryEntry entry = null; String fileName = null; StringBuilder messageBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(fileLog)) { String line; while ((line = reader.readLine()) != null) { Matcher matcher = FILENAME_PATTERN.matcher(line); if (matcher.find()) { fileName = repo.getDirectoryNameRelative() + File.separator + unprotectPerforceFilename(matcher.group(1)); continue; } matcher = REVISION_PATTERN.matcher(line); if (matcher.find()) { entry = parseEntryLine(entries, entry, messageBuilder, matcher); if (fileName != null) { entry.addFile(fileName); } continue; } if (line.startsWith("\t")) { messageBuilder.append(line.substring(1)); messageBuilder.append("\n"); } else if (line.startsWith("... ...")) { if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); entry = null; } messageBuilder.setLength(0); } } } if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); } History history = new History(); history.setHistoryEntries(entries); return history; } PerforceHistoryParser(PerforceRepository repo);  }
PerforceHistoryParser { History parseFileLog(Reader fileLog) throws IOException { List<HistoryEntry> entries = new ArrayList<>(); HistoryEntry entry = null; String fileName = null; StringBuilder messageBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(fileLog)) { String line; while ((line = reader.readLine()) != null) { Matcher matcher = FILENAME_PATTERN.matcher(line); if (matcher.find()) { fileName = repo.getDirectoryNameRelative() + File.separator + unprotectPerforceFilename(matcher.group(1)); continue; } matcher = REVISION_PATTERN.matcher(line); if (matcher.find()) { entry = parseEntryLine(entries, entry, messageBuilder, matcher); if (fileName != null) { entry.addFile(fileName); } continue; } if (line.startsWith("\t")) { messageBuilder.append(line.substring(1)); messageBuilder.append("\n"); } else if (line.startsWith("... ...")) { if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); entry = null; } messageBuilder.setLength(0); } } } if (entry != null) { entry.setMessage(messageBuilder.toString().trim()); entries.add(entry); } History history = new History(); history.setHistoryEntries(entries); return history; } PerforceHistoryParser(PerforceRepository repo);   }