Search in sources :

Example 46 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 47 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 48 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 49 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)

Example 50 with IFileStore

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

the class JavaDocContentProducer method getInputStream.

/**
 * Returns an input stream for the requested file. This method will be
 * called by the Eclipse help system to serve up content to the internal
 * web server, which will then be displayed in the help browser.
 *
 * @param  pluginID  the plugin ID as set in the manifest
 * @param  href      the link to the file generated by the help system
 * @param  locale    the locale of the file requested (as set in
 * 					 JavaDocTocProvider)
 * @return           the input stream to the file requested
 */
@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
    // path creation so we just strip them.
    if (href.contains("?")) {
        // $NON-NLS-1$
        href = href.substring(0, href.indexOf('?'));
    }
    // Eclipse help system appends additional plugin ID, so we strip this
    // as well.
    // $NON-NLS-1$ //$NON-NLS-2$
    String pathToFile = href.replace("org.eclipse.linuxtools.javadocs", "");
    // Get path from preferences store, attempt to open input stream to the
    // file being requested.
    IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
    IPath javadocLocation = new Path(ps.getString(PreferenceConstants.JAVADOCS_DIRECTORY)).append(pathToFile);
    IFileSystem fs = EFS.getLocalFileSystem();
    IFileStore localLocation = fs.getStore(javadocLocation);
    InputStream stream = null;
    if (!localLocation.fetchInfo().exists()) {
        return null;
    }
    try {
        stream = localLocation.openInputStream(EFS.NONE, new NullProgressMonitor());
    } catch (CoreException e) {
        ILog eLog = JavaDocPlugin.getDefault().getLog();
        eLog.log(e.getStatus());
    }
    return stream;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) IFileSystem(org.eclipse.core.filesystem.IFileSystem) IFileStore(org.eclipse.core.filesystem.IFileStore) ILog(org.eclipse.core.runtime.ILog) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

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