blob: 86793ce7d1bd9e702da162eeacc01f0f6ba0c6fd (
plain) (
blame)
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
|
/**********************************************************************
* Copyright (c) 2012, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bernd Hufmann - Initial API and implementation
**********************************************************************/
package org.eclipse.tracecompass.internal.tmf.remote.core.shell;
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
import java.util.List;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
import com.google.common.collect.ImmutableList;
/**
* Class containing command result of remote command execution.
*
* @author Bernd Hufmann
*/
public class CommandResult implements ICommandResult {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
/** The result of the command. 0 if successful else > 0 */
private final int fResult;
/** The output as list of Strings. */
private final List<String> fOutput;
/** The error stream output as list of Strings. */
private final List<String> fErrorOutput;
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
/**
* Constructor
*
* @param result
* The result of the command
* @param output
* The output, as an array of strings
* @param errorOutput
* THe error output as an array of strings
*/
public CommandResult(int result, String[] output, String[] errorOutput) {
fResult = result;
fOutput = checkNotNull(ImmutableList.copyOf(output));
fErrorOutput = checkNotNull(ImmutableList.copyOf(errorOutput));
}
// ------------------------------------------------------------------------
// Accessors
// ------------------------------------------------------------------------
@Override
public int getResult() {
return fResult;
}
@Override
public String[] getOutput() {
return checkNotNull(fOutput.toArray(new String[fOutput.size()]));
}
@Override
public String[] getErrorOutput() {
return checkNotNull(fErrorOutput.toArray(new String[fErrorOutput.size()]));
}
@Override
public String toString() {
StringBuffer ret = new StringBuffer();
ret.append("Error Output:\n"); //$NON-NLS-1$
for (String string : fErrorOutput) {
ret.append(string).append("\n"); //$NON-NLS-1$
}
ret.append("Return Value: "); //$NON-NLS-1$
ret.append(fResult);
ret.append("\n"); //$NON-NLS-1$
for (String string : fOutput) {
ret.append(string).append("\n"); //$NON-NLS-1$
}
return nullToEmptyString(ret.toString());
}
}
|