CheckoutResult.java

  1. /*
  2.  * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@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.api;

  11. import java.util.ArrayList;
  12. import java.util.List;

  13. /**
  14.  * Encapsulates the result of a {@link org.eclipse.jgit.api.CheckoutCommand}
  15.  */
  16. public class CheckoutResult {

  17.     /**
  18.      * The {@link Status#ERROR} result;
  19.      */
  20.     public static final CheckoutResult ERROR_RESULT = new CheckoutResult(
  21.             Status.ERROR, null);

  22.     /**
  23.      * The {@link Status#NOT_TRIED} result;
  24.      */
  25.     public static final CheckoutResult NOT_TRIED_RESULT = new CheckoutResult(
  26.             Status.NOT_TRIED, null);

  27.     /**
  28.      * The status
  29.      */
  30.     public enum Status {
  31.         /**
  32.          * The call() method has not yet been executed
  33.          */
  34.         NOT_TRIED,
  35.         /**
  36.          * Checkout completed normally
  37.          */
  38.         OK,
  39.         /**
  40.          * Checkout has not completed because of checkout conflicts
  41.          */
  42.         CONFLICTS,
  43.         /**
  44.          * Checkout has completed, but some files could not be deleted
  45.          */
  46.         NONDELETED,
  47.         /**
  48.          * An Exception occurred during checkout
  49.          */
  50.         ERROR;
  51.     }

  52.     private final Status myStatus;

  53.     private final List<String> conflictList;

  54.     private final List<String> undeletedList;

  55.     private final List<String> modifiedList;

  56.     private final List<String> removedList;

  57.     /**
  58.      * Create a new fail result. If status is {@link Status#CONFLICTS},
  59.      * <code>fileList</code> is a list of conflicting files, if status is
  60.      * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
  61.      * files. All other values ignore <code>fileList</code>. To create a result
  62.      * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
  63.      *
  64.      * @param status
  65.      *            the failure status
  66.      * @param fileList
  67.      *            the list of files to store, status has to be either
  68.      *            {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
  69.      */
  70.     CheckoutResult(Status status, List<String> fileList) {
  71.         this(status, fileList, null, null);
  72.     }

  73.     /**
  74.      * Create a new fail result. If status is {@link Status#CONFLICTS},
  75.      * <code>fileList</code> is a list of conflicting files, if status is
  76.      * {@link Status#NONDELETED}, <code>fileList</code> is a list of not deleted
  77.      * files. All other values ignore <code>fileList</code>. To create a result
  78.      * for {@link Status#OK}, see {@link #CheckoutResult(List, List)}.
  79.      *
  80.      * @param status
  81.      *            the failure status
  82.      * @param fileList
  83.      *            the list of files to store, status has to be either
  84.      *            {@link Status#CONFLICTS} or {@link Status#NONDELETED}.
  85.      * @param modified
  86.      *            the modified files
  87.      * @param removed
  88.      *            the removed files.
  89.      */
  90.     CheckoutResult(Status status, List<String> fileList, List<String> modified,
  91.             List<String> removed) {
  92.         myStatus = status;
  93.         if (status == Status.CONFLICTS)
  94.             this.conflictList = fileList;
  95.         else
  96.             this.conflictList = new ArrayList<>(0);
  97.         if (status == Status.NONDELETED)
  98.             this.undeletedList = fileList;
  99.         else
  100.             this.undeletedList = new ArrayList<>(0);

  101.         this.modifiedList = modified;
  102.         this.removedList = removed;
  103.     }

  104.     /**
  105.      * Create a new OK result with modified and removed files.
  106.      *
  107.      * @param modified
  108.      *            the modified files
  109.      * @param removed
  110.      *            the removed files.
  111.      */
  112.     CheckoutResult(List<String> modified, List<String> removed) {
  113.         myStatus = Status.OK;

  114.         this.conflictList = new ArrayList<>(0);
  115.         this.undeletedList = new ArrayList<>(0);

  116.         this.modifiedList = modified;
  117.         this.removedList = removed;
  118.     }

  119.     /**
  120.      * Get status
  121.      *
  122.      * @return the status
  123.      */
  124.     public Status getStatus() {
  125.         return myStatus;
  126.     }

  127.     /**
  128.      * Get list of file that created a checkout conflict
  129.      *
  130.      * @return the list of files that created a checkout conflict, or an empty
  131.      *         list if {@link #getStatus()} is not
  132.      *         {@link org.eclipse.jgit.api.CheckoutResult.Status#CONFLICTS};
  133.      */
  134.     public List<String> getConflictList() {
  135.         return conflictList;
  136.     }

  137.     /**
  138.      * Get the list of files that could not be deleted during checkout
  139.      *
  140.      * @return the list of files that could not be deleted during checkout, or
  141.      *         an empty list if {@link #getStatus()} is not
  142.      *         {@link org.eclipse.jgit.api.CheckoutResult.Status#NONDELETED};
  143.      */
  144.     public List<String> getUndeletedList() {
  145.         return undeletedList;
  146.     }

  147.     /**
  148.      * Get the list of files that where modified during checkout
  149.      *
  150.      * @return the list of files that where modified during checkout, or an
  151.      *         empty list if {@link #getStatus()} is not
  152.      *         {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
  153.      */
  154.     public List<String> getModifiedList() {
  155.         return modifiedList;
  156.     }

  157.     /**
  158.      * Get the list of files that where removed during checkout
  159.      *
  160.      * @return the list of files that where removed during checkout, or an empty
  161.      *         list if {@link #getStatus()} is not
  162.      *         {@link org.eclipse.jgit.api.CheckoutResult.Status#OK}
  163.      */
  164.     public List<String> getRemovedList() {
  165.         return removedList;
  166.     }
  167. }