View Javadoc

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  import java.util.List;
30  
31  import com.aragost.javahg.Repository;
32  import com.aragost.javahg.commands.flags.ResolveCommandFlags;
33  import com.aragost.javahg.internals.HgInputStream;
34  import com.aragost.javahg.internals.RuntimeIOException;
35  import com.aragost.javahg.internals.Utils;
36  import com.google.common.collect.Lists;
37  
38  /**
39   * Command class for executing <tt>hg resolve</tt>. The resolve
40   * command is actually a front-end for several sub-commands:
41   * <ul>
42   * <li>with <tt>--list</tt>, it lists the current merge state. Use
43   * {@link #list()} for this command.</li>
44   * <li>with <tt>--mark</tt> and <tt>--unmark</tt> it manipulates the
45   * current merge state. Use {@link #mark(String...)} and
46   * {@link #unmark(String...)} for these commands.</li>
47   * <li>without the above flags it re-merges files. Use
48   * {@link #execute(String...)} for this command.</li>
49   * </li>
50   * </ul>
51   */
52  public class ResolveCommand extends ResolveCommandFlags {
53  
54      /**
55       * @param repository
56       *            the repository associated with this command.
57       */
58      public ResolveCommand(Repository repository) {
59          super(repository);
60      }
61  
62      /**
63       * @param files
64       *            the files to re-merge
65       * @return the command output
66       */
67      public String execute(String... files) {
68          return launchString(files);
69      }
70  
71      /**
72       * This correspond to the --list option for resolve.
73       * 
74       * @return List we status of merge files
75       */
76      public List<ResolveStatusLine> list() {
77          HgInputStream stream = launchStream("--list");
78          List<ResolveStatusLine> result = Lists.newArrayList();
79          try {
80              while (stream.peek() != -1) {
81                  result.add(ResolveStatusLine.fromStream(stream));
82              }
83          } catch (IOException e) {
84              throw new RuntimeIOException(e);
85          }
86          return result;
87      }
88  
89      @Override
90      public boolean isSuccessful() {
91          return super.isSuccessful() || getReturnCode() == 1;
92      }
93  
94      /**
95       * @param files
96       *            the files to mark as resolved.
97       */
98      public void mark(String... files) {
99          launchString(Utils.arrayUnshift("--mark", files));
100     }
101 
102     /**
103      * @param files
104      *            the files to mark as unresolved.
105      */
106     public void unmark(String... files) {
107         launchString(Utils.arrayUnshift("--unmark", files));
108     }
109 
110 }