1 /*
2 * #%L
3 * JavaHg
4 * %%
5 * Copyright (C) 2011 aragost Trifork ag
6 * %%
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 * #L%
25 */
26 package com.aragost.javahg.commands;
27
28 import java.io.IOException;
29
30 import com.aragost.javahg.internals.BaseStatusLine;
31 import com.aragost.javahg.internals.HgInputStream;
32
33 /**
34 * A parsed line from the <tt>hg status</tt> output.
35 */
36 public class StatusLine extends BaseStatusLine<StatusLine.Type> {
37
38 /**
39 * Status line types.
40 */
41 public enum Type {
42
43 /**
44 * A modified file.
45 */
46 MODIFIED('M'),
47 /**
48 * An added file.
49 */
50 ADDED('A'),
51 /**
52 * A removed file.
53 */
54 REMOVED('R'),
55 /**
56 * A clean file.
57 */
58 CLEAN('C'),
59 /**
60 * A missing file (deleted outside of Mercurial)
61 */
62 MISSING('!'),
63 /**
64 * An unknown file.
65 */
66 UNKNOWN('?'),
67 /**
68 * An ignored file.
69 */
70 IGNORED('I'),
71 /**
72 * The origin of a copied file.
73 */
74 ORIGIN(' ');
75
76 private final char discriminator;
77
78 private Type(char discriminator) {
79 this.discriminator = discriminator;
80 }
81 }
82
83 /**
84 * @param stream
85 * the output of <tt>hg status</tt>
86 * @return the parsed status line
87 * @throws IOException
88 */
89 public static StatusLine fromStream(HgInputStream stream) throws IOException {
90 StatusLine result = new StatusLine();
91 result.initFromStream(stream);
92 return result;
93 }
94
95 @Override
96 protected Type typeForChar(char ch) {
97 for (Type t : Type.values()) {
98 if (t.discriminator == ch) {
99 return t;
100 }
101 }
102 throw new IllegalArgumentException("No status type for " + ch);
103 }
104 }