View Javadoc
1   /*
2    * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3    * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
4    * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org> and others
5    *
6    * This program and the accompanying materials are made available under the
7    * terms of the Eclipse Distribution License v. 1.0 which is available at
8    * https://www.eclipse.org/org/documents/edl-v10.php.
9    *
10   * SPDX-License-Identifier: BSD-3-Clause
11   */
12  
13  package org.eclipse.jgit.errors;
14  
15  import java.io.IOException;
16  import java.text.MessageFormat;
17  
18  import org.eclipse.jgit.internal.JGitText;
19  
20  /**
21   * Exception thrown if a conflict occurs during a merge checkout.
22   */
23  public class CheckoutConflictException extends IOException {
24  	private static final long serialVersionUID = 1L;
25  
26  	private final String[] conflicting;
27  
28  	/**
29  	 * Construct a CheckoutConflictException for the specified file
30  	 *
31  	 * @param file
32  	 *            relative path of a file
33  	 */
34  	public CheckoutConflictException(String file) {
35  		super(MessageFormat.format(JGitText.get().checkoutConflictWithFile, file));
36  		conflicting = new String[] { file };
37  	}
38  
39  	/**
40  	 * Construct a CheckoutConflictException for the specified set of files
41  	 *
42  	 * @param files
43  	 *            an array of relative file paths
44  	 */
45  	public CheckoutConflictException(String[] files) {
46  		super(MessageFormat.format(JGitText.get().checkoutConflictWithFiles, buildList(files)));
47  		conflicting = files;
48  	}
49  
50  	/**
51  	 * Get the relative paths of the conflicting files
52  	 *
53  	 * @return the relative paths of the conflicting files (relative to the
54  	 *         working directory root).
55  	 * @since 4.4
56  	 */
57  	public String[] getConflictingFiles() {
58  		return conflicting;
59  	}
60  
61  	private static String buildList(String[] files) {
62  		StringBuilder builder = new StringBuilder();
63  		for (String f : files) {
64  			builder.append("\n"); //$NON-NLS-1$
65  			builder.append(f);
66  		}
67  		return builder.toString();
68  	}
69  }