View Javadoc
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  
11  package org.eclipse.jgit.internal.diffmergetool;
12  
13  import org.eclipse.jgit.lib.internal.BooleanTriState;
14  
15  /**
16   * The pre-defined merge tool.
17   */
18  public class PreDefinedMergeTool extends UserDefinedMergeTool {
19  
20  	/**
21  	 * the tool parameters without base
22  	 */
23  	private final String parametersWithoutBase;
24  
25  	/**
26  	 * Creates the pre-defined merge tool
27  	 *
28  	 * @param name
29  	 *            the name
30  	 * @param path
31  	 *            the path
32  	 * @param parametersWithBase
33  	 *            the tool parameters that are used together with path as
34  	 *            command and "base is present" ($BASE)
35  	 * @param parametersWithoutBase
36  	 *            the tool parameters that are used together with path as
37  	 *            command and "base is present" ($BASE)
38  	 * @param trustExitCode
39  	 *            the "trust exit code" option
40  	 */
41  	public PreDefinedMergeTool(String name, String path,
42  			String parametersWithBase, String parametersWithoutBase,
43  			BooleanTriState trustExitCode) {
44  		super(name, path, parametersWithBase, trustExitCode);
45  		this.parametersWithoutBase = parametersWithoutBase;
46  	}
47  
48  	/**
49  	 * Creates the pre-defined merge tool
50  	 *
51  	 * @param tool
52  	 *            the command line merge tool
53  	 *
54  	 */
55  	public PreDefinedMergeTool(CommandLineMergeTool tool) {
56  		this(tool.name(), tool.getPath(), tool.getParameters(true),
57  				tool.getParameters(false),
58  				tool.isExitCodeTrustable() ? BooleanTriState.TRUE
59  						: BooleanTriState.FALSE);
60  	}
61  
62  	/**
63  	 * @param trustExitCode
64  	 *            the "trust exit code" option
65  	 */
66  	@Override
67  	public void setTrustExitCode(BooleanTriState trustExitCode) {
68  		super.setTrustExitCode(trustExitCode);
69  	}
70  
71  	/**
72  	 * @return the tool command (with base present)
73  	 */
74  	@Override
75  	public String getCommand() {
76  		return getCommand(true);
77  	}
78  
79  	/**
80  	 * @param withBase
81  	 *            get command with base present (true) or without base present
82  	 *            (false)
83  	 * @return the tool command
84  	 */
85  	@Override
86  	public String getCommand(boolean withBase) {
87  		return ExternalToolUtils.quotePath(getPath()) + " " //$NON-NLS-1$
88  				+ (withBase ? super.getCommand() : parametersWithoutBase);
89  	}
90  
91  }