aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/internal/diffmergetool/UserDefinedDiffTool.java
blob: 62bde28feb20f3442260887f89e359207e68ebec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * Copyright (C) 2018-2021, Andre Bossert <andre.bossert@siemens.com>
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.internal.diffmergetool;

/**
 * The user-defined diff tool.
 */
public class UserDefinedDiffTool implements ExternalDiffTool {

	private boolean available;

	/**
	 * the diff tool name
	 */
	private final String name;

	/**
	 * the diff tool path
	 */
	private String path;

	/**
	 * the diff tool command
	 */
	private final String cmd;

	/**
	 * Creates the diff tool
	 *
	 * @param name
	 *            the name
	 * @param path
	 *            the path
	 * @param cmd
	 *            the command
	 */
	public UserDefinedDiffTool(String name, String path, String cmd) {
		this.name = name;
		this.path = path;
		this.cmd = cmd;
	}

	/**
	 * @return the diff tool name
	 */
	@Override
	public String getName() {
		return name;
	}

	/**
	 * The path of the diff tool.
	 *
	 * <p>
	 * The path to a pre-defined external diff tool can be overridden by
	 * specifying {@code difftool.<tool>.path} in a configuration file.
	 * </p>
	 * <p>
	 * For a user defined diff tool (that does not override a pre-defined diff
	 * tool), the path is ignored when invoking the tool.
	 * </p>
	 *
	 * @return the diff tool path
	 *
	 * @see <a href=
	 *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
	 */
	@Override
	public String getPath() {
		return path;
	}

	/**
	 * The command of the diff tool.
	 *
	 * <p>
	 * A pre-defined external diff tool can be overridden using the tools name
	 * in a configuration file. The overwritten tool is then a user defined tool
	 * and the command of the diff tool is specified with
	 * {@code difftool.<tool>.cmd}. This command must work without prepending
	 * the value of {@link #getPath()} and can sometimes include tool
	 * parameters.
	 * </p>
	 *
	 * @return the diff tool command
	 *
	 * @see <a href=
	 *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
	 */
	@Override
	public String getCommand() {
		return cmd;
	}

	/**
	 * @return availability of the tool: true if tool can be executed and false
	 *         if not
	 */
	@Override
	public boolean isAvailable() {
		return available;
	}

	/**
	 * Set whether tool is available
	 *
	 * @param available
	 *            true if tool can be found and false if not
	 */
	public void setAvailable(boolean available) {
		this.available = available;
	}

	/**
	 * Overrides the path for the given tool. Equivalent to setting
	 * {@code difftool.<tool>.path}.
	 *
	 * @param path
	 *            the new diff tool path
	 *
	 * @see <a href=
	 *      "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
	 */
	public void setPath(String path) {
		this.path = path;
	}
}