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