Search in sources :

Example 36 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class RemoteConnection method delete.

/**
 * Remote delete function. This method is recursive. If a remote directory
 * is specified, the remote directory and all its contents are removed. A
 * RemoteConnectionException is thrown if failure occurs for any reason.
 *
 * @param remotePath
 *            - the remote path of the file or folder to be deleted
 * @param monitor
 *            - progress monitor
 * @throws RemoteConnectionException If a problem while deleting occured.
 */
public void delete(IPath remotePath, IProgressMonitor monitor) throws RemoteConnectionException {
    try {
        IFileStore remoteFile = rmtFileProxy.getResource(remotePath.toString());
        remoteFile.delete(0, monitor);
    } catch (CoreException e) {
        throw new RemoteConnectionException(e.getLocalizedMessage(), e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 37 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class RemoteProxyCMainTab method checkWorkingDir.

private boolean checkWorkingDir(IProject project) {
    String name = workingDirText.getText().trim();
    if (name.length() == 0) {
        // an empty working directory means, "use the default"
        return true;
    }
    // changed (project).
    if (name.equals(fPreviouslyCheckedWorkingDir)) {
        if (fPreviouslyCheckedWorkingDirErrorMsg != null) {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg);
        }
        return fPreviouslyCheckedWorkingDirIsValid;
    }
    fPreviouslyCheckedWorkingDir = name;
    // we'll flip this below if
    fPreviouslyCheckedWorkingDirIsValid = true;
    // not true
    // we'll set this below if
    fPreviouslyCheckedWorkingDirErrorMsg = null;
    // there's an error
    IPath wdPath;
    URI wdURI = null;
    boolean passed = false;
    try {
        wdURI = new URI(name);
        String wdPathStr = wdURI.getPath();
        if (wdPathStr == null) {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_working_directory_is_invalid);
            fPreviouslyCheckedWorkingDirIsValid = false;
            return false;
        }
        wdPath = Path.fromOSString(wdURI.getPath());
        if (!wdPath.isAbsolute() && wdURI != null && !wdURI.isAbsolute()) {
            URI projectURI = project.getLocationURI();
            wdURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + wdPath.toString(), EMPTY_STRING);
        }
        if (wdURI != null) {
            passed = true;
        }
    } catch (URISyntaxException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.uri_of_working_directory_is_invalid);
        fPreviouslyCheckedWorkingDirIsValid = false;
        return false;
    }
    if (!passed) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_does_not_exist);
        fPreviouslyCheckedWorkingDirIsValid = false;
        return false;
    }
    passed = false;
    IRemoteFileProxy wdFileProxy;
    try {
        wdFileProxy = RemoteProxyManager.getInstance().getFileProxy(wdURI);
        if (wdFileProxy != null) {
            IFileStore wdFS = wdFileProxy.getResource(wdURI.getPath());
            if (wdFS != null) {
                IFileInfo wdFI = wdFS.fetchInfo();
                if (wdFI != null) {
                    if (wdFI.exists()) {
                        if (wdFI.isDirectory()) {
                            passed = true;
                        } else {
                            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_is_not_a_directory);
                        }
                    } else {
                        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.working_directory_does_not_exist);
                    }
                } else {
                    setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
                }
            } else {
                setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
            }
        } else {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.scheme_error_in_working_directory);
        }
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.connection_of_working_directory_cannot_be_opened);
    }
    if (!passed) {
        fPreviouslyCheckedWorkingDirIsValid = false;
        return false;
    }
    setErrorMessage(null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 38 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class RemoteProxyCMainTab method checkCopyFromExe.

private boolean checkCopyFromExe(IProject project) {
    if (!enableCopyFromExeButton.getSelection()) {
        setErrorMessage(null);
        return true;
    }
    String name = copyFromExeText.getText().trim();
    if (name.length() == 0) {
        setErrorMessage(ProxyLaunchMessages.copy_from_exe_is_not_specified);
        return false;
    }
    // changed (binary or project name). See bug 277663.
    if (name.equals(fPreviouslyCheckedCopyFromExe)) {
        if (fPreviouslyCheckedCopyFromExeErrorMsg != null) {
            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg);
        }
        return fPreviouslyCheckedCopyFromExeIsValid;
    }
    fPreviouslyCheckedCopyFromExe = name;
    // we'll flip this below if
    fPreviouslyCheckedCopyFromExeIsValid = true;
    // not true
    // we'll set this below if
    fPreviouslyCheckedCopyFromExeErrorMsg = null;
    // there's an error
    IPath exePath;
    URI exeURI = null;
    boolean passed = false;
    try {
        exeURI = new URI(name);
        String exePathStr = exeURI.getPath();
        if (exePathStr == null) {
            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
            fPreviouslyCheckedCopyFromExeIsValid = false;
            return false;
        }
        exePath = Path.fromOSString(exeURI.getPath());
        if (!exePath.isAbsolute() && exeURI != null && !exeURI.isAbsolute()) {
            URI projectURI = project.getLocationURI();
            exeURI = new URI(projectURI.getScheme(), projectURI.getAuthority(), projectURI.getRawPath() + '/' + exePath.toString(), EMPTY_STRING);
        }
        if (exeURI != null) {
            passed = true;
        }
    } catch (URISyntaxException e) {
        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.uri_of_copy_from_exe_is_invalid);
        fPreviouslyCheckedCopyFromExeIsValid = false;
        return false;
    }
    if (!passed) {
        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
        fPreviouslyCheckedCopyFromExeIsValid = false;
        return false;
    }
    passed = false;
    try {
        IRemoteFileProxy exeFileProxy;
        exeFileProxy = RemoteProxyManager.getInstance().getFileProxy(exeURI);
        if (exeFileProxy != null) {
            String exeFilePath = exeURI.getPath();
            IFileStore exeFS = exeFileProxy.getResource(exeFilePath);
            if (exeFS != null) {
                IFileInfo exeFI = exeFS.fetchInfo();
                if (exeFI != null) {
                    if (exeFI.exists()) {
                        if (exeFI.getAttribute(EFS.ATTRIBUTE_EXECUTABLE) && !exeFI.isDirectory()) {
                            passed = true;
                        } else {
                            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_have_execution_rights);
                        }
                    } else {
                        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.copy_from_exe_does_not_exist);
                    }
                } else {
                    setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
                }
            } else {
                setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.error_accessing_copy_from_exe);
            }
        } else {
            setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.scheme_error_in_copy_from_exe);
        }
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedCopyFromExeErrorMsg = ProxyLaunchMessages.connection_of_copy_from_exe_cannot_be_opened);
    }
    if (!passed) {
        fPreviouslyCheckedCopyFromExeIsValid = false;
        return false;
    }
    setErrorMessage(null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 39 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 offset : Offset of the function to be highlighted.
 * @param length : Length of the function to be highlighted.
 * @throws PartInitException if the editor could not be initialized
 */
public static void openEditorAndSelect(String path, int offset, int length) throws PartInitException {
    Path p = new Path(path);
    if (p.toFile().exists()) {
        IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(p);
        IEditorPart editor = IDE.openEditorOnFileStore(activePage, fileStore);
        if (editor instanceof ITextEditor) {
            ITextEditor text = (ITextEditor) editor;
            text.selectAndReveal(offset, length);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) IEditorPart(org.eclipse.ui.IEditorPart)

Example 40 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project linuxtools by eclipse.

the class FileProxyTest method testLocalFileProxy.

@Test
public void testLocalFileProxy() {
    IRemoteFileProxy fileProxy = null;
    try {
        fileProxy = proxyManager.getFileProxy(localProject.getProject());
        assertTrue("Should have returned a remote launcher", fileProxy instanceof LocalFileProxy);
    } catch (CoreException e) {
        fail("Should have returned a launcher: " + e.getCause());
    }
    /*
		 * Test getDirectorySeparator()
		 */
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);
    /*
		 *  Test getResource()
		 */
    IFileStore actualFileStore = fileProxy.getResource(localProject.getProject().getLocation().toOSString());
    assertNotNull(actualFileStore);
    IFileStore expectedFileStore = null;
    try {
        expectedFileStore = EFS.getStore(localProject.getLocationURI());
    } catch (CoreException e) {
        fail("Unabled to get FileStore to local project: " + e.getMessage());
    }
    assertEquals("FileStore to local project folder diverge", expectedFileStore, actualFileStore);
    assertTrue(actualFileStore.fetchInfo().isDirectory());
    actualFileStore = fileProxy.getResource("/filenotexits");
    assertNotNull(actualFileStore);
    IFileInfo fileInfo = actualFileStore.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());
    /*
		 * Test getWorkingDir()
		 */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals(localProject.getLocationURI(), workingDir);
    /*
		 * Test toPath()
		 */
    assertEquals(localProject.getProject().getLocation().toOSString(), fileProxy.toPath(localProject.getLocationURI()));
}
Also used : LocalFileProxy(org.eclipse.linuxtools.internal.profiling.launch.LocalFileProxy) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) IRemoteFileProxy(org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy) IFileStore(org.eclipse.core.filesystem.IFileStore) URI(java.net.URI) AbstractProxyTest(org.eclipse.linuxtools.remote.proxy.tests.AbstractProxyTest) Test(org.junit.Test)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)178 CoreException (org.eclipse.core.runtime.CoreException)80 IOException (java.io.IOException)49 IPath (org.eclipse.core.runtime.IPath)42 IFileInfo (org.eclipse.core.filesystem.IFileInfo)33 URI (java.net.URI)30 Path (org.eclipse.core.runtime.Path)30 IFile (org.eclipse.core.resources.IFile)28 PartInitException (org.eclipse.ui.PartInitException)25 File (java.io.File)22 InputStream (java.io.InputStream)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)21 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 InputStreamReader (java.io.InputStreamReader)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)14 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)14 BufferedInputStream (java.io.BufferedInputStream)13 BufferedReader (java.io.BufferedReader)13 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)11 IStatus (org.eclipse.core.runtime.IStatus)11