View Javadoc
1   /*
2    * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com> and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  package org.eclipse.jgit.api;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Encapsulates the result of a {@link org.eclipse.jgit.api.CheckoutCommand}
17   */
18  public class CheckoutResult {
19  
20  	/**
21  	 * The {@link Status#ERROR} result;
22  	 */
23  	public static final CheckoutResult ERROR_RESULT = new CheckoutResult(
24  			Status.ERROR, null);
25  
26  	/**
27  	 * The {@link Status#NOT_TRIED} result;
28  	 */
29  	public static final CheckoutResult NOT_TRIED_RESULT = new CheckoutResult(
30  			Status.NOT_TRIED, null);
31  
32  	/**
33  	 * The status
34  	 */
35  	public enum Status {
36  		/**
37  		 * The call() method has not yet been executed
38  		 */
39  		NOT_TRIED,
40  		/**
41  		 * Checkout completed normally
42  		 */
43  		OK,
44  		/**
45  		 * Checkout has not completed because of checkout conflicts
46  		 */
47  		CONFLICTS,
48  		/**
49  		 * Checkout has completed, but some files could not be deleted
50  		 */
51  		NONDELETED,
52  		/**
53  		 * An Exception occurred during checkout
54  		 */
55  		ERROR;
56  	}
57  
58  	private final Status myStatus;
59  
60  	private final List<String> conflictList;
61  
62  	private final List<String> undeletedList;
63  
64  	private final List<String> modifiedList;
65  
66  	private final List<String> removedList;
67  
68  	/**
69  	 * Create a new fail result. If status is {@link Status#CONFLICTS},
70  	 * <code>fileList</code> is a list of conflicting files, if status is
71  	 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
72  	 * files. All other values ignore <code>fileList</code>. To create a result
73  	 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
74  	 *
75  	 * @param status
76  	 *            the failure status
77  	 * @param fileList
78  	 *            the list of files to store, status has to be either
79  	 *            {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
80  	 */
81  	CheckoutResult(Status status, List<String> fileList) {
82  		this(status, fileList, null, null);
83  	}
84  
85  	/**
86  	 * Create a new fail result. If status is {@link Status#CONFLICTS},
87  	 * <code>fileList</code> is a list of conflicting files, if status is
88  	 * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
89  	 * files. All other values ignore <code>fileList</code>. To create a result
90  	 * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
91  	 *
92  	 * @param status
93  	 *            the failure status
94  	 * @param fileList
95  	 *            the list of files to store, status has to be either
96  	 *            {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
97  	 * @param modified
98  	 *            the modified files
99  	 * @param removed
100 	 *            the removed files.
101 	 */
102 	CheckoutResult(Status status, List<String> fileList, List<String> modified,
103 			List<String> removed) {
104 		myStatus = status;
105 		if (status == Status.CONFLICTS)
106 			this.conflictList = fileList;
107 		else
108 			this.conflictList = new ArrayList<>(0);
109 		if (status == Status.NONDELETED)
110 			this.undeletedList = fileList;
111 		else
112 			this.undeletedList = new ArrayList<>(0);
113 
114 		this.modifiedList = modified;
115 		this.removedList = removed;
116 	}
117 
118 	/**
119 	 * Create a new OK result with modified and removed files.
120 	 *
121 	 * @param modified
122 	 *            the modified files
123 	 * @param removed
124 	 *            the removed files.
125 	 */
126 	CheckoutResult(List<String> modified, List<String> removed) {
127 		myStatus = Status.OK;
128 
129 		this.conflictList = new ArrayList<>(0);
130 		this.undeletedList = new ArrayList<>(0);
131 
132 		this.modifiedList = modified;
133 		this.removedList = removed;
134 	}
135 
136 	/**
137 	 * Get status
138 	 *
139 	 * @return the status
140 	 */
141 	public Status getStatus() {
142 		return myStatus;
143 	}
144 
145 	/**
146 	 * Get list of file that created a checkout conflict
147 	 *
148 	 * @return the list of files that created a checkout conflict, or an empty
149 	 *         list if {@link #getStatus()} is not
150 	 *         {@link org.eclipse.jgit.api.CheckoutResult.Status#CONFLICTS};
151 	 */
152 	public List<String> getConflictList() {
153 		return conflictList;
154 	}
155 
156 	/**
157 	 * Get the list of files that could not be deleted during checkout
158 	 *
159 	 * @return the list of files that could not be deleted during checkout, or
160 	 *         an empty list if {@link #getStatus()} is not
161 	 *         {@link org.eclipse.jgit.api.CheckoutResult.Status#NONDELETED};
162 	 */
163 	public List<String> getUndeletedList() {
164 		return undeletedList;
165 	}
166 
167 	/**
168 	 * Get the list of files that where modified during checkout
169 	 *
170 	 * @return the list of files that where modified during checkout, or an
171 	 *         empty list if {@link #getStatus()} is not
172 	 *         {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
173 	 */
174 	public List<String> getModifiedList() {
175 		return modifiedList;
176 	}
177 
178 	/**
179 	 * Get the list of files that where removed during checkout
180 	 *
181 	 * @return the list of files that where removed during checkout, or an empty
182 	 *         list if {@link #getStatus()} is not
183 	 *         {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
184 	 */
185 	public List<String> getRemovedList() {
186 		return removedList;
187 	}
188 }