Search in sources :

Example 1 with IRemoteConnection

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;
}
Also used : IRemoteConnectionType(org.eclipse.remote.core.IRemoteConnectionType) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteServicesManager(org.eclipse.remote.core.IRemoteServicesManager) IRemoteConnectionWorkingCopy(org.eclipse.remote.core.IRemoteConnectionWorkingCopy)

Example 2 with IRemoteConnection

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());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) InputStream(java.io.InputStream) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) IOException(java.io.IOException) RDTCommandLauncher(org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 3 with IRemoteConnection

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;
}
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 4 with IRemoteConnection

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;
}
Also used : IRemoteConnectionType(org.eclipse.remote.core.IRemoteConnectionType) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteServicesManager(org.eclipse.remote.core.IRemoteServicesManager) URISyntaxException(java.net.URISyntaxException) IRemoteUIFileService(org.eclipse.remote.ui.IRemoteUIFileService) URI(java.net.URI) IRemoteFileService(org.eclipse.remote.core.IRemoteFileService)

Example 5 with IRemoteConnection

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) {
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteServicesManager(org.eclipse.remote.core.IRemoteServicesManager) IFileStore(org.eclipse.core.filesystem.IFileStore) IRemoteFileService(org.eclipse.remote.core.IRemoteFileService)

Aggregations

IRemoteConnection (org.eclipse.remote.core.IRemoteConnection)9 CoreException (org.eclipse.core.runtime.CoreException)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 IRemoteFileService (org.eclipse.remote.core.IRemoteFileService)3 IRemoteServicesManager (org.eclipse.remote.core.IRemoteServicesManager)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)2 IRemoteConnectionType (org.eclipse.remote.core.IRemoteConnectionType)2 IRemoteProcessService (org.eclipse.remote.core.IRemoteProcessService)2 RemoteConnectionException (org.eclipse.remote.core.exception.RemoteConnectionException)2 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1