PreDefinedMergeTool.java

  1. /*
  2.  * Copyright (C) 2018-2022, 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. import org.eclipse.jgit.lib.internal.BooleanTriState;

  12. /**
  13.  * The pre-defined merge tool.
  14.  */
  15. public class PreDefinedMergeTool extends UserDefinedMergeTool {

  16.     /**
  17.      * the tool parameters without base
  18.      */
  19.     private final String parametersWithoutBase;

  20.     /**
  21.      * Creates the pre-defined merge tool
  22.      *
  23.      * @param name
  24.      *            the name
  25.      * @param path
  26.      *            the path
  27.      * @param parametersWithBase
  28.      *            the tool parameters that are used together with path as
  29.      *            command and "base is present" ($BASE)
  30.      * @param parametersWithoutBase
  31.      *            the tool parameters that are used together with path as
  32.      *            command and "base is present" ($BASE)
  33.      * @param trustExitCode
  34.      *            the "trust exit code" option
  35.      */
  36.     public PreDefinedMergeTool(String name, String path,
  37.             String parametersWithBase, String parametersWithoutBase,
  38.             BooleanTriState trustExitCode) {
  39.         super(name, path, parametersWithBase, trustExitCode);
  40.         this.parametersWithoutBase = parametersWithoutBase;
  41.     }

  42.     /**
  43.      * Creates the pre-defined merge tool
  44.      *
  45.      * @param tool
  46.      *            the command line merge tool
  47.      *
  48.      */
  49.     public PreDefinedMergeTool(CommandLineMergeTool tool) {
  50.         this(tool.name(), tool.getPath(), tool.getParameters(true),
  51.                 tool.getParameters(false),
  52.                 tool.isExitCodeTrustable() ? BooleanTriState.TRUE
  53.                         : BooleanTriState.FALSE);
  54.     }

  55.     /**
  56.      * @param trustExitCode
  57.      *            the "trust exit code" option
  58.      */
  59.     @Override
  60.     public void setTrustExitCode(BooleanTriState trustExitCode) {
  61.         super.setTrustExitCode(trustExitCode);
  62.     }

  63.     /**
  64.      * @return the tool command (with base present)
  65.      */
  66.     @Override
  67.     public String getCommand() {
  68.         return getCommand(true);
  69.     }

  70.     /**
  71.      * @param withBase
  72.      *            get command with base present (true) or without base present
  73.      *            (false)
  74.      * @return the tool command
  75.      */
  76.     @Override
  77.     public String getCommand(boolean withBase) {
  78.         return ExternalToolUtils.quotePath(getPath()) + " " //$NON-NLS-1$
  79.                 + (withBase ? super.getCommand() : parametersWithoutBase);
  80.     }

  81. }