BuildChangeLog { public static Change [] process(String string) { int revision = 0; ArrayList<Change> list = new ArrayList<Change>(100); String [] commits = string.split("\f"); Pattern pat = Pattern.compile(".*\\$foruser\\$(.*)",Pattern.DOTALL|Pattern.MULTILINE); DateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy Z"); for (String c : commits) { String [] cols = c.trim().split("\t"); if (cols.length < 4) continue; String author = cols[1]; String date = cols[2]; String logs = cols[3]; revision++; logs = logs.split("git-svn-id:")[0]; try { Date parsedDate = df.parse(date); Matcher mat = pat.matcher(logs); if (!mat.find()) continue; Change ch = new Change(); ch.revision = revision; ch.authorString = author.trim(); ch.logString = mat.group(1).trim(); ch.dateString = date; ch.date = parsedDate; list.add(ch); } catch (ParseException e) { e.printStackTrace(); } } int totalRevisions = revision; Change [] c = new Change[list.size()]; list.toArray(c); for (int i=0; i < c.length; i++) { c[i].revision = totalRevisions - c[i].revision; c[i].revisionString = Integer.toString(c[i].revision); } return c; }  static Change [] process(String string); static void main(String[] args);  }
@Test public void testBasicLog() { String string = "a0cad40\tSebastian Bauer\tThu Feb 4 16:30:58 2016 +0100\tIntroduced ArrayBufferHttpRequest class.\n" + "\n" + "$foruser$Test\n\f" + "86f4645\tSebastian Bauer\tWed Feb 3 21:35:51 2016 +0100\tAdded \"Ontologize\" button and use bootstrap table to display results.\n" + "\n" + "It is all very slow.\n"+ "\n\f" + "ae87f12\tSebastian Bauer\tWed Feb 3 21:36:21 2016 +0100\tTeaVM compatibility.\n" + "$foruser$Test2\n" + "\n\f" + "c918776\tSebastian Bauer\tWed Feb 3 21:31:38 2016 +0100\tExtracted HTMLTextAreaElement class.\n" + "$foruser$Test3\n"+ "\n\f"; Change [] result = BuildChangeLog.process(string); assertEquals(3,result.length); assertEquals("Test", result[0].logString); assertEquals("Sebastian Bauer", result[0].authorString); assertEquals("Test2", result[1].logString); assertEquals("Sebastian Bauer", result[1].authorString); assertEquals("Test3", result[2].logString); assertEquals("Sebastian Bauer", result[2].authorString); }