1 /*
2 * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
3 * and other copyright owners as documented in the project's IP log.
4 *
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
23 *
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43 package org.eclipse.jgit.api;
44
45 import java.util.ArrayList;
46 import java.util.List;
47
48 /**
49 * Encapsulates the result of a {@link CheckoutCommand}
50 *
51 */
52 public class CheckoutResult {
53
54 /**
55 * The {@link Status#ERROR} result;
56 */
57 public static final CheckoutResult ERROR_RESULT = new CheckoutResult(
58 Status.ERROR, null);
59
60 /**
61 * The {@link Status#NOT_TRIED} result;
62 */
63 public static final CheckoutResult NOT_TRIED_RESULT = new CheckoutResult(
64 Status.NOT_TRIED, null);
65
66 /**
67 * The status
68 */
69 public enum Status {
70 /**
71 * The call() method has not yet been executed
72 */
73 NOT_TRIED,
74 /**
75 * Checkout completed normally
76 */
77 OK,
78 /**
79 * Checkout has not completed because of checkout conflicts
80 */
81 CONFLICTS,
82 /**
83 * Checkout has completed, but some files could not be deleted
84 */
85 NONDELETED,
86 /**
87 * An Exception occurred during checkout
88 */
89 ERROR;
90 }
91
92 private final Status myStatus;
93
94 private final List<String> conflictList;
95
96 private final List<String> undeletedList;
97
98 private final List<String> modifiedList;
99
100 private final List<String> removedList;
101
102 /**
103 * Create a new fail result. If status is {@link Status#CONFLICTS},
104 * <code>fileList</code> is a list of conflicting files, if status is
105 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
106 * files. All other values ignore <code>fileList</code>. To create a result
107 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
108 *
109 * @param status
110 * the failure status
111 * @param fileList
112 * the list of files to store, status has to be either
113 * {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
114 */
115 CheckoutResult(Status status, List<String> fileList) {
116 myStatus = status;
117 if (status == Status.CONFLICTS)
118 this.conflictList = fileList;
119 else
120 this.conflictList = new ArrayList<String>(0);
121 if (status == Status.NONDELETED)
122 this.undeletedList = fileList;
123 else
124 this.undeletedList = new ArrayList<String>(0);
125
126 this.modifiedList = new ArrayList<String>(0);
127 this.removedList = new ArrayList<String>(0);
128 }
129
130 /**
131 * Create a new OK result with modified and removed files.
132 *
133 * @param modified
134 * the modified files
135 * @param removed
136 * the removed files.
137 */
138 CheckoutResult(List<String> modified, List<String> removed) {
139 myStatus = Status.OK;
140
141 this.conflictList = new ArrayList<String>(0);
142 this.undeletedList = new ArrayList<String>(0);
143
144 this.modifiedList = modified;
145 this.removedList = removed;
146 }
147
148 /**
149 * @return the status
150 */
151 public Status getStatus() {
152 return myStatus;
153 }
154
155 /**
156 * @return the list of files that created a checkout conflict, or an empty
157 * list if {@link #getStatus()} is not {@link Status#CONFLICTS};
158 */
159 public List<String> getConflictList() {
160 return conflictList;
161 }
162
163 /**
164 * @return the list of files that could not be deleted during checkout, or
165 * an empty list if {@link #getStatus()} is not
166 * {@link Status#NONDELETED};
167 */
168 public List<String> getUndeletedList() {
169 return undeletedList;
170 }
171
172 /**
173 * @return the list of files that where modified during checkout, or an
174 * empty list if {@link #getStatus()} is not {@link Status#OK}
175 */
176 public List<String> getModifiedList() {
177 return modifiedList;
178 }
179
180 /**
181 * @return the list of files that where removed during checkout, or an empty
182 * list if {@link #getStatus()} is not {@link Status#OK}
183 */
184 public List<String> getRemovedList() {
185 return removedList;
186 }
187 }