Search in sources :

Example 86 with IFileStore

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);
            }
        }
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument)

Example 87 with IFileStore

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());
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteConnection(org.eclipse.remote.core.IRemoteConnection) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) RDTFileProxy(org.eclipse.linuxtools.internal.rdt.proxy.RDTFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) SyncConfig(org.eclipse.ptp.rdt.sync.core.SyncConfig) URISyntaxException(java.net.URISyntaxException) MissingConnectionException(org.eclipse.ptp.rdt.sync.core.exceptions.MissingConnectionException) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Example 88 with IFileStore

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()));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SftpException(com.jcraft.jsch.SftpException) LinkedList(java.util.LinkedList) ChannelSftp(com.jcraft.jsch.ChannelSftp) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 89 with IFileStore

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 = "";
    }
}
Also used : RemoteConnectionException(org.eclipse.linuxtools.profiling.launch.RemoteConnectionException) PTY(org.eclipse.cdt.utils.pty.PTY) InputStreamReader(java.io.InputStreamReader) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 90 with IFileStore

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
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9