use of org.eclipse.remote.core.IRemoteFileService 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;
}
use of org.eclipse.remote.core.IRemoteFileService 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) {
}
}
use of org.eclipse.remote.core.IRemoteFileService 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);
}
Aggregations