Search in sources :

Example 6 with IRemoteConnection

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

the class FileProxyTest method testRemoteFileProxyOnSyncProject.

@Test
public void testRemoteFileProxyOnSyncProject() {
    IRemoteFileProxy fileProxy = null;
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", fileProxy instanceof RDTFileProxy);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);
    SyncConfig config = getSyncConfig(syncProject.getProject());
    String projectLocation = config.getLocation();
    assertNotNull(projectLocation);
    IRemoteConnection conn = null;
    String connScheme = null;
    try {
        conn = config.getRemoteConnection();
        connScheme = conn.getConnectionType().getScheme();
    } catch (MissingConnectionException e) {
        fail("Unabled to get remote connection: " + e.getMessage());
    }
    /*
		 *  Test getResource()
		 */
    IFileStore fs = fileProxy.getResource(projectLocation);
    assertNotNull(fs);
    assertEquals("Remote connection and FileStore schemes diverge", connScheme, fs.toURI().getScheme());
    // assertTrue(fs.fetchInfo().isDirectory());
    fs = fileProxy.getResource("/filenotexits");
    assertNotNull(fs);
    IFileInfo fileInfo = fs.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());
    /*
		 * Test getWorkingDir()
		 */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals("Remote connection and URI schemes diverge", connScheme, workingDir.getScheme());
    /*
		 * Test toPath()
		 */
    URI uri = null;
    try {
        uri = new URI(connScheme, conn.getName(), projectLocation, null, null);
    } catch (URISyntaxException e) {
        fail("Failed to build URI for the test: " + e.getMessage());
    }
    assertEquals(projectLocation, fileProxy.toPath(uri));
    /*
		 * Test it opens connection
		 */
    assertNotNull(conn);
    conn.close();
    assertFalse(conn.isOpen());
    try {
        fileProxy = proxyManager.getFileProxy(syncProject.getProject());
        assertNotNull(fileProxy);
    } catch (CoreException e) {
        fail("Failed to obtain file proxy when connection is closed: " + e.getMessage());
    }
    fs = fileProxy.getResource("/tmp/somedir");
    assertNotNull(fs);
    assertFalse(fs.fetchInfo().exists());
    try {
        fs.mkdir(EFS.SHALLOW, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("should be able to create a directory when connection is closed: " + e.getMessage());
    }
    assertTrue(fs.fetchInfo().exists());
    try {
        fs.delete(EFS.NONE, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("Failed to delete file: " + e.getMessage());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SyncConfig(org.eclipse.ptp.rdt.sync.core.SyncConfig) URISyntaxException(java.net.URISyntaxException) MissingConnectionException(org.eclipse.ptp.rdt.sync.core.exceptions.MissingConnectionException) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 7 with IRemoteConnection

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

Example 8 with IRemoteConnection

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

the class RDTProxyManager method getOS.

@Override
public String getOS(URI uri) {
    IRemoteConnection connection = getConnection(uri);
    String os = connection.getProperty(IRemoteConnection.OS_NAME_PROPERTY);
    if (os == null || os.isEmpty()) {
        // $NON-NLS-1$
        return "Linux";
    }
    return os;
}
Also used : IRemoteConnection(org.eclipse.remote.core.IRemoteConnection)

Example 9 with IRemoteConnection

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

the class RemoteProxyEnvManagerTest method testGetEnv.

@Test
public void testGetEnv() {
    Map<String, String> actualEnv = new HashMap<>();
    Map<String, String> expectedEnv = new HashMap<>();
    IRemoteEnvProxyManager proxy = new RemoteEnvProxyManager();
    /*
		 * Get local environment to compare with returned by the proxy
		 */
    expectedEnv = System.getenv();
    try {
        actualEnv = proxy.getEnv(localProject.getProject());
    } catch (CoreException e) {
        fail("Failed to get environment variables: " + e.getMessage());
    }
    assertEquals(expectedEnv.size(), actualEnv.size());
    assertEquals(expectedEnv.keySet(), actualEnv.keySet());
    assertEquals(expectedEnv.values(), actualEnv.values());
    /*
		 * Get remote environment to compare with returned by the proxy
		 */
    try {
        actualEnv = proxy.getEnv(syncProject.getProject());
    } catch (CoreException e) {
        fail("Failed to get remote environment variables: " + e.getMessage());
    }
    assertTrue(!actualEnv.isEmpty());
    // Bug 469184 - it should be able to filter out some variables
    for (Entry<String, String> entry : actualEnv.entrySet()) {
        assertTrue("It should not hold exported functions: " + entry.getKey(), !entry.getKey().matches("BASH_FUNC_.*"));
        assertTrue("It should not hold exported functions: " + entry.getKey(), !entry.getValue().matches("^\\("));
    }
    /*
		 * Test it opens connection to get the env
		 */
    IRemoteConnection conn = getConnection();
    assertNotNull(conn);
    conn.close();
    assertFalse(conn.isOpen());
    proxy = new RemoteEnvProxyManager();
    try {
        actualEnv = proxy.getEnv(syncProject.getProject());
        assertTrue(actualEnv.size() > 0);
    } catch (CoreException e) {
        fail("Failed to get env when connection is closed: " + e.getMessage());
    }
}
Also used : RemoteEnvProxyManager(org.eclipse.linuxtools.profiling.launch.RemoteEnvProxyManager) IRemoteEnvProxyManager(org.eclipse.linuxtools.profiling.launch.IRemoteEnvProxyManager) CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) IRemoteEnvProxyManager(org.eclipse.linuxtools.profiling.launch.IRemoteEnvProxyManager) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) Test(org.junit.Test)

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