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
11 package org.eclipse.jgit.internal.diffmergetool;
12
13 /**
14 * The user-defined diff tool.
15 */
16 public class UserDefinedDiffTool implements ExternalDiffTool {
17
18 /**
19 * the diff tool name
20 */
21 private final String name;
22
23 /**
24 * the diff tool path
25 */
26 private String path;
27
28 /**
29 * the diff tool command
30 */
31 private final String cmd;
32
33 /**
34 * Creates the diff tool
35 *
36 * @param name
37 * the name
38 * @param path
39 * the path
40 * @param cmd
41 * the command
42 */
43 public UserDefinedDiffTool(String name, String path, String cmd) {
44 this.name = name;
45 this.path = path;
46 this.cmd = cmd;
47 }
48
49 /**
50 * @return the diff tool name
51 */
52 @Override
53 public String getName() {
54 return name;
55 }
56
57 /**
58 * The path of the diff tool.
59 *
60 * <p>
61 * The path to a pre-defined external diff tool can be overridden by
62 * specifying {@code difftool.<tool>.path} in a configuration file.
63 * </p>
64 * <p>
65 * For a user defined diff tool (that does not override a pre-defined diff
66 * tool), the path is ignored when invoking the tool.
67 * </p>
68 *
69 * @return the diff tool path
70 *
71 * @see <a href=
72 * "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
73 */
74 @Override
75 public String getPath() {
76 return path;
77 }
78
79 /**
80 * The command of the diff tool.
81 *
82 * <p>
83 * A pre-defined external diff tool can be overridden using the tools name
84 * in a configuration file. The overwritten tool is then a user defined tool
85 * and the command of the diff tool is specified with
86 * {@code difftool.<tool>.cmd}. This command must work without prepending
87 * the value of {@link #getPath()} and can sometimes include tool
88 * parameters.
89 * </p>
90 *
91 * @return the diff tool command
92 *
93 * @see <a href=
94 * "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
95 */
96 @Override
97 public String getCommand() {
98 return cmd;
99 }
100
101 /**
102 * Overrides the path for the given tool. Equivalent to setting
103 * {@code difftool.<tool>.path}.
104 *
105 * @param path
106 * the new diff tool path
107 *
108 * @see <a href=
109 * "https://git-scm.com/docs/git-difftool">https://git-scm.com/docs/git-difftool</a>
110 */
111 public void setPath(String path) {
112 this.path = path;
113 }
114 }