1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
12 **********************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.stubs
.shells
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Arrays
;
20 import java
.util
.List
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
24 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
26 import org
.eclipse
.jdt
.annotation
.Nullable
;
27 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandInput
;
28 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandResult
;
29 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
34 public class TestCommandShell
implements ICommandShell
{
36 /** If the shell is connected */
37 protected boolean fIsConnected
= false;
40 public void dispose() {
45 public ICommandResult
executeCommand(ICommandInput command
, IProgressMonitor monitor
) throws ExecutionException
{
47 return new CommandResultStub(0, new String
[0], new String
[0]);
49 return new CommandResultStub(1, new String
[0], new String
[0]);
53 public ICommandInput
createCommand() {
54 return new CommandInputStub();
61 protected class CommandResultStub
implements ICommandResult
{
63 private final int fResult
;
64 private final List
<String
> fOutput
;
65 private final List
<String
> fErrorOutput
;
70 * The result of the command
72 * The output, as an array of strings
74 * THe error output as an array of strings
76 public CommandResultStub(int result
, String
[] output
, String
[] errorOutput
) {
78 fOutput
= checkNotNull(Arrays
.asList(output
));
79 fErrorOutput
= checkNotNull(Arrays
.asList(errorOutput
));
83 public int getResult() {
88 public List
<String
> getOutput() {
93 public List
<String
> getErrorOutput() {
98 public String
toString() {
99 StringBuffer ret
= new StringBuffer();
100 ret
.append("Error Output:\n"); //$NON-NLS-1$
101 for (String string
: fErrorOutput
) {
102 ret
.append(string
).append("\n"); //$NON-NLS-1$
104 ret
.append("Return Value: "); //$NON-NLS-1$
106 ret
.append("\n"); //$NON-NLS-1$
107 for (String string
: fOutput
) {
108 ret
.append(string
).append("\n"); //$NON-NLS-1$
110 return nullToEmptyString(ret
.toString());
117 public class CommandInputStub
implements ICommandInput
{
118 private final List
<String
> fInput
= new ArrayList
<>();
121 @NonNull public List
<String
> getInput() {
122 return checkNotNull(fInput
);
126 public void add(@Nullable String segment
) {
127 if (segment
!= null) {
133 public void addAll(@Nullable List
<String
> segments
) {
134 if (segments
!= null) {
135 fInput
.addAll(segments
);
140 public String
toString() {
141 StringBuilder builder
= new StringBuilder();
142 for (String segment
: fInput
) {
143 builder
.append(segment
).append(' ');
145 return nullToEmptyString(builder
.toString().trim());
This page took 0.038408 seconds and 5 git commands to generate.