Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Plugin Dev: How do I get the paths for the currently selected project?

I'm writing a plugin that will parse a bunch of files in a project. But for the moment I'm stuck searching through the Eclipse API for answers.

The plugin works like this: Whenever I open a source file I let the plugin parse the source's corresponding build file (this could be further developed with caching the parse result). Getting the file is simple enough:

public void showSelection(IWorkbenchPart sourcePart) {
    // Gets the currently selected file from the editor
    IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor()
        .getEditorInput().getAdapter(IFile.class);
    if (file != null) {
        String path = file.getProjectRelativePath();
        /** Snipped out: Rip out the source path part
         * and replace with build path
         * Then parse it. */
    }
}

The problem I have is I have to use hard coded strings for the paths where the source files and build files go. Anyone know how to retrieve the build path from Eclipse? (I'm working in CDT by the way). Also is there a simple way to determine what the source path is (e.g. one file is under the "src" directory) of a source file?

like image 383
Spoike Avatar asked Sep 01 '08 10:09

Spoike


1 Answers

You should take a look at ICProject, especially the getOutputEntries and getAllSourceRoots operations. This tutorial has some brief examples too. I work with JDT so thats pretty much what I can do. Hope it helps :)

like image 133
Marcio Aguiar Avatar answered Oct 11 '22 09:10

Marcio Aguiar