Question

I want to identify the type (java/c/...) of the currently selected project from an Eclipse plug-in; If possible some other information also (used libraries and what not), basically all the information surrounding the project.

I have been searching on google and here for a couple of hours now, to no avail. Can i even access the information i want without selecting some bogus Extension Point (none of the ones listed seem to fit what i want to do)? I mean, i don't want to actually add anything to Eclipse right now, i just want to print out that stuff into the console. (start small and stuff)

Sorry for the long rant, but i don't know how to better express my problem right now.

Was it helpful?

Solution

A lot of this information is stored in the .project file in the project folder. The correct way to access the information is via the IProject object for the project.

The IProject.getDescription method returns you a IProjectDescription containing information about the project.

To determine the type of project you need to look at the natures that are defined in the project description. The IProjectDescription.getNatureIds() method returns an array of the nature ids. A Java project will have the org.eclipse.jdt.core.javanature and a plug-in will have org.eclipse.pde.PluginNature (and a Java plug-in will have both these natures).

To find the IProject. If you have a selection in something like Package or Project Explorer try:

IResource resource = (IResource)Platform.getAdapterManager().getAdapter(obj, IResource.class);

or

IFile file = (IFile)Platform.getAdapterManager().getAdapter(obj, IFile.class);

the getProject() method of these interfaces gives you the IProject. You may also just be able to do:

IProject project = (IProject)Platform.getAdapterManager().getAdapter(obj, IProject.class);

Platform in the above is org.eclipse.core.runtime.Platform (there are other Platform classes in Eclipse so be sure to get the correct one).

If you just have a project name then use:

IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top