valueOf
([C)Ljava/lang/String;
([C)L1java/lang/String;
+valueOf
+ ([CII)Ljava/lang/String;
+ ([CII)L1java/lang/String;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.tracecompass.internal.tmf.remote.core.stubs.shells.TestCommandShell;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
+import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandOutputListener;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
@SuppressWarnings("javadoc")
@Override
public synchronized ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor) throws ExecutionException {
+ return executeCommand(command, monitor, null);
+ }
+
+ @Override
+ public synchronized ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor, ICommandOutputListener listener) throws ExecutionException {
Map<String, ICommandResult> commands = checkNotNull(fScenarioMap.get(fScenario));
String commandLine = command.toString();
String fullCommand = commandLine;
import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandInput;
import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandResult;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
+import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandOutputListener;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
@Override
public ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor) throws ExecutionException {
+ return executeCommand(command, monitor, null);
+ }
+
+ @Override
+ public ICommandResult executeCommand(ICommandInput command, IProgressMonitor monitor, ICommandOutputListener listener) throws ExecutionException {
if (fIsConnected) {
return createCommandResult(0, new String[0], new String[0]);
}
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 2.0.0.qualifier
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tracecompass.tmf.remote.core;singleton:=true
Bundle-Activator: org.eclipse.tracecompass.internal.tmf.remote.core.Activator
</parent>
<artifactId>org.eclipse.tracecompass.tmf.remote.core</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>Trace Compass TMF Remote Core Plug-in</name>
import org.eclipse.tracecompass.internal.tmf.remote.core.messages.Messages;
import org.eclipse.tracecompass.internal.tmf.remote.core.preferences.TmfRemotePreferences;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
+import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandOutputListener;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
@Override
public ICommandResult executeCommand(final ICommandInput command, final IProgressMonitor aMonitor) throws ExecutionException {
+ return executeCommand(command, aMonitor, null);
+ }
+
+ @Override
+ public ICommandResult executeCommand(final ICommandInput command, final IProgressMonitor aMonitor, ICommandOutputListener listener) throws ExecutionException {
if (fConnection.isOpen()) {
FutureTask<CommandResult> future = new FutureTask<>(new Callable<CommandResult>() {
@Override
return new CommandResult(1, new @NonNull String[0], new @NonNull String[] { nullToEmptyString(Messages.RemoteConnection_ServiceNotDefined) });
}
IRemoteProcess process = service.getProcessBuilder(command.getInput()).start();
- InputReader stdout = new InputReader(checkNotNull(process.getInputStream()));
- InputReader stderr = new InputReader(checkNotNull(process.getErrorStream()));
+ InputReader stdout = new InputReader(checkNotNull(process.getInputStream()), listener, true);
+ InputReader stderr = new InputReader(checkNotNull(process.getErrorStream()), listener, false);
try {
stdout.waitFor(monitor);
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandOutputListener;
@NonNullByDefault
class InputReader {
private final StringBuilder fResult;
private volatile boolean fDone;
- public InputReader(InputStream inputStream) {
+ public InputReader(InputStream inputStream, @Nullable final ICommandOutputListener listener, final boolean isStdOut) {
fResult = new StringBuilder();
fReader = new InputStreamReader(inputStream);
fThread = new Thread() {
try {
while (!fDone && (read = fReader.read(buffer)) > 0) {
fResult.append(buffer, 0, read);
+ if (listener != null) {
+ if (isStdOut) {
+ listener.outputUpdated(String.valueOf(buffer, 0, read));
+ } else {
+ listener.errorOutputUpdated(String.valueOf(buffer, 0, read));
+ }
+ }
}
} catch (IOException e) {
}
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 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
+ **********************************************************************/
+package org.eclipse.tracecompass.tmf.remote.core.shell;
+
+/**
+ * Interface for a providing a command output listener
+ *
+ * @author Bernd Hufmann
+ * @since 2.0
+ */
+public interface ICommandOutputListener {
+
+ /**
+ * Call back with new output String. It will provide the delta String
+ * in comparison to the previous call of this method.
+ *
+ * The implementer of this method must not block the current thread.
+ *
+ * @param updatedString
+ * The new outputString
+ */
+ void outputUpdated(String updatedString);
+
+ /**
+ * Call back with new error output String. It will provide the delta String
+ * in comparison to the previous call of this method.
+ *
+ * The implementer of this method must not block the current thread.
+ *
+ * @param updatedString
+ * The new outputString
+ */
+ void errorOutputUpdated(String updatedString);
+}
*/
ICommandResult executeCommand(ICommandInput command, @Nullable IProgressMonitor monitor) throws ExecutionException;
+ /**
+ * Method to execute a command on the command shell.
+ *
+ * @param command
+ * The command to executed
+ * @param monitor
+ * A progress monitor
+ * @param listener
+ * A command output listener (can be null if not used)
+ * @return a {@link ICommandResult} instance
+ * @throws ExecutionException
+ * If the command fails
+ * @since 2.0
+ */
+ ICommandResult executeCommand(ICommandInput command, @Nullable IProgressMonitor monitor, @Nullable ICommandOutputListener listener) throws ExecutionException;
+
/**
* Creates a command input instance
*