View Javadoc
1   /*
2    * Copyright (C) 2011, Philipp Thun <philipp.thun@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.List;
46  import java.util.Map;
47  
48  import org.eclipse.jgit.lib.Ref;
49  import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
50  import org.eclipse.jgit.revwalk.RevCommit;
51  
52  /**
53   * Encapsulates the result of a {@link org.eclipse.jgit.api.CherryPickCommand}.
54   */
55  public class CherryPickResult {
56  
57  	/**
58  	 * The cherry-pick status
59  	 */
60  	public enum CherryPickStatus {
61  		/** */
62  		OK {
63  			@Override
64  			public String toString() {
65  				return "Ok"; //$NON-NLS-1$
66  			}
67  		},
68  		/** */
69  		FAILED {
70  			@Override
71  			public String toString() {
72  				return "Failed"; //$NON-NLS-1$
73  			}
74  		},
75  		/** */
76  		CONFLICTING {
77  			@Override
78  			public String toString() {
79  				return "Conflicting"; //$NON-NLS-1$
80  			}
81  		}
82  	}
83  
84  	private final CherryPickStatus status;
85  
86  	private final RevCommit newHead;
87  
88  	private final List<Ref> cherryPickedRefs;
89  
90  	private final Map<String, MergeFailureReason> failingPaths;
91  
92  	/**
93  	 * Constructor for CherryPickResult
94  	 *
95  	 * @param newHead
96  	 *            commit the head points at after this cherry-pick
97  	 * @param cherryPickedRefs
98  	 *            list of successfully cherry-picked <code>Ref</code>'s
99  	 */
100 	public CherryPickResult(RevCommit newHead, List<Ref> cherryPickedRefs) {
101 		this.status = CherryPickStatus.OK;
102 		this.newHead = newHead;
103 		this.cherryPickedRefs = cherryPickedRefs;
104 		this.failingPaths = null;
105 	}
106 
107 	/**
108 	 * Constructor for CherryPickResult
109 	 *
110 	 * @param failingPaths
111 	 *            list of paths causing this cherry-pick to fail (see
112 	 *            {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
113 	 *            for details)
114 	 */
115 	public CherryPickResult(Map<String, MergeFailureReason> failingPaths) {
116 		this.status = CherryPickStatus.FAILED;
117 		this.newHead = null;
118 		this.cherryPickedRefs = null;
119 		this.failingPaths = failingPaths;
120 	}
121 
122 	private CherryPickResult(CherryPickStatus status) {
123 		this.status = status;
124 		this.newHead = null;
125 		this.cherryPickedRefs = null;
126 		this.failingPaths = null;
127 	}
128 
129 	/**
130 	 * A <code>CherryPickResult</code> with status
131 	 * {@link CherryPickStatus#CONFLICTING}
132 	 */
133 	public static final CherryPickResultml#CherryPickResult">CherryPickResult CONFLICT = new CherryPickResult(
134 			CherryPickStatus.CONFLICTING);
135 
136 	/**
137 	 * Get status
138 	 *
139 	 * @return the status this cherry-pick resulted in
140 	 */
141 	public CherryPickStatus getStatus() {
142 		return status;
143 	}
144 
145 	/**
146 	 * Get the new head after this cherry-pick
147 	 *
148 	 * @return the commit the head points at after this cherry-pick,
149 	 *         <code>null</code> if {@link #getStatus} is not
150 	 *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
151 	 */
152 	public RevCommit getNewHead() {
153 		return newHead;
154 	}
155 
156 	/**
157 	 * Get the cherry-picked {@code Ref}s
158 	 *
159 	 * @return the list of successfully cherry-picked <code>Ref</code>'s,
160 	 *         <code>null</code> if {@link #getStatus} is not
161 	 *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#OK}
162 	 */
163 	public List<Ref> getCherryPickedRefs() {
164 		return cherryPickedRefs;
165 	}
166 
167 	/**
168 	 * Get the list of paths causing this cherry-pick to fail
169 	 *
170 	 * @return the list of paths causing this cherry-pick to fail (see
171 	 *         {@link org.eclipse.jgit.merge.ResolveMerger#getFailingPaths()}
172 	 *         for details), <code>null</code> if {@link #getStatus} is not
173 	 *         {@link org.eclipse.jgit.api.CherryPickResult.CherryPickStatus#FAILED}
174 	 */
175 	public Map<String, MergeFailureReason> getFailingPaths() {
176 		return failingPaths;
177 	}
178 }