Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 525466

Summary: Converting project to modeling project may fail to create the aird file
Product: [Modeling] Sirius Reporter: Pierre Guilet <pierre.guilet>
Component: CoreAssignee: Pierre Guilet <pierre.guilet>
Status: CLOSED FIXED QA Contact: Maxime Porhel <maxime.porhel>
Severity: normal    
Priority: P3 CC: julien.dupont, maxime.porhel, pierre-charles.david, romain.guider
Version: 5.1.0Keywords: triaged
Target Milestone: 5.1.3   
Hardware: PC   
OS: Windows NT   
See Also: https://git.eclipse.org/r/126327
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=bac023110798111100de5f1bc1233a87f99ce285
https://git.eclipse.org/r/126789
https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/commit/?id=2fe4add651af8847888248dc9ae6d81ffa9b9993
Whiteboard:
Bug Depends on:    
Bug Blocks: 537187, 537188    

Description Pierre Guilet CLA 2017-10-02 11:49:10 EDT
When converting projects like default project or java project to modeling one, the aird may not be created.

Steps to reproduce:
1-Close all editors
2-Be on modeling perspective with Model Explorer view
3-Close your RCP
4-Launch it
5-Right click on Model explorer view>new>project>general>project
6-Convert the newly created project to modeling project

The aird should not be created. But the problem may be random.
Comment 1 Pierre Guilet CLA 2017-10-03 05:57:35 EDT
The problem is hardly reproducible.
I could not reproduce it anymore.
Comment 2 Julien Dupont CLA 2017-10-03 11:22:31 EDT
To reproduce: 
- Open Modeling perspective
- In the model Explorer view create a General Project.
- Convert it to Modeling Project. Does not create a representation file(aird)
- Create a Java Project.
- Convert it to Modeling Project. Create a representation file (aird). KO
Comment 3 Julien Dupont CLA 2017-10-03 11:25:42 EDT
Ignore previous comment
To reproduce: 
- Open Modeling perspective
- In the model Explorer view create a General Project.
- Convert it to Modeling Project. Does not create a representation file(aird) KO
- Create a Java Project.
- Convert it to Modeling Project. Create a representation file (aird).
Comment 4 Pierre-Charles David CLA 2017-10-04 07:10:08 EDT
I can't reproduce. I tried the scenario 10 successive times and it always work. I don't know if it can make a difference but I'm under Linux.
Comment 5 Romain Guider CLA 2018-07-19 04:55:26 EDT
I manage to reproduce it with two different scenarios (on windows 10): 

whatever perspective you're in (plug-in, java or modeling) : 
- create a plug-in project (not a java project, but a plug-in project)
- right clic on the project 
- select the menu 'Configure>Convert to modeling project'

the result of this scenario seems to be : 
- the modeling nature is added to the project (according to the M decorating the project's icon in the project explorer)
- the aird file isn't added to the project. 

When creating a java project and converting it to modeling nature right away, there's no problem. However, the following scenario allows to reproduce on a java project : 
- create a java project, 
- create a plug-in project,
- try to convert the java project in modeling project

the last operation fails the same way it fails on the plug-in project of the first scenario. 

I tried other scenarios and it seems that the direct proximity of the plug-in project creation is at the origin of the problem:

- create a plug-in project, 
- create a java project,
- convert the plug-in project in modeling project

In this scenario, the last operation works like a charm.
Comment 6 Romain Guider CLA 2018-07-19 05:01:36 EDT
(In reply to Romain Guider from comment #5)
> I manage to reproduce it with two different scenarios (on windows 10): 
> 
> whatever perspective you're in (plug-in, java or modeling) : 
> - create a plug-in project (not a java project, but a plug-in project)
> - right clic on the project 
> - select the menu 'Configure>Convert to modeling project'
> 
> the result of this scenario seems to be : 
> - the modeling nature is added to the project (according to the M decorating
> the project's icon in the project explorer)
> - the aird file isn't added to the project. 
> 
> When creating a java project and converting it to modeling nature right
> away, there's no problem. However, the following scenario allows to
> reproduce on a java project : 
> - create a java project, 
> - create a plug-in project,
> - try to convert the java project in modeling project
> 
> the last operation fails the same way it fails on the plug-in project of the
> first scenario. 
> 
> I tried other scenarios and it seems that the direct proximity of the
> plug-in project creation is at the origin of the problem:
> 
> - create a plug-in project, 
> - create a java project,
> - convert the plug-in project in modeling project
> 
> In this scenario, the last operation works like a charm.

One additional information : these scenarios works perfectly well on a linux box that we tried.
Comment 7 Pierre Guilet CLA 2018-07-19 09:36:02 EDT
The problem comes from bad thread synchronization between org.eclipse.sirius.ui.tools.api.views.modelexplorerview.resourcelistener.DefaultModelingProjectResourceListener

org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.manager.ModelingProjectManagerImpl

Both are called when converting in a separate thread. 

And both call ModelingProject.getMainRepresentationsFileURI()

The call order depends on unknown variable and can differ from one environment to another.

In both case getMainRepresentationsFileURI is called whereas the representation is not created yet. So it set the valid boolean to false and throw an exception.

ModelingProjectManagerImpl needs the valid boolean to true to have the exception to create the representation when converting.

So if DefaultModelingProjectResourceListener comes first then nothing is done.
Comment 8 Eclipse Genie CLA 2018-07-19 09:48:17 EDT
New Gerrit change created: https://git.eclipse.org/r/126327
Comment 10 Pierre Guilet CLA 2018-07-20 09:09:09 EDT
Steps to reproduce:
1-Do a remote debug on the Sirius bundle
2-Activate a breakpoint at the beginning of org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.manager.ModelingProjectManagerImpl.doAddModelingNature(IProject, IProgressMonitor)
3-Create a plugin project
4-convert it to modeling project
5-the breakpoint hit. Resume
6-The aird should be created.
Comment 11 Maxime Porhel CLA 2018-07-30 04:32:29 EDT
On MacOs at least, when I create a plugin project and then convert it to a modeling project, the aird is well created but I have an error marker on the project "Zero representations file found in "mysampleproject".

Note that the issue seems not always reproductible as the initial issue of this ticket.
Comment 12 Eclipse Genie CLA 2018-07-30 10:22:40 EDT
New Gerrit change created: https://git.eclipse.org/r/126789
Comment 14 Maxime Porhel CLA 2018-07-31 04:10:40 EDT
Validated on Sirius 5.1.3-N20180731-035556
Comment 15 Pierre-Charles David CLA 2018-08-01 03:38:44 EDT
Available in Sirius 5.1.3, see https://wiki.eclipse.org/Sirius/5.1.3 for details.