use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Open a file in the Editor at the specified offset, highlighting the given length
*
* @param path : Absolute path pointing to the file which will be opened.
* @param line - line number to select, 0 to not select a line
* @param project - current project object
* @throws BadLocationException - Line number not valid in file
* @throws PartInitException if the editor could not be initialized
* @throws CoreException if the proxy cannot be initialized
* @since 3.1
*/
public static void openEditorAndSelect(String path, int line, IProject project) throws PartInitException, BadLocationException, CoreException {
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRemoteFileProxy proxy = null;
proxy = RemoteProxyManager.getInstance().getFileProxy(project);
IFileStore file = proxy.getResource(path);
if (file.fetchInfo().exists()) {
IEditorPart editor = IDE.openEditorOnFileStore(activePage, file);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
int start = document.getLineOffset(line - 1);
textEditor.selectAndReveal(start, 0);
}
}
}
}
use of org.eclipse.core.filesystem.IFileStore 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.core.filesystem.IFileStore in project linuxtools by eclipse.
the class SSHFileStore method childStores.
@Override
public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
if (monitor == null)
monitor = new NullProgressMonitor();
try {
monitor.beginTask(Messages.SSHFileStore_childStoresMonitor, 100);
ChannelSftp channel = proxy.getChannelSftp();
monitor.worked(25);
Vector<?> v = channel.ls(uri.getPath());
monitor.worked(50);
LinkedList<IFileStore> childs = new LinkedList<>();
boolean isDir = false;
for (int i = 0; i < v.size(); i++) {
ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) v.get(i);
if (// $NON-NLS-1$ //$NON-NLS-2$
!entry.getFilename().equals(".") && !entry.getFilename().equals(".."))
childs.add(createFileStore(path.append(entry.getFilename()).toString()));
else
isDir = true;
}
if (!isDir)
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.SSHFileStore_childStoresFailedDirectory, getName())));
monitor.worked(100);
monitor.done();
return childs.toArray(new IFileStore[0]);
} catch (SftpException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SSHFileStore_childStoresFailed + e.getMessage()));
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class AbstractDataManipulator method performCommand.
public void performCommand(String[] cmd, String file) {
Process proc = null;
IRemoteFileProxy fileProxy;
try {
try {
fileProxy = RemoteProxyManager.getInstance().getFileProxy(project);
} catch (RemoteConnectionException e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.MsgProxyError, Messages.MsgProxyError);
return;
}
IFileStore workDirStore = getWorkingDirStore();
proc = RuntimeProcessFactory.getFactory().exec(cmd, null, workDirStore, project, new PTY());
// $NON-NLS-1$
DebugPlugin.newProcess(launch, proc, "");
proc.waitFor();
StringBuffer data = new StringBuffer();
try (BufferedReader buffData = new BufferedReader(new InputStreamReader(fileProxy.getResource(file).openInputStream(EFS.NONE, null)))) {
readStream(buffData, data);
joinAll();
}
text = data.toString();
} catch (IOException | CoreException e) {
// $NON-NLS-1$
text = "";
} catch (InterruptedException e) {
// $NON-NLS-1$
text = "";
}
}
use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.
the class AbstractDataManipulator method performCommand.
public void performCommand(String[] cmd, int fd) {
BufferedReader buffData = null;
BufferedReader buffTemp = null;
try {
Process proc = null;
IFileStore workDirStore = getWorkingDirStore();
proc = RuntimeProcessFactory.getFactory().exec(cmd, null, workDirStore, project);
StringBuffer data = new StringBuffer();
StringBuffer temp = new StringBuffer();
switch(fd) {
case 2:
buffData = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
buffTemp = new BufferedReader(new InputStreamReader(proc.getInputStream()));
readStream(buffTemp, temp);
readStream(buffData, data);
break;
case 1:
// fall through to default case
default:
buffData = new BufferedReader(new InputStreamReader(proc.getInputStream()));
buffTemp = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
readStream(buffData, data);
readStream(buffTemp, temp);
break;
}
joinAll();
text = data.toString();
} catch (IOException | InterruptedException e) {
// $NON-NLS-1$
text = "";
} finally {
try {
if (buffData != null) {
buffData.close();
}
if (buffTemp != null) {
buffTemp.close();
}
} catch (IOException e) {
// continue
}
}
}
Aggregations