NotesMergeConflictException.java

  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. package org.eclipse.jgit.notes;

  11. import java.io.IOException;
  12. import java.text.MessageFormat;

  13. import org.eclipse.jgit.internal.JGitText;

  14. /**
  15.  * This exception will be thrown from the
  16.  * {@link org.eclipse.jgit.notes.NoteMerger} when a conflict on Notes content is
  17.  * found during merge.
  18.  */
  19. public class NotesMergeConflictException extends IOException {
  20.     private static final long serialVersionUID = 1L;

  21.     /**
  22.      * Construct a NotesMergeConflictException for the specified base, ours and
  23.      * theirs note versions.
  24.      *
  25.      * @param base
  26.      *            note version
  27.      * @param ours
  28.      *            note version
  29.      * @param theirs
  30.      *            note version
  31.      */
  32.     public NotesMergeConflictException(Note base, Note ours, Note theirs) {
  33.         super(MessageFormat.format(JGitText.get().mergeConflictOnNotes,
  34.                 noteOn(base, ours, theirs), noteData(base), noteData(ours),
  35.                 noteData(theirs)));
  36.     }

  37.     /**
  38.      * Constructs a NotesMergeConflictException for the specified base, ours and
  39.      * theirs versions of the root note tree.
  40.      *
  41.      * @param base
  42.      *            version of the root note tree
  43.      * @param ours
  44.      *            version of the root note tree
  45.      * @param theirs
  46.      *            version of the root note tree
  47.      */
  48.     public NotesMergeConflictException(NonNoteEntry base, NonNoteEntry ours,
  49.             NonNoteEntry theirs) {
  50.         super(MessageFormat.format(
  51.                 JGitText.get().mergeConflictOnNonNoteEntries, name(base),
  52.                 name(ours), name(theirs)));
  53.     }

  54.     private static String noteOn(Note base, Note ours, Note theirs) {
  55.         if (base != null)
  56.             return base.name();
  57.         if (ours != null)
  58.             return ours.name();
  59.         return theirs.name();
  60.     }

  61.     private static String noteData(Note n) {
  62.         if (n != null)
  63.             return n.getData().name();
  64.         return ""; //$NON-NLS-1$
  65.     }

  66.     private static String name(NonNoteEntry e) {
  67.         return e != null ? e.name() : ""; //$NON-NLS-1$
  68.     }
  69. }