Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to get the current IProject during build

I found this from http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg23281.html
"In any case, there's no 'Active' project; but what you can do is find the currently selected item, then find out what it belongs to. From the IResource, you can get IProject. To track selections, use the ISelectionListener to be notified when the selection changes."
You can get IProject by calling IResource.getProject().

Petri

On 03/05/2011 02:34 AM, wwarren wrote:
Greetings,

I have implemented the IDynamicVariableResolver interface to produce
workspace and project variables for use in a MBS tool. My current
problem is that I cannot figure out how to get a hold of the
project-scoped variable stored from within the MBSCustomPage extension I
wrote to extend the CDTProjectWizard.

The simplest solution I can think of to get a hold of the project-scoped
variable is to get the IPathVariableManager through the IProject.
However, I have not figured out how to get the IProject. I have read the
Help Documentation and the MBSE Document but have been unable to find
what I am looking for.

The steps I plan to take to solve this problem are as follows:

1. I will run my plugin with the Eclipse debugger thing attached and
purposely generate a null pointer exception from within the
resolveValue() function so that I can view the the stack trace for clues
as to what class/package might give me access to the current project. I
actually just thought of doing this while writing the e-mail...I don't
know how effective it will be, but it's better than sitting on my
thumbs.

2. I will afterward download as much of the MBS source code as I can
find from the eclipse CVS respository and try to understand better what
happens after the build is initiated through the Project menu or the
Project Explorer context menu. I am sure there must be a way to have my
plugin notified of that event or detect it from within the
resolveValue() function through the ResourcesPlugin, though I am
doubtful as to whether the API exposes this functionality. If I could
create a class that gets notified of this event, I would create a
workspace variable that has as its value the name of the project for
which the build was initiated...which could then be used to get a handle
on the project during the resolveValue() function. 

3. If all else fails, I will learn how to use some standard Java XML
parser to get the necessary information from the .cproject file. I am
sure there are reasons not to do this such as changes to the XML file
format and naming conventions at the next Eclipse/CDT upgrade...so I
would prefer not to. Actually, I just realized that the .cproject is
stored within the project folder for which I would need the name of the
project to access. If I had that during the build, I would not need to
do this so...nevermind. Step 3 is probably not a potential solution.

If anyone on this list could offer me some advice or instruction about
how to approach this problem through any of the two options above, I
would appreciate it greatly. If not, have a nice weekend! I know I
will ;-].

Wayne


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top