Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/StatusOutputParser.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.io.File; | |
20 import java.util.LinkedList; | |
21 import java.util.List; | |
22 import java.util.Map; | |
23 import java.util.regex.Matcher; | |
24 import java.util.regex.Pattern; | |
25 | |
26 import org.tmatesoft.hg.repo.HgStatusCollector; | |
27 import org.tmatesoft.hg.util.Path; | |
28 import org.tmatesoft.hg.util.PathPool; | |
29 import org.tmatesoft.hg.util.PathRewrite; | |
30 | |
31 /** | |
32 * | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public class StatusOutputParser implements OutputParser { | |
37 | |
38 private final Pattern pattern; | |
39 // although using StatusCollector.Record is not really quite honest for testing, | |
40 // it's deemed acceptable as long as that class is primitive 'collect all results' | |
41 private HgStatusCollector.Record result = new HgStatusCollector.Record(); | |
42 private final PathPool pathHelper; | |
43 | |
44 public StatusOutputParser() { | |
45 // pattern = Pattern.compile("^([MAR?IC! ]) ([\\w \\.-/\\\\]+)$", Pattern.MULTILINE); | |
46 pattern = Pattern.compile("^([MAR?IC! ]) (.+)$", Pattern.MULTILINE); | |
47 pathHelper = new PathPool(new PathRewrite() { | |
48 | |
49 private final boolean winPathSeparator = File.separatorChar == '\\'; | |
50 | |
51 public String rewrite(String s) { | |
52 if (winPathSeparator) { | |
53 // Java impl always give slashed path, while Hg uses local, os-specific convention | |
54 s = s.replace('\\', '/'); | |
55 } | |
56 return s; | |
57 } | |
58 }); | |
59 } | |
60 | |
61 public void reset() { | |
62 result = new HgStatusCollector.Record(); | |
63 } | |
64 | |
65 public void parse(CharSequence seq) { | |
66 Matcher m = pattern.matcher(seq); | |
67 Path lastEntry = null; | |
68 while (m.find()) { | |
69 Path fname = pathHelper.path(m.group(2)); | |
70 switch ((int) m.group(1).charAt(0)) { | |
71 case (int) 'M' : { | |
72 result.modified(fname); | |
73 lastEntry = fname; // for files modified through merge there's also 'copy' source | |
74 break; | |
75 } | |
76 case (int) 'A' : { | |
77 result.added(fname); | |
78 lastEntry = fname; | |
79 break; | |
80 } | |
81 case (int) 'R' : { | |
82 result.removed(fname); | |
83 break; | |
84 } | |
85 case (int) '?' : { | |
86 result.unknown(fname); | |
87 break; | |
88 } | |
89 case (int) 'I' : { | |
90 result.ignored(fname); | |
91 break; | |
92 } | |
93 case (int) 'C' : { | |
94 result.clean(fname); | |
95 break; | |
96 } | |
97 case (int) '!' : { | |
98 result.missing(fname); | |
99 break; | |
100 } | |
101 case (int) ' ' : { | |
102 // last added is copy destination | |
103 // to get or to remove it - depends on what StatusCollector does in this case | |
104 result.copied(fname, lastEntry); | |
105 lastEntry = null; | |
106 break; | |
107 } | |
108 } | |
109 } | |
110 } | |
111 | |
112 // | |
113 public List<Path> getModified() { | |
114 return result.getModified(); | |
115 } | |
116 | |
117 public List<Path> getAdded() { | |
118 List<Path> rv = new LinkedList<Path>(result.getAdded()); | |
119 for (Path p : result.getCopied().keySet()) { | |
120 rv.remove(p); // remove only one duplicate | |
121 } | |
122 return rv; | |
123 } | |
124 | |
125 public List<Path> getRemoved() { | |
126 return result.getRemoved(); | |
127 } | |
128 | |
129 public Map<Path,Path> getCopied() { | |
130 return result.getCopied(); | |
131 } | |
132 | |
133 public List<Path> getClean() { | |
134 return result.getClean(); | |
135 } | |
136 | |
137 public List<Path> getMissing() { | |
138 return result.getMissing(); | |
139 } | |
140 | |
141 public List<Path> getUnknown() { | |
142 return result.getUnknown(); | |
143 } | |
144 | |
145 public List<Path> getIgnored() { | |
146 return result.getIgnored(); | |
147 } | |
148 } |