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 org.eclipse.jgit.api.CheckoutCommand}
50 */
51 public class CheckoutResult {
52
53 /**
54 * The {@link Status#ERROR} result;
55 */
56 public static final CheckoutResult ERROR_RESULT = new CheckoutResult(
57 Status.ERROR, null);
58
59 /**
60 * The {@link Status#NOT_TRIED} result;
61 */
62 public static final CheckoutResult NOT_TRIED_RESULT = new CheckoutResult(
63 Status.NOT_TRIED, null);
64
65 /**
66 * The status
67 */
68 public enum Status {
69 /**
70 * The call() method has not yet been executed
71 */
72 NOT_TRIED,
73 /**
74 * Checkout completed normally
75 */
76 OK,
77 /**
78 * Checkout has not completed because of checkout conflicts
79 */
80 CONFLICTS,
81 /**
82 * Checkout has completed, but some files could not be deleted
83 */
84 NONDELETED,
85 /**
86 * An Exception occurred during checkout
87 */
88 ERROR;
89 }
90
91 private final Status myStatus;
92
93 private final List<String> conflictList;
94
95 private final List<String> undeletedList;
96
97 private final List<String> modifiedList;
98
99 private final List<String> removedList;
100
101 /**
102 * Create a new fail result. If status is {@link Status#CONFLICTS},
103 * <code>fileList</code> is a list of conflicting files, if status is
104 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
105 * files. All other values ignore <code>fileList</code>. To create a result
106 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
107 *
108 * @param status
109 * the failure status
110 * @param fileList
111 * the list of files to store, status has to be either
112 * {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
113 */
114 CheckoutResult(Status status, List<String> fileList) {
115 this(status, fileList, null, null);
116 }
117
118 /**
119 * Create a new fail result. If status is {@link Status#CONFLICTS},
120 * <code>fileList</code> is a list of conflicting files, if status is
121 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
122 * files. All other values ignore <code>fileList</code>. To create a result
123 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
124 *
125 * @param status
126 * the failure status
127 * @param fileList
128 * the list of files to store, status has to be either
129 * {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
130 * @param modified
131 * the modified files
132 * @param removed
133 * the removed files.
134 */
135 CheckoutResult(Status status, List<String> fileList, List<String> modified,
136 List<String> removed) {
137 myStatus = status;
138 if (status == Status.CONFLICTS)
139 this.conflictList = fileList;
140 else
141 this.conflictList = new ArrayList<>(0);
142 if (status == Status.NONDELETED)
143 this.undeletedList = fileList;
144 else
145 this.undeletedList = new ArrayList<>(0);
146
147 this.modifiedList = modified;
148 this.removedList = removed;
149 }
150
151 /**
152 * Create a new OK result with modified and removed files.
153 *
154 * @param modified
155 * the modified files
156 * @param removed
157 * the removed files.
158 */
159 CheckoutResult(List<String> modified, List<String> removed) {
160 myStatus = Status.OK;
161
162 this.conflictList = new ArrayList<>(0);
163 this.undeletedList = new ArrayList<>(0);
164
165 this.modifiedList = modified;
166 this.removedList = removed;
167 }
168
169 /**
170 * Get status
171 *
172 * @return the status
173 */
174 public Status getStatus() {
175 return myStatus;
176 }
177
178 /**
179 * Get list of file that created a checkout conflict
180 *
181 * @return the list of files that created a checkout conflict, or an empty
182 * list if {@link #getStatus()} is not
183 * {@link org.eclipse.jgit.api.CheckoutResult.Status#CONFLICTS};
184 */
185 public List<String> getConflictList() {
186 return conflictList;
187 }
188
189 /**
190 * Get the list of files that could not be deleted during checkout
191 *
192 * @return the list of files that could not be deleted during checkout, or
193 * an empty list if {@link #getStatus()} is not
194 * {@link org.eclipse.jgit.api.CheckoutResult.Status#NONDELETED};
195 */
196 public List<String> getUndeletedList() {
197 return undeletedList;
198 }
199
200 /**
201 * Get the list of files that where modified during checkout
202 *
203 * @return the list of files that where modified during checkout, or an
204 * empty list if {@link #getStatus()} is not
205 * {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
206 */
207 public List<String> getModifiedList() {
208 return modifiedList;
209 }
210
211 /**
212 * Get the list of files that where removed during checkout
213 *
214 * @return the list of files that where removed during checkout, or an empty
215 * list if {@link #getStatus()} is not
216 * {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
217 */
218 public List<String> getRemovedList() {
219 return removedList;
220 }
221 }