Bug 553647 - Project natures are not applied on open project action
Summary: Project natures are not applied on open project action
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 4.6   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-Resources-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-01 07:48 EST by Lidia Popescu CLA
Modified: 2019-12-06 09:15 EST (History)
1 user (show)

See Also:


Attachments
The eclipse plugin demo project (101.75 KB, application/x-zip-compressed)
2019-12-01 07:48 EST, Lidia Popescu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lidia Popescu CLA 2019-12-01 07:48:42 EST
Created attachment 280826 [details]
The eclipse plugin demo project

Hello,

We are generating programmatically some project at workbench start-up based on existing templates, and then keep them close. 
If such project is open in next workbench session, the project natures are not applied.
 
I am providing a demo project, steps to reproduce, and the root cause based on my investigation.
Maybe it's an unusual case, and it is done by purpose, but still if there is a chance to fix it, it would be very useful for us.

Steps to reproduce:
Tested on eclipse oxygen (March 21, 2018) and in latest available eclipse (v. 4.13 September 18, 2019).

- Import attached eclipse project 'com.demo.projecttest'
- Update in StartupExtension.copyTemplate()   the absolute path to the template (com.demo.projecttest\\.demo-project) . I tested on Windows.
- Run eclipse application.
Three projects will be created, based on copied .project template. And will be left closed.
- Open first project (right after creation), the project natures will be properly applied.
It have a resource change listener that prints the logs about the natures on open action.
       NatureIds -> P/DemoProject1 [org.eclipse.cdt.core.cnature, org.eclipse.cdt.core.ccnature,…]
- Close workbench
- Relaunch eclipse Application, don’t clean the workspace. Open next project created in previous session. The natures will not be applied!
      NatureIds -> P/DemoProject2 []
- Close the project DemoProject2 and reopen. This time the natures are applied. And it means that on Project properties I have C/CPP properties on my case.
NatureIds -> P/DemoProject2 [org.eclipse.cdt.core.cnature, org.eclipse.cdt.core.ccnature,…]


What happens:
-  When the project is created first time it is missing the flag M_USED (M_USED = false), but it has the ProjectDescription object that is provided during creation, that is instantiated based on existing template, and knows about the natures. 
The workflow reaches IDEWorkbenchActivityHelper.processProjects() where natures ids array is not null, 'needsUpdates' is true. that is why if we open project now it has the natures.

- 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).

The only solution I found to fix this issue from my plugin is to use restricted API and to set flag M_USED right after project creation.
But it wouldn't like to use restricted API.

Thank you
Regards
Lidia
Comment 1 Andrey Loskutov CLA 2019-12-06 09:15:48 EST
Lidia, could you please validate this with 4.14 RC2? We had a fix via bug 544975 that could be related to your case, just wondering it helps here or not.

Also it would be helpful if you could attach the stack at the time the natures are applied (for the first and second good cases), just to be able to see it without starting debugger every time.

And finally, for those of us who do not have CDT installed by default, could you please update your example to use JDT natures instead of CDT?