Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipse-dev] Project natures are not applied after Project open

Hello eclipse developers ,


I am a question for plugin developers of ‘org.eclipse.core.resources’ & ‘org.eclipse.ui.ide’.


I am facing following problem with the projects:


We are generating some projects programmatically at eclipse start-up based on some templates, including .project , and then close projects after generation. 

Then if I open project A, it's natures are successfully applied from .project.

But if I leave closed the project B, then restart eclipse, and then open project B, the natures are not applied. I have to close and reopen the project B, and only then the natures are properly applied.


Based on the debug that I did in 'org.eclipse.core.resources' & 'org.eclipse.ui.ide' it seems to be by intention.

I found the cause of this problem and a potential fix but it implies to use restricted API. 

The question is, if there is a better way to fix this?

I am working on eclipse oxygen 4.7.3


In detail:

The projects are generated using general workflow:


IPath path = new Path(projectName);

IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment());  
IPath projectLocation = Platform.getLocation().append(path);


IProjectDescription pDesc = ResourcesPlugin.getWorkspace().newProjectDescription(path.lastSegment());


projectHandle.create( pDesc , progressMonitor);

// and, by default, the project is not open after creation


If I open project now, same instance of IProjectDescription is used that I provided, that has natures, and it works as expected.

When projects are created for the first time they have the flag M_USED= false

It reaches IDEWorkbenchActivityHelper.processProjects() where natures ids array is not null, needsUpdates is true, and the natures are applied before the project is open.


But if I restart eclipse and open project B that never has been opened after creation, On open action, it also has the flag  M_USED= false

but this time, the project description instance is new and does not have required natures (ids = [empty] ; needsUpdate =false)

I close and reopen the project, now it has  M_USED= true, and goes through different stacktrace that suppose to restore the project and to reload the natures, and thanks to that, second time, all natures are applied. The  (ids = [is not empty] ; needsUpdate = true) .




Is it a bug that can be fixed, or It's an unusual case, and it is supposed that first time when project is created is has natures already, and not need to restore it ?


The only solution I found is to use restricted API, and force to set the flag  M_USED right after project creation. 


int M_USED = 0x10;
org.eclipse.core.internal.resources.ResourceInfo resinfo = ((org.eclipse.core.internal.resources.Project) projectHandle).getResourceInfo(false, true);




Thank you in advance

Kind Regards



Back to the top