use of org.eclipse.remote.core.RemoteProcessAdapter in project linuxtools by eclipse.
the class RDTCommandLauncher method execute.
@Override
public Process execute(IPath commandPath, String[] args, String[] env, IPath changeToDirectory, IProgressMonitor monitor, PTY pty) {
try {
// add platform specific arguments (shell invocation)
fCommandArgs = constructCommandArray(commandPath.toOSString(), args);
fShowCommand = true;
IRemoteConnection connection = RDTProxyManager.getConnection(uri);
if (connection == null) {
fErrorMessage = Messages.RDTCommandLauncher_connection_not_found;
return null;
} else if (!connection.isOpen()) {
try {
connection.open(monitor);
} catch (RemoteConnectionException e) {
fErrorMessage = e.getMessage();
return null;
}
}
IRemoteProcessService ps = connection.getService(IRemoteProcessService.class);
IRemoteProcessBuilder builder = ps.getProcessBuilder(Arrays.asList(fCommandArgs));
if (changeToDirectory != null) {
IRemoteFileService fm = connection.getService(IRemoteFileService.class);
builder.directory(fm.getResource(changeToDirectory.toString()));
}
Map<String, String> envMap = builder.environment();
for (int i = 0; i < env.length; ++i) {
String s = env[i];
// $NON-NLS-1$
String[] tokens = s.split("=", 2);
switch(tokens.length) {
case 1:
envMap.put(tokens[0], null);
break;
case 2:
envMap.put(tokens[0], tokens[1]);
break;
default:
Activator.log(IStatus.WARNING, Messages.RDTCommandLauncher_malformed_env_var_string + s);
}
}
fProcess = builder.start();
// $NON-NLS-1$
fErrorMessage = "";
} catch (IOException e) {
fErrorMessage = e.getMessage();
return null;
}
return new RemoteProcessAdapter(fProcess);
}
Aggregations