View Javadoc
1   /*
2    * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@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  
11  package org.eclipse.jgit.notes;
12  
13  import java.io.IOException;
14  import java.text.MessageFormat;
15  
16  import org.eclipse.jgit.internal.JGitText;
17  
18  /**
19   * This exception will be thrown from the
20   * {@link org.eclipse.jgit.notes.NoteMerger} when a conflict on Notes content is
21   * found during merge.
22   */
23  public class NotesMergeConflictException extends IOException {
24  	private static final long serialVersionUID = 1L;
25  
26  	/**
27  	 * Construct a NotesMergeConflictException for the specified base, ours and
28  	 * theirs note versions.
29  	 *
30  	 * @param base
31  	 *            note version
32  	 * @param ours
33  	 *            note version
34  	 * @param theirs
35  	 *            note version
36  	 */
37  	public NotesMergeConflictException(Note base, Note ours, Note theirs) {
38  		super(MessageFormat.format(JGitText.get().mergeConflictOnNotes,
39  				noteOn(base, ours, theirs), noteData(base), noteData(ours),
40  				noteData(theirs)));
41  	}
42  
43  	/**
44  	 * Constructs a NotesMergeConflictException for the specified base, ours and
45  	 * theirs versions of the root note tree.
46  	 *
47  	 * @param base
48  	 *            version of the root note tree
49  	 * @param ours
50  	 *            version of the root note tree
51  	 * @param theirs
52  	 *            version of the root note tree
53  	 */
54  	public NotesMergeConflictException(NonNoteEntry base, NonNoteEntry ours,
55  			NonNoteEntry theirs) {
56  		super(MessageFormat.format(
57  				JGitText.get().mergeConflictOnNonNoteEntries, name(base),
58  				name(ours), name(theirs)));
59  	}
60  
61  	private static String noteOn(Note base, Note ours, Note theirs) {
62  		if (base != null)
63  			return base.name();
64  		if (ours != null)
65  			return ours.name();
66  		return theirs.name();
67  	}
68  
69  	private static String noteData(Note n) {
70  		if (n != null)
71  			return n.getData().name();
72  		return ""; //$NON-NLS-1$
73  	}
74  
75  	private static String name(NonNoteEntry e) {
76  		return e != null ? e.name() : ""; //$NON-NLS-1$
77  	}
78  }