CheckoutConflictException.java

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

  13. import java.io.IOException;
  14. import java.text.MessageFormat;

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

  16. /**
  17.  * Exception thrown if a conflict occurs during a merge checkout.
  18.  */
  19. public class CheckoutConflictException extends IOException {
  20.     private static final long serialVersionUID = 1L;

  21.     private final String[] conflicting;

  22.     /**
  23.      * Construct a CheckoutConflictException for the specified file
  24.      *
  25.      * @param file
  26.      *            relative path of a file
  27.      */
  28.     public CheckoutConflictException(String file) {
  29.         super(MessageFormat.format(JGitText.get().checkoutConflictWithFile, file));
  30.         conflicting = new String[] { file };
  31.     }

  32.     /**
  33.      * Construct a CheckoutConflictException for the specified set of files
  34.      *
  35.      * @param files
  36.      *            an array of relative file paths
  37.      */
  38.     public CheckoutConflictException(String[] files) {
  39.         super(MessageFormat.format(JGitText.get().checkoutConflictWithFiles, buildList(files)));
  40.         conflicting = files;
  41.     }

  42.     /**
  43.      * Get the relative paths of the conflicting files
  44.      *
  45.      * @return the relative paths of the conflicting files (relative to the
  46.      *         working directory root).
  47.      * @since 4.4
  48.      */
  49.     public String[] getConflictingFiles() {
  50.         return conflicting;
  51.     }

  52.     private static String buildList(String[] files) {
  53.         StringBuilder builder = new StringBuilder();
  54.         for (String f : files) {
  55.             builder.append("\n"); //$NON-NLS-1$
  56.             builder.append(f);
  57.         }
  58.         return builder.toString();
  59.     }
  60. }