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