use of org.eclipse.remote.core.exception.RemoteConnectionException 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;
}
use of org.eclipse.remote.core.exception.RemoteConnectionException 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