Search in sources :

Example 1 with LocalLauncher

use of org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher in project linuxtools by eclipse.

the class RemoteProxyManager method getLauncher.

@Override
public IRemoteCommandLauncher getLauncher(IProject project) throws CoreException {
    if (project == null) {
        return new LocalLauncher();
    }
    String scheme = mapping.getSchemeFromNature(project);
    if (scheme != null) {
        IRemoteProxyManager manager = getRemoteManager(scheme);
        return manager.getLauncher(project);
    }
    URI projectURI = project.getLocationURI();
    return getLauncher(projectURI);
}
Also used : LocalLauncher(org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher) URI(java.net.URI)

Example 2 with LocalLauncher

use of org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher in project linuxtools by eclipse.

the class CommandLauncherProxyTest method testLocalCommandLauncher.

@Test
public void testLocalCommandLauncher() {
    IRemoteCommandLauncher cl = null;
    Process p = null;
    InputStream actualIS = null, expectedIS = null;
    IPath commandPath, changeToDirectory;
    String[] args, env;
    try {
        cl = proxyManager.getLauncher(localProject.getProject());
        assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    /*
		 * Prepare arguments for the test
		 */
    commandPath = new Path("/bin/uptime");
    args = new String[] { "-s" };
    StringBuilder fullCmd = new StringBuilder();
    fullCmd.append(commandPath.toOSString());
    for (String s : args) {
        fullCmd.append(" " + s);
    }
    // Use local env variables
    ArrayList<String> envList = new ArrayList<>();
    for (Entry<String, String> entry : System.getenv().entrySet()) {
        envList.add(entry.getKey() + "=" + entry.getValue());
    }
    env = envList.toArray(new String[] {});
    changeToDirectory = new Path("/tmp");
    /*
		 * Run and get results using the proxy
		 */
    try {
        p = cl.execute(commandPath, args, env, changeToDirectory, new NullProgressMonitor());
        assertNotNull(p);
        while (p.isAlive()) {
        }
        // Call to waitFor() will drive to empty result
        // p.waitFor();
        assertEquals("Process exited with failure", 0, p.exitValue());
    } catch (Exception e) {
        fail("Unable to execute " + fullCmd.toString() + " on local machine: " + e.getMessage());
    }
    actualIS = p.getInputStream();
    assertNotNull(actualIS);
    /*
		 * Run and get results using java Runtime
		 */
    try {
        Process expectedProcess = Runtime.getRuntime().exec(fullCmd.toString());
        expectedProcess.waitFor();
        expectedIS = expectedProcess.getInputStream();
        assertNotNull(expectedIS);
    } catch (Exception e) {
        fail("Unable to execute " + fullCmd.toString() + " on  local using Runtime.exec: " + e.getMessage());
    }
    /*
		 * Finally compare results obtained
		 */
    int va = 0, ve = 0;
    do {
        try {
            va = actualIS.read();
            ve = expectedIS.read();
        } catch (IOException e) {
            fail("Unable to read from Input Stream: " + e.getMessage());
        }
        assertEquals("Local proxy command output differs from Runtime.exec", ve, va);
    } while (va != -1);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) LocalLauncher(org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) 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 LocalLauncher

use of org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher in project linuxtools by eclipse.

the class RemoteProxyManagerTest method testGetLauncher.

@Test
public void testGetLauncher() {
    IRemoteCommandLauncher cl;
    try {
        /*
			 * Test launcher got for local URIs and project
			 */
        cl = proxyManager.getLauncher(localProject.getLocationURI());
        assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
        cl = proxyManager.getLauncher(localProject.getProject());
        assertTrue("Should have returned a local launcher", cl instanceof LocalLauncher);
        /*
			 * Test launcher got for remote project and URI
			 */
        cl = proxyManager.getLauncher(URI.create("ssh://" + CONNECTION_NAME + "/path/to/file"));
        assertTrue("Should have returned a remote file proxy", cl instanceof RDTCommandLauncher);
        cl = proxyManager.getLauncher(syncProject.getProject());
        assertTrue("Should have returned a remote launcher", cl instanceof RDTCommandLauncher);
        /*
			 * Test launcher got for jsch scheme
			 */
        cl = proxyManager.getLauncher(URI.create("jsch://" + USERNAME + "@" + HOST + ":22/path/to/file"));
        assertTrue("Should have returned a remote file proxy", cl instanceof SSHCommandLauncher);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    /*
		 * Test the proxy for unsupported URIs
		 */
    try {
        // As of org.eclipse.remote 2.0, remotetools scheme is no longer
        // support
        cl = proxyManager.getLauncher(URI.create("remotetools://MyConnection/path/to/file"));
        fail("remotetools scheme should not be recognized");
    } catch (CoreException e) {
        assertTrue(e.getMessage(), true);
    }
}
Also used : LocalLauncher(org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher) CoreException(org.eclipse.core.runtime.CoreException) SSHCommandLauncher(org.eclipse.linuxtools.internal.ssh.proxy.SSHCommandLauncher) IRemoteCommandLauncher(org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher) RDTCommandLauncher(org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Aggregations

LocalLauncher (org.eclipse.linuxtools.internal.profiling.launch.LocalLauncher)3 CoreException (org.eclipse.core.runtime.CoreException)2 IRemoteCommandLauncher (org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher)2 AbstractProxyTest (org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 RDTCommandLauncher (org.eclipse.linuxtools.internal.rdt.proxy.RDTCommandLauncher)1 SSHCommandLauncher (org.eclipse.linuxtools.internal.ssh.proxy.SSHCommandLauncher)1