Search in sources :

Example 1 with IRemoteProcessService

use of org.eclipse.remote.core.IRemoteProcessService in project linuxtools by eclipse.

the class RDTProxyManager method getEnv.

@Override
public Map<String, String> getEnv(URI uri) {
    IRemoteConnection connection = getConnection(uri);
    if (!connection.isOpen()) {
        try {
            connection.open(null);
        } catch (RemoteConnectionException e) {
            Status status = new Status(IStatus.ERROR, e.getMessage(), Activator.PLUGIN_ID);
            Activator.getDefault().getLog().log(status);
            return Collections.emptyMap();
        }
    }
    /*
         * It is common to export functions declaration in the environment so
         * this pattern filters out them because they get truncated and might
         * end up on failure. When a function is exported it makes a mess in ENV
         * and none of LT plugins working remotely because they are not find on
         * path.
         *
         * Patterns added in the env list:
         * var=value
         * i.e: SHELL=/bin/bash
         *
         * Patterns not added in the env list:
         * var=() { foo
         * i.e: BASH_FUNC_module()=() { eval `/usr/bin/modulecmd bash $*`, }
         */
    // $NON-NLS-1$
    Pattern variablePattern = Pattern.compile("^(.+)=([^\\(\\)\\s{].*|)$");
    Matcher m;
    Map<String, String> envMap = new HashMap<>();
    IRemoteProcessService ps = connection.getService(IRemoteProcessService.class);
    Map<String, String> envTemp = ps.getEnv();
    for (Map.Entry<String, String> entry : envTemp.entrySet()) {
        String env = entry.getKey() + '=' + entry.getValue();
        m = variablePattern.matcher(env);
        if (m.matches()) {
            envMap.put(entry.getKey(), entry.getValue());
        }
    }
    return envMap;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IRemoteProcessService(org.eclipse.remote.core.IRemoteProcessService) Pattern(java.util.regex.Pattern) RemoteConnectionException(org.eclipse.remote.core.exception.RemoteConnectionException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IRemoteProcessService

use of org.eclipse.remote.core.IRemoteProcessService 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

IRemoteConnection (org.eclipse.remote.core.IRemoteConnection)2 IRemoteProcessService (org.eclipse.remote.core.IRemoteProcessService)2 RemoteConnectionException (org.eclipse.remote.core.exception.RemoteConnectionException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IRemoteFileService (org.eclipse.remote.core.IRemoteFileService)1 IRemoteProcessBuilder (org.eclipse.remote.core.IRemoteProcessBuilder)1 RemoteProcessAdapter (org.eclipse.remote.core.RemoteProcessAdapter)1