UserDefinedDiffTool.java

  1. /*
  2.  * Copyright (C) 2018-2021, Andre Bossert <andre.bossert@siemens.com>
  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.internal.diffmergetool;

  11. /**
  12.  * The user-defined diff tool.
  13.  */
  14. public class UserDefinedDiffTool implements ExternalDiffTool {

  15.     private boolean available;

  16.     /**
  17.      * the diff tool name
  18.      */
  19.     private final String name;

  20.     /**
  21.      * the diff tool path
  22.      */
  23.     private String path;

  24.     /**
  25.      * the diff tool command
  26.      */
  27.     private final String cmd;

  28.     /**
  29.      * Creates the diff tool
  30.      *
  31.      * @param name
  32.      *            the name
  33.      * @param path
  34.      *            the path
  35.      * @param cmd
  36.      *            the command
  37.      */
  38.     public UserDefinedDiffTool(String name, String path, String cmd) {
  39.         this.name = name;
  40.         this.path = path;
  41.         this.cmd = cmd;
  42.     }

  43.     /**
  44.      * @return the diff tool name
  45.      */
  46.     @Override
  47.     public String getName() {
  48.         return name;
  49.     }

  50.     /**
  51.      * The path of the diff tool.
  52.      *
  53.      * <p>
  54.      * The path to a pre-defined external diff tool can be overridden by
  55.      * specifying {@code difftool.<tool>.path} in a configuration file.
  56.      * </p>
  57.      * <p>
  58.      * For a user defined diff tool (that does not override a pre-defined diff
  59.      * tool), the path is ignored when invoking the tool.
  60.      * </p>
  61.      *
  62.      * @return the diff tool path
  63.      *
  64.      * @see <a href=
  65.      *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
  66.      */
  67.     @Override
  68.     public String getPath() {
  69.         return path;
  70.     }

  71.     /**
  72.      * The command of the diff tool.
  73.      *
  74.      * <p>
  75.      * A pre-defined external diff tool can be overridden using the tools name
  76.      * in a configuration file. The overwritten tool is then a user defined tool
  77.      * and the command of the diff tool is specified with
  78.      * {@code difftool.<tool>.cmd}. This command must work without prepending
  79.      * the value of {@link #getPath()} and can sometimes include tool
  80.      * parameters.
  81.      * </p>
  82.      *
  83.      * @return the diff tool command
  84.      *
  85.      * @see <a href=
  86.      *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
  87.      */
  88.     @Override
  89.     public String getCommand() {
  90.         return cmd;
  91.     }

  92.     /**
  93.      * @return availability of the tool: true if tool can be executed and false
  94.      *         if not
  95.      */
  96.     @Override
  97.     public boolean isAvailable() {
  98.         return available;
  99.     }

  100.     /**
  101.      * @param available
  102.      *            true if tool can be found and false if not
  103.      */
  104.     public void setAvailable(boolean available) {
  105.         this.available = available;
  106.     }

  107.     /**
  108.      * Overrides the path for the given tool. Equivalent to setting
  109.      * {@code difftool.<tool>.path}.
  110.      *
  111.      * @param path
  112.      *            the new diff tool path
  113.      *
  114.      * @see <a href=
  115.      *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
  116.      */
  117.     public void setPath(String path) {
  118.         this.path = path;
  119.     }
  120. }