View Javadoc
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 		this(status, fileList, null, null);
117 	}
118 
119 	/**
120 	 * Create a new fail result. If status is {@link Status#CONFLICTS},
121 	 * <code>fileList</code> is a list of conflicting files, if status is
122 	 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
123 	 * files. All other values ignore <code>fileList</code>. To create a result
124 	 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
125 	 *
126 	 * @param status
127 	 *            the failure status
128 	 * @param fileList
129 	 *            the list of files to store, status has to be either
130 	 *            {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
131 	 * @param modified
132 	 *            the modified files
133 	 * @param removed
134 	 *            the removed files.
135 	 */
136 	CheckoutResult(Status status, List<String> fileList, List<String> modified,
137 			List<String> removed) {
138 		myStatus = status;
139 		if (status == Status.CONFLICTS)
140 			this.conflictList = fileList;
141 		else
142 			this.conflictList = new ArrayList<>(0);
143 		if (status == Status.NONDELETED)
144 			this.undeletedList = fileList;
145 		else
146 			this.undeletedList = new ArrayList<>(0);
147 
148 		this.modifiedList = modified;
149 		this.removedList = removed;
150 	}
151 
152 	/**
153 	 * Create a new OK result with modified and removed files.
154 	 *
155 	 * @param modified
156 	 *            the modified files
157 	 * @param removed
158 	 *            the removed files.
159 	 */
160 	CheckoutResult(List<String> modified, List<String> removed) {
161 		myStatus = Status.OK;
162 
163 		this.conflictList = new ArrayList<>(0);
164 		this.undeletedList = new ArrayList<>(0);
165 
166 		this.modifiedList = modified;
167 		this.removedList = removed;
168 	}
169 
170 	/**
171 	 * @return the status
172 	 */
173 	public Status getStatus() {
174 		return myStatus;
175 	}
176 
177 	/**
178 	 * @return the list of files that created a checkout conflict, or an empty
179 	 *         list if {@link #getStatus()} is not {@link Status#CONFLICTS};
180 	 */
181 	public List<String> getConflictList() {
182 		return conflictList;
183 	}
184 
185 	/**
186 	 * @return the list of files that could not be deleted during checkout, or
187 	 *         an empty list if {@link #getStatus()} is not
188 	 *         {@link Status#NONDELETED};
189 	 */
190 	public List<String> getUndeletedList() {
191 		return undeletedList;
192 	}
193 
194 	/**
195 	 * @return the list of files that where modified during checkout, or an
196 	 *         empty list if {@link #getStatus()} is not {@link Status#OK}
197 	 */
198 	public List<String> getModifiedList() {
199 		return modifiedList;
200 	}
201 
202 	/**
203 	 * @return the list of files that where removed during checkout, or an empty
204 	 *         list if {@link #getStatus()} is not {@link Status#OK}
205 	 */
206 	public List<String> getRemovedList() {
207 		return removedList;
208 	}
209 }