Bug 479726 - AQL : meta model are not correctly registered for Interpreter at session opening when there is no selected Viewpoint
Summary: AQL : meta model are not correctly registered for Interpreter at session open...
Status: REOPENED
Alias: None
Product: Sirius
Classification: Modeling
Component: Core (show other bugs)
Version: 3.0.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: Next   Edit
Assignee: Maxime Porhel CLA
QA Contact:
URL:
Whiteboard: backport
Keywords: triaged
Depends on: 474807 477217 477596
Blocks: 542859 576446
  Show dependency tree
 
Reported: 2015-10-14 04:57 EDT by Laurent Fasani CLA
Modified: 2021-10-06 09:44 EDT (History)
3 users (show)

See Also:


Attachments
metamodel garden (37.92 KB, application/zip)
2015-10-14 04:59 EDT, Laurent Fasani CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Laurent Fasani CLA 2015-10-14 04:57:47 EDT
Scenario:

1 create a modeling project with the following model
meta-modele : A contains a list of B (you can use the following attached meta model)
modele : A1 contains B1 and B2
2 activate a viewpoint for this meta-model
3 From Interpreter view, select A1 and type the following query
aql:self.eContents()->filter(myMetaModel::B) -> it works 
4 Close and reopen the project
5 redo step3 -> nothing is displayed in Evaluation Result. There is no message in error log
6 Add and remoce the VP on this project. Redo step3 -> it works

It seems that meta-model are not correctly registered at session open but only if a VP is applied manually on the modeling project.

Note that the issue is not specific to filter but all as soon as myMetaModel:: is used
Comment 1 Laurent Fasani CLA 2015-10-14 04:59:52 EDT
Created attachment 257254 [details]
metamodel garden
Comment 2 Maxime Porhel CLA 2015-10-14 05:02:50 EDT
This comes from org.eclipse.sirius.common.tools.api.interpreter.JavaExtensionsManager.reloadEPackages() which does nothing when there is no activated Viewpoints.

> AQLSiriusInterpreter$3.loaded(String, EPackage) line: 135	
> JavaExtensionsManager.loadedEPackage(EPackage) line: 430	
 >JavaExtensionsManager.reloadEPackages() line: 333	
> JavaExtensionsManager.reloadIfNeeded() line: 237	
> AQLSiriusInterpreter.evaluateExpression(EObject, String) line: 200	
> ODesignGenericInterpreter.evaluateExpression(EObject, String) line: 124	
> SiriusEvaluationTask.call() line: 121	


See: this.classLoading.findEcoreDeclarations(this.viewpointProjects, this.viewpointPlugins);
Comment 3 Eclipse Genie CLA 2015-10-28 16:48:55 EDT
New Gerrit change created: https://git.eclipse.org/r/59175
Comment 4 Maxime Porhel CLA 2015-10-28 17:03:31 EDT
Two workaround to make this work:

 . Complete VSM plugin dependencies with the meta-models plug-ins.
 
 . Second possibility if the metamodel is deployed, use the "Add package from registry" button in the Metamodels properties tab of each representation description. This make the dependency to the metamodel plugin(s) optional (until you write Java services without importing required packages in the MANIFEST.MF). 



The proposed gerrit patch set modify several entries in the documentation to recommend to add the metamodels in the dependencies of the VSP. 
I will create a new bugzilla will be created to think about a proper enhancement of the situation: Acceleo3 does not require to explicitly depends on the metamodel of the evaluation context, the completion and validation for domain types and interpreted expression are not consistent with the runtime behavior of the AQL interpreter. 

