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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/*
* 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;
import org.eclipse.jgit.util.FS.ExecutionResult;
import org.eclipse.jgit.util.SystemReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tool exception for differentiation.
*
*/
public class ToolException extends Exception {
private final static Logger LOG = LoggerFactory
.getLogger(ToolException.class);
private final ExecutionResult result;
private final boolean commandExecutionError;
/**
* the serial version UID
*/
private static final long serialVersionUID = 1L;
/**
* Create tool exception
*/
public ToolException() {
this(null, null, false);
}
/**
* Create tool exception
*
* @param message
* the exception message
*/
public ToolException(String message) {
this(message, null, false);
}
/**
* Create tool exception
*
* @param message
* the exception message
* @param result
* the execution result
* @param commandExecutionError
* is command execution error happened ?
*/
public ToolException(String message, ExecutionResult result,
boolean commandExecutionError) {
super(message);
this.result = result;
this.commandExecutionError = commandExecutionError;
}
/**
* Create tool exception
*
* @param message
* the exception message
* @param cause
* the cause for throw
*/
public ToolException(String message, Throwable cause) {
super(message, cause);
result = null;
commandExecutionError = false;
}
/**
* Create tool exception
*
* @param cause
* the cause for throw
*/
public ToolException(Throwable cause) {
super(cause);
result = null;
commandExecutionError = false;
}
/**
* Whether result is valid
*
* @return true if result is valid, false else
*/
public boolean isResult() {
return result != null;
}
/**
* Get execution result
*
* @return the execution result
*/
public ExecutionResult getResult() {
return result;
}
/**
* Whether execution failed with an error
*
* @return true if command execution error appears, false otherwise
*/
public boolean isCommandExecutionError() {
return commandExecutionError;
}
/**
* Get buffered stderr as a String
*
* @return the result Stderr
*/
public String getResultStderr() {
if (result == null) {
return ""; //$NON-NLS-1$
}
try {
return new String(result.getStderr().toByteArray(),
SystemReader.getInstance().getDefaultCharset());
} catch (Exception e) {
LOG.warn("Failed to retrieve standard error output", e); //$NON-NLS-1$
}
return ""; //$NON-NLS-1$
}
/**
* Get buffered stdout as a String
*
* @return the result Stdout
*/
public String getResultStdout() {
if (result == null) {
return ""; //$NON-NLS-1$
}
try {
return new String(result.getStdout().toByteArray(),
SystemReader.getInstance().getDefaultCharset());
} catch (Exception e) {
LOG.warn("Failed to retrieve standard output", e); //$NON-NLS-1$
}
return ""; //$NON-NLS-1$
}
}
|