Search in sources :

Example 1 with RemoteProcessAdapter

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);
}
Also used : IRemoteProcessService(org.eclipse.remote.core.IRemoteProcessService) RemoteConnectionException(org.eclipse.remote.core.exception.RemoteConnectionException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) RemoteProcessAdapter(org.eclipse.remote.core.RemoteProcessAdapter) IOException(java.io.IOException) IRemoteProcessBuilder(org.eclipse.remote.core.IRemoteProcessBuilder) IRemoteFileService(org.eclipse.remote.core.IRemoteFileService)

Aggregations

IOException (java.io.IOException)1 IRemoteConnection (org.eclipse.remote.core.IRemoteConnection)1 IRemoteFileService (org.eclipse.remote.core.IRemoteFileService)1 IRemoteProcessBuilder (org.eclipse.remote.core.IRemoteProcessBuilder)1 IRemoteProcessService (org.eclipse.remote.core.IRemoteProcessService)1 RemoteProcessAdapter (org.eclipse.remote.core.RemoteProcessAdapter)1 RemoteConnectionException (org.eclipse.remote.core.exception.RemoteConnectionException)1