use of org.eclipse.remote.core.IRemoteConnection in project linuxtools by eclipse.
the class AbstractRemoteTest method createJSchConnection.
/**
* Create a new connection. Save the connection working copy before return.
*
* @param connName Connection Name
* @param connTypeId The connection type identifier
* @return The created remote connection
* @throws RemoteConnectionException
*/
protected static IRemoteConnection createJSchConnection(String connName, String connTypeId) throws RemoteConnectionException {
checkConnectionInfo();
IRemoteServicesManager manager = getServicesManager();
IRemoteConnectionType ct = manager.getConnectionType(connTypeId);
assertNotNull(ct);
IRemoteConnectionWorkingCopy wc = ct.newConnection(connName);
wc.setAttribute(JSchConnection.ADDRESS_ATTR, HOST);
wc.setAttribute(JSchConnection.USERNAME_ATTR, USERNAME);
wc.setSecureAttribute(JSchConnection.PASSWORD_ATTR, PASSWORD);
IRemoteConnection conn = wc.save();
assertNotNull(conn);
conn.open(new NullProgressMonitor());
assertTrue(conn.isOpen());
return conn;
}
use of org.eclipse.remote.core.IRemoteConnection in project linuxtools by eclipse.
the class CommandLauncherProxyTest method testRemoteCommandLauncher.
@Test
public void testRemoteCommandLauncher() {
IRemoteCommandLauncher cl = null;
Process p = null;
IPath commandPath, changeToDirectory;
String[] args, env;
try {
cl = proxyManager.getLauncher(syncProject.getProject());
assertTrue("Should have returned a remote launcher", cl instanceof RDTCommandLauncher);
} catch (CoreException e) {
fail("Should have returned a launcher: " + e.getCause());
}
commandPath = new Path("uptime");
args = new String[] { "-s" };
env = new String[] { "PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" };
changeToDirectory = new Path("/tmp");
try {
p = cl.execute(commandPath, args, env, changeToDirectory, new NullProgressMonitor());
assertNotNull(p);
p.waitFor();
assertEquals("Process exited with failure", 0, p.exitValue());
} catch (Exception e) {
fail("Unable to execute " + commandPath + " on remote machine: " + e.getMessage());
}
InputStream actualIS = p.getInputStream();
int v = -1;
try {
v = actualIS.read();
} catch (IOException e) {
fail("Failed to read output of command executed remotely: " + e.getMessage());
}
// Ensure something can be read
assertTrue(v != -1);
/*
* Test it opens connection before execute.
*/
IRemoteConnection conn = getConnection();
conn.close();
assertFalse(conn.isOpen());
try {
p = cl.execute(new Path("ls"), new String[] {}, new String[] {}, null, new NullProgressMonitor());
assertNotNull(p);
p.waitFor();
assertEquals("Process exited with failure", 0, p.exitValue());
} catch (CoreException | InterruptedException e) {
fail("Failed to open connection to execute a command: " + e.getMessage());
}
}
use of org.eclipse.remote.core.IRemoteConnection 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.IRemoteConnection in project linuxtools by eclipse.
the class RDTResourceSelectorProxy method selectResource.
private URI selectResource(String scheme, String initialPath, String prompt, Shell shell, ResourceType resourceType) {
IRemoteUIFileService uiFileService;
boolean schemeSwitch = false;
URI uri;
try {
uri = new URI(initialPath);
if (!scheme.equals(uri.getScheme())) {
uri = getEmptyPathURI(scheme);
schemeSwitch = true;
}
} catch (URISyntaxException e) {
uri = getEmptyPathURI(scheme);
schemeSwitch = true;
}
IRemoteServicesManager sm = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType ct = sm.getConnectionType(uri);
IRemoteConnection connection = ct.getConnection(uri);
IRemoteFileService fileService = connection.getService(IRemoteFileService.class);
// If the user is switching schemes, start with an empty host and path
uiFileService = ct.getService(IRemoteUIFileService.class);
uiFileService.showConnections(true);
if (!schemeSwitch) {
uiFileService.setConnection(connection);
}
String selectedPath = null;
switch(resourceType) {
case FILE:
selectedPath = uiFileService.browseFile(shell, prompt, uri.getPath(), IRemoteUIConstants.NONE);
break;
case DIRECTORY:
selectedPath = uiFileService.browseDirectory(shell, prompt, uri.getPath(), IRemoteUIConstants.NONE);
break;
default:
Activator.log(IStatus.ERROR, Messages.RDTResourceSelectorProxy_unsupported_resourceType + resourceType);
return null;
}
URI selectedURI = null;
if (selectedPath != null) {
connection = uiFileService.getConnection();
fileService = connection.getService(IRemoteFileService.class);
selectedURI = fileService.toURI(selectedPath);
}
return selectedURI;
}
use of org.eclipse.remote.core.IRemoteConnection in project linuxtools by eclipse.
the class AbstractRemoteTest method deleteResource.
protected void deleteResource(String directory) {
IRemoteServicesManager sm = getServicesManager();
IRemoteConnection conn = sm.getConnectionType("ssh").getConnection(CONNECTION_NAME);
assertNotNull(conn);
IRemoteFileService fileManager = conn.getService(IRemoteFileService.class);
assertNotNull(fileManager);
final IFileStore dstFileStore = fileManager.getResource(directory);
try {
dstFileStore.delete(EFS.NONE, null);
} catch (CoreException e) {
}
}
Aggregations