Mercurial > hg4j
annotate test/org/tmatesoft/hg/test/LogOutputParser.java @ 150:6b55f10ef54b
Unused variables removed.
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Thu, 24 Feb 2011 18:53:33 +0100 |
parents | a3a2e5deb320 |
children | 7a908ba66ff3 |
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 |
102
a3a2e5deb320
Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
74
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
70
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 |
74
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
70
diff
changeset
|
24 import org.tmatesoft.hg.repo.HgRepository; |
6f1b88693d48
Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
70
diff
changeset
|
25 |
70
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 * |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 * @author Artem Tikhomirov |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 * @author TMate Software Ltd. |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 */ |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 public class LogOutputParser implements OutputParser { |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 private final List<Record> result = new LinkedList<Record>(); |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 private Pattern pattern1; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 private Pattern pattern2; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 private Pattern pattern3; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 private Pattern pattern4; |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 |
993f6f8e1314
Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 public LogOutputParser(boolean outputWithDebug) { |
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 } |