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