Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] get artifact name and getProjet return null

Thanks for the answer,

Will try and use something along the lines you wrote to find the active (focused) project.

The main problem is however question 1, I will describe the plug-in some more and maybe someone can give me some hints.

This part of the plug-in will run the program several times with different environments variables and report back execution time and output data from the program. Today I am using a hard coded shell script that is started from within eclipse and then parse the result and report it nicely.

The problem is that this is far from a general solution since I need a new shell script for each project, I would like to either create a dynamic shell script depending on the artifact name and the program arguments or start the program directly from within eclipse. The nice thing with a shell script is that I can very easily add the timing command and set different environment variables, this solution will be specific for the operating system (Kubuntu, 7.04), but that is not a problem for now.

I can however not find any functions in the API that will return artifact name and/or program arguments, any hints where I can find this information?


On Mon, Jun 2, 2008 at 6:14 PM, Wieant Nielander <wieant@xxxxxxxxx> wrote:

> Using the following function to get the active project will always return
> null, is this a bug or do I use it incorrect?
> IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
> For now I use this method, but it is far from perfect since I need to close
> all the other projects.
> IProject[] myproject =
> ResourcesPlugin.getWorkspace().getRoot().getProjects();
>   IProject project = null;
>   for(int i = 0; i < myproject.length; i++) {
>     if( myproject[i].isOpen()) {
>       project = myproject[i];
>       continue;
>     }
> }

You are using getProject incorrectly, 'getProject()' is a method
defined on all IResource elements, including the root workspace, and
returns the project to which the given resource belongs, but as the
workspace root does not belong to any project it will by definition
return null.

It is important to state in what context you need this info, in
general an action or view keeps track of the current selection,
and from that you can distill the 'active' project, e.g. if you have
an action, you could use something like the following in its delegate:

 * @see IActionDelegate#selectionChanged(IAction, ISelection)
public void selectionChanged(IAction action, ISelection selection)
       if ( selection instanceof StructuredSelection )
               Object obj = ((StructuredSelection)selection).getFirstElement();
               if ( obj instanceof IAdaptable )
                       obj = ((IAdaptable)obj).getAdapter(IResource.class);
               if ( obj instanceof IResource )
                       m_project = ((IResource)obj).getProject();
cdt-dev mailing list

Back to the top