Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/LogOutputParser.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Tue, 10 May 2011 10:52:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
212:edb2e2829352 | 213:6ec4af642ba8 |
---|---|
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@hg4j.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 org.tmatesoft.hg.repo.HgRepository; | |
25 | |
26 | |
27 /** | |
28 * | |
29 * @author Artem Tikhomirov | |
30 * @author TMate Software Ltd. | |
31 */ | |
32 public class LogOutputParser implements OutputParser { | |
33 private final List<Record> result = new LinkedList<Record>(); | |
34 private Pattern pattern1; | |
35 private Pattern pattern2; | |
36 private Pattern pattern3; | |
37 private Pattern pattern4; | |
38 private Pattern pattern5; | |
39 | |
40 public LogOutputParser(boolean outputWithDebug) { | |
41 if (outputWithDebug) { | |
42 pattern1 = Pattern.compile("^changeset:\\s+(\\d+):([a-f0-9]{40})\n(^tag:(.+)$)?", Pattern.MULTILINE); | |
43 pattern2 = Pattern.compile("^parent:\\s+(-?\\d+):([a-f0-9]{40})\n", Pattern.MULTILINE); | |
44 pattern3 = Pattern.compile("^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:\\s+(\\S.+)\ndate:\\s+(\\S.+)\n", Pattern.MULTILINE); | |
45 pattern4 = Pattern.compile("^description:\\n", Pattern.MULTILINE); | |
46 pattern5 = Pattern.compile("\\n\\n"); | |
47 //p = "^manifest:\\s+(\\d+):([a-f0-9]{40})\nuser:(.+)$"; | |
48 } else { | |
49 throw HgRepository.notImplemented(); | |
50 } | |
51 } | |
52 | |
53 public void reset() { | |
54 result.clear(); | |
55 } | |
56 | |
57 public List<Record> getResult() { | |
58 return result; | |
59 } | |
60 | |
61 public void parse(CharSequence seq) { | |
62 Matcher m = pattern1.matcher(seq); | |
63 while (m.find()) { | |
64 Record r = new Record(); | |
65 r.changesetIndex = Integer.parseInt(m.group(1)); | |
66 r.changesetNodeid = m.group(2); | |
67 //tags = m.group(4); | |
68 m.usePattern(pattern2); | |
69 if (m.find()) { | |
70 r.parent1Index = Integer.parseInt(m.group(1)); | |
71 r.parent1Nodeid = m.group(2); | |
72 } | |
73 if (m.find()) { | |
74 r.parent2Index = Integer.parseInt(m.group(1)); | |
75 r.parent2Nodeid = m.group(2); | |
76 } | |
77 m.usePattern(pattern3); | |
78 if (m.find()) { | |
79 r.user = m.group(3); | |
80 r.date = m.group(4); | |
81 } | |
82 m.usePattern(pattern4); | |
83 if (m.find()) { | |
84 int commentStart = m.end(); | |
85 m.usePattern(pattern5); | |
86 if (m.find()) { | |
87 r.description = seq.subSequence(commentStart, m.start()).toString(); | |
88 } | |
89 } | |
90 result.add(r); | |
91 m.usePattern(pattern1); | |
92 } | |
93 } | |
94 | |
95 public static class Record { | |
96 public int changesetIndex; | |
97 public String changesetNodeid; | |
98 public int parent1Index; | |
99 public int parent2Index; | |
100 public String parent1Nodeid; | |
101 public String parent2Nodeid; | |
102 public String user; | |
103 public String date; | |
104 public String description; | |
105 } | |
106 } |