comparison test/org/tmatesoft/hg/test/LogOutputParser.java @ 70:993f6f8e1314

Test for log command
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 23 Jan 2011 03:28:52 +0100
parents
children 6f1b88693d48
comparison
equal deleted inserted replaced
69:5a69397f0f99 70:993f6f8e1314
1 /*
2 * Copyright (c) 2011 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@svnkit.com
16 */
17 package org.tmatesoft.hg.test;
18
19 import java.util.LinkedList;
20 import java.util.List;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24 import com.tmate.hgkit.ll.HgRepository;
25
26 /**
27 *
28 * @author Artem Tikhomirov
29 * @author TMate Software Ltd.
30 */
31 public class LogOutputParser implements OutputParser {
32 private final List<Record> result = new LinkedList<Record>();
33 private Pattern pattern1;
34 private Pattern pattern2;
35 private Pattern pattern3;
36 private Pattern pattern4;
37
38 public LogOutputParser(boolean outputWithDebug) {
39 String p;
40 if (outputWithDebug) {
41 pattern1 = Pattern.compile("^changeset:\\s+(\\d+):([a-f0-9]{40})\n(^tag:(.+)$)?", Pattern.MULTILINE);
42 pattern2 = Pattern.compile("^parent:\\s+(-?\\d+):([a-f0-9]{40})\n", Pattern.MULTILINE);
43 pattern3 = Pattern.compile("^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:\\s+(\\S.+)\ndate:\\s+(\\S.+)\n", Pattern.MULTILINE);
44 pattern4 = Pattern.compile("^description:\n^(.+)\n\n", Pattern.MULTILINE);
45 //p = "^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:(.+)$";
46 } else {
47 throw HgRepository.notImplemented();
48 }
49 }
50
51 public void reset() {
52 result.clear();
53 }
54
55 public List<Record> getResult() {
56 return result;
57 }
58
59 public void parse(CharSequence seq) {
60 Matcher m = pattern1.matcher(seq);
61 while (m.find()) {
62 Record r = new Record();
63 r.changesetIndex = Integer.parseInt(m.group(1));
64 r.changesetNodeid = m.group(2);
65 //tags = m.group(4);
66 m.usePattern(pattern2);
67 if (m.find()) {
68 r.parent1Index = Integer.parseInt(m.group(1));
69 r.parent1Nodeid = m.group(2);
70 }
71 if (m.find()) {
72 r.parent2Index = Integer.parseInt(m.group(1));
73 r.parent2Nodeid = m.group(2);
74 }
75 m.usePattern(pattern3);
76 if (m.find()) {
77 r.user = m.group(3);
78 r.date = m.group(4);
79 }
80 m.usePattern(pattern4);
81 if (m.find()) {
82 r.description = m.group(1);
83 }
84 result.add(r);
85 m.usePattern(pattern1);
86 }
87 }
88
89 public static class Record {
90 public int changesetIndex;
91 public String changesetNodeid;
92 public int parent1Index;
93 public int parent2Index;
94 public String parent1Nodeid;
95 public String parent2Nodeid;
96 public String user;
97 public String date;
98 public String description;
99 }
100
101 private static void a(Matcher m) {
102 for (int i = 1; i <= m.groupCount(); i++) {
103 System.out.println("" + i + ":" + m.group(i));
104 }
105 }
106 }