Search in sources :

Example 41 with IFileStore

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

the class OpenSourceFileAction method openAnnotatedSourceFile.

public static void openAnnotatedSourceFile(IProject project, IFile binary, SourceFile sourceFile, IPath realLocation, int lineNumber) {
    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        IWorkbenchPage page = CUIPlugin.getActivePage();
        if (page != null) {
            IFileStore fs = getFileStore(project, realLocation);
            if (fs == null && !realLocation.isAbsolute() && binary != null) {
                IPath p = binary.getProjectRelativePath().removeLastSegments(1);
                fs = getFileStore(project, p.append(realLocation));
            }
            if (fs == null) {
                try {
                    page.openEditor(new STAnnotatedSourceNotFoundEditorInput(project, sourceFile, realLocation, lineNumber), STAnnotatedSourceNotFoundEditor.ID, true);
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            } else {
                try {
                    IEditorPart editor = IDE.openEditorOnFileStore(page, fs);
                    if (lineNumber > 0 && editor instanceof ITextEditor) {
                        IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
                        IDocument document = provider.getDocument(editor.getEditorInput());
                        try {
                            int start = document.getLineOffset(lineNumber - 1);
                            ((ITextEditor) editor).selectAndReveal(start, 0);
                        } catch (BadLocationException e) {
                        // ignore
                        }
                        IWorkbenchPage p = editor.getSite().getPage();
                        p.activate(editor);
                    }
                } catch (PartInitException e) {
                    Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.OpenSourceFileAction_open_error, e);
                    Activator.getDefault().getLog().log(s);
                }
            }
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IPath(org.eclipse.core.runtime.IPath) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) PartInitException(org.eclipse.ui.PartInitException) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 42 with IFileStore

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

the class KernelSourceTreeTest method testBuildKernelTree.

@Test
public void testBuildKernelTree() {
    TreeNode t;
    // Null
    String direct = null;
    String[] excluded = null;
    kst.buildKernelTree(direct, excluded);
    assertNull("Null directory", kst.getTree());
    // Empty string for directory
    direct = "";
    kst.buildKernelTree(direct, excluded);
    assertNull("Empty string directory", kst.getTree());
    // Missing folder
    direct = "/noSuchDirectory/";
    kst.buildKernelTree(direct, excluded);
    assertEquals("Missing directory", 0, kst.getTree().getChildCount());
    // Inaccessible
    direct = "/root/";
    kst.buildKernelTree(direct, excluded);
    assertEquals("Inaccessable directory", 0, kst.getTree().getChildCount());
    // No .c or .h files
    direct = "/bin/";
    kst.buildKernelTree(direct, excluded);
    t = kst.getTree();
    assertEquals("Bin folder item count", 0, t.getChildCount());
    assertTrue("Bin folder name", "bin".equals(t.toString()));
    assertTrue("Bin has file", t.getData() instanceof IFileStore);
    excluded = new String[] { ".git" };
    // No .c or .h files
    direct = "/tmp/";
    kst.buildKernelTree(direct, excluded);
}
Also used : TreeNode(org.eclipse.linuxtools.systemtap.structures.TreeNode) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 43 with IFileStore

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

the class ErrorLineMatcher method matchFound.

@Override
public void matchFound(PatternMatchEvent event) {
    try {
        String line = console.getDocument().get(event.getOffset(), event.getLength());
        String file = line.substring(line.indexOf('/'));
        // $NON-NLS-1$
        String[] splitted = file.split(":");
        Path path = new Path(splitted[0]);
        if (path.toFile().exists()) {
            IFileStore iFileStore = EFS.getLocalFileSystem().getStore(path);
            FileHyperlink fileLink = new FileHyperlink(iFileStore, Integer.valueOf(splitted[1]));
            console.addHyperlink(fileLink, line.indexOf('/') + event.getOffset(), file.length());
        }
    } catch (BadLocationException e1) {
        return;
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFileStore(org.eclipse.core.filesystem.IFileStore) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 44 with IFileStore

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

the class OpenFileHandler method runActions.

private void runActions(File file) {
    successful = false;
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
    IWorkbenchPage page = window.getActivePage();
    try {
        IDE.openEditorOnFileStore(page, fileStore);
        successful = true;
    } catch (PartInitException e) {
        ErrorDialog.openError(window.getShell(), // $NON-NLS-1$
        Localization.getString("OpenFileHandler.Problem"), // $NON-NLS-1$
        Localization.getString("OpenFileHandler.ProblemMessage"), new Status(IStatus.ERROR, IDEPlugin.PLUGIN_ID, e.getMessage(), e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 45 with IFileStore

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

the class ImageBuildPage method validate.

private void validate() {
    boolean complete = true;
    boolean error = false;
    setMessage(null);
    String name = nameText.getText();
    if (name.length() > 0 && name.charAt(name.length() - 1) == ':') {
        setErrorMessage(WizardMessages.getString(INVALID_ID));
        error = true;
    } else {
        if (name.contains(":")) {
            // $NON-NLS-1$
            if (name.substring(name.indexOf(':') + 1).contains(":")) {
                // $NON-NLS-1$
                setErrorMessage(WizardMessages.getString(INVALID_ID));
                error = true;
            }
        } else if (name.isEmpty()) {
            setMessage(WizardMessages.getString(IMAGE_NAME_EMPTY), WARNING);
        }
    }
    if (!error) {
        String dir = directoryText.getText();
        if (dir.length() == 0) {
            editButton.setEnabled(false);
            complete = false;
        } else {
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(dir));
            IFileInfo info = fileStore.fetchInfo();
            if (!info.exists()) {
                error = true;
                setErrorMessage(WizardMessages.getString(NONEXISTENT_DIRECTORY));
            } else if (!info.isDirectory()) {
                error = true;
                setErrorMessage(WizardMessages.getString(INVALID_DIRECTORY));
            } else if (!Files.isReadable(Paths.get(dir))) {
                error = true;
                setErrorMessage(WizardMessages.getString(UNREADABLE_DIRECTORY));
            } else {
                editButton.setEnabled(true);
                // $NON-NLS-1$
                IFileStore dockerStore = fileStore.getChild("Dockerfile");
                if (!dockerStore.fetchInfo().exists()) {
                    complete = false;
                    setMessage(WizardMessages.getString(NO_DOCKER_FILE), IMessageProvider.INFORMATION);
                } else {
                    lastDirectoryPath = dir;
                }
            }
        }
    }
    if (!error) {
        setErrorMessage(null);
    } else {
        editButton.setEnabled(false);
    }
    setPageComplete(complete && !error);
}
Also used : Path(org.eclipse.core.runtime.Path) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore)

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