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);
}
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);
}
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);
}
}
Aggregations