Note that this mainly impact new simple project as advanced project will often declares Java service or other elements requiring those dependencies.
Comment 6 Pierre-Charles David CLA 2015-10-29 10:34:29 EDT
The reasons for the bug are now better understood, but for 3.1.1 we'll only document the workaround (explicitly add the dependencies to the meta-models' plug-in in the VSP). Moving to 3.1.2 to re-evaluate what an actual fix would look like (it's probably tricky as it will impact JavaExtensionManager).
Comment 7 Laurent Fasani CLA 2016-04-27 04:33:07 EDT
It seems that the problem is worst than the original scenario. Even deactivating/activating the VP, the MM is not found.

Otherwise, a first analysis has been done through the bug 481849, 488094 and 488299. It shows that the change needed to fix this issue is heavy, risky and could break API for IInterpreter or IInterpreterContext

The plan for the next releases (described in https://git.eclipse.org/r/#/c/66188/) is 
* add documentation (done in this bug)
* help specifier register its MM in RepresentationDescription and as dependency of the VSP
* make sirius simplier and more robust considering that sirius is based and that MM registration constraint

As a conclusion, the best for now is to settle with the documentation in 3.1.x version(that shows the good practices which solve the issue of this bug) and not do more in 3.1.
Comment 8 Laurent Fasani CLA 2016-04-28 05:59:07 EDT
(In reply to Laurent Fasani from comment #7)
> It seems that the problem is worst than the original scenario. Even
> deactivating/activating the VP, the MM is not found.
> 
> Otherwise, a first analysis has been done through the bug 481849, 488094 and
> 488299. It shows that the change needed to fix this issue is heavy, risky
> and could break API for IInterpreter or IInterpreterContext
> 
> The plan for the next releases (described in
> https://git.eclipse.org/r/#/c/66188/) is 
> * add documentation (done in this bug)
> * help specifier register its MM in RepresentationDescription and as
> dependency of the VSP
> * make sirius simplier and more robust considering that sirius is based and
> that MM registration constraint
> 
> As a conclusion, the best for now is to settle with the documentation in
> 3.1.x version(that shows the good practices which solve the issue of this
> bug) and not do more in 3.1.

The previous comment #7 is out of subject.
Just consider a modeling project with some semantic resources and without any activated VP.
When evaluating an aql expression, the interpreter of the Sirius session(or at least the acceleo queryEnvironment) should know about all meta-models of the EObject contained in the semantic models of the session. Note that the search can't rely on the activated VP because there can be none.

The question is : how to efficiently retrieve that MMs. I guess that navigating on eAllContent of the root object is a bad idea.
Comment 9 Eclipse Genie CLA 2016-04-28 10:09:14 EDT
New Gerrit change created: https://git.eclipse.org/r/71610
Comment 10 Laurent Fasani CLA 2016-04-29 05:26:26 EDT
If we want to be strictly aware about the semantic meta-models of the semantic objects, we have to :
1- get MM EPackage of all semantic instances at session opening or when adding a new semantic resource. Basically, it does an eAllContents.
2- update MM on each addition of semantic object. Indeed the new objects can belong to another MM. To do that we could use a SemMMContentAdapter on the semanticResources that manage the semantic MM list. To go forward, note that we could limit the number of notifier for that adapter, if we could assume, with a static analysis of the mm, that the contained objects of a semantic object1 are instances of classes of the same MM than object1. (cf [DRAFT] Scoped content adapter https://github.com/pcdavid/org.eclipse.sirius/commit/2f6e107303a17191e748869eea5a6c614a1f3275)
3- update MM on each removal of semantic object. the MM is deactivated only if the removed object is the last for its MM. To do that, we need a map MMToObjectsInstanceOfClassesOfThisMM which would be managed by the SemMMContentAdapter.

1-It represents about 1% a the total time of the session opening. That is accepatble
2 and 3- We try to limit the number of Adapter and especially ContentAdapter in sirius session so, that subject has to be discussed with Sirius team. Moreover, that cases(2-3), when during the lifecycle of the session, the semantic metamodel used in the session are changed because of object removal or addition, practically never occur except at the very beginning of the project because objects are not yet instanciated. In top of that, a workaround for 2-3 cases is to close and reopen session to get the updated semantic meta-models
Comment 11 Pierre-Charles David CLA 2016-05-10 08:57:46 EDT
With bug #481849 we're moving towards an approach with less "magic" where Sirius tries to approximate which MMs are needed, and instead encourage/force specifiers to be explicit in which MMs they need. If Sirius would continue to try to infer which MMs should be enabled based on completetly different sources, why would specifiers bother with configuring anything?

Anyway, the more global issue about which MMs are registered/visible at any point in time and in code is a very complex one. It's too late in the 4.0 cycle to change things in a way that may be reverted in a later version once we have thought more about it. Moving this ticket to 4.1, where it may or may not be implemented, but at least it will be used as a source of concrete data to fuel the discussion about what should be done.
Comment 12 Pierre-Charles David CLA 2017-02-28 08:35:07 EST
Moving out of 5.0. It made sense in the more global theme of enforcing explicit declaration of the metamodels in the VSMs, but I already removed those other tickets for lack of time.