Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354619 - generation fails when launched from another plugin
Summary: generation fails when launched from another plugin
Status: CLOSED FIXED
Alias: None
Product: Acceleo
Classification: Modeling
Component: Core (show other bugs)
Version: 3.1.0   Edit
Hardware: PC Windows 7
: P3 normal
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 09:28 EDT by A Vernotte CLA
Modified: 2015-05-27 08:55 EDT (History)
3 users (show)

See Also:


Attachments
plugin project that uses acceleo to generate code from metamodel instance (451.00 KB, application/octet-stream)
2011-08-12 09:30 EDT, A Vernotte CLA
no flags Details
smaller plugin project that uses acceleo to generate code (386.02 KB, application/octet-stream)
2011-08-18 05:57 EDT, A Vernotte CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description A Vernotte CLA 2011-08-12 09:28:51 EDT
I'm creating a plugin for Papyrus, in which I perform M2M and M2T. It works as follows : first, a native metamodel transformation from UML to a dedicated metamodel. Then, an extension point "modelTransformation" is set to accept model transformations from this dedicated metamodel to any other, and it has an attribute "codeGeneration" to link this transformation to a code generation module. 
I can't get to launch the code generation. I've got this error :

!ENTRY org.eclipse.acceleo.engine 2 0 2011-08-02 10:03:47.137
!MESSAGE The generation fail to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates. 
The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator.


The metamodel I use isn't registered, it would seem. But it is well registered indeed, as I used the extension org.eclipse.emf.ecore.dynamic_package to get it done, and I can tell it works because (for example) modisco browser can go through the generated xmi.

Let's see then how the code generation is executed : 
@Override
					public void run() throws Exception {
						((AbstractAcceleoGenerator) codeGen).initialize(URI.createURI(model),currentProject.getFullPath().toFile(), args);
						((AbstractAcceleoGenerator) codeGen).doGenerate(new BasicMonitor());
					}


"model" is a string containing the full name of the xmi file. 
"currentProject" is the current active IProject, I tested it and it correspond to what's expected.

I tried in the template to replace the package ns uri with a relative and an absolute path, it didn't change a thing (wasn't worse tho).

I should mention that the generation works when executed alone in my dev eclipse instance. 

--------------------------------------------------------

To test the plugin :
- create a Papyrus project, with a UML classdiagram.
- create a class, and its instance specification.
- trigger transformation and generation by clicking on the second purple button, or in the "Test Designer" Menu.
Comment 1 A Vernotte CLA 2011-08-12 09:30:45 EDT
Created attachment 201397 [details]
plugin project that uses acceleo to generate code from metamodel instance
Comment 2 Stephane Begaudeau CLA 2011-08-16 05:07:12 EDT
Hi,

I tried to use the project that you have provided but I couldn't reproduce your problem as the complexity of the example provided made me stumble on several critical errors. If you have a simpler example with just the metamodel, a model generated by your m2m system andthe generator it should be easier. I tried with the generator and models in the project and its seems that the uri are correct but the dependencies between your projects are curious (why does the project containing the metamodel depends on the code generator? and not the other way around? it should not even compile) and launching the generator created several errors (NPEs in fr.inria.uml4tst.papyrus.core.Activator#start(...)).

You could try to put a breakpoint in the initialize method, in the constructor of the generator (TMmodel), and then you should compare the uri of the type of the variable of your template and the type of the element of your model after this:

URI moduleURI = createTemplateURI(moduleURL.toString());
moduleURI = URI.createURI(moduleURI.toString(), true);
module = (Module)ModelUtils.load(moduleURI, modulesResourceSet);

URI newModelURI = URI.createURI(modelURI.toString(), true);
model = ModelUtils.load(newModelURI, modelResourceSet);
targetFolder = folder;

In theory, you should get module.getOwnedModuleElement().get(0) casted as a template (org.eclipse.acceleo.model.mtl.Template) and then use template.getParameter().get(0).getEType(). Navigate in the same way in the loaded model, and then compare the uris of the element and/or the instances of their metaclasses (their EType), if those metaclasses does not share the same uri or if their are not assignable one to the other, then there is a problem with the compilation of your modules (I doubt it since you are using xmi resources) or with the m2m transformation.

Stephane Begaudeau
Comment 3 A Vernotte CLA 2011-08-18 05:51:23 EDT
Hi,

thank you for your help. I created a simpler project, and I still get errors. I tried a lot of things : 
- tried to register the metamodel package using dynamic_package extension
- tried to register the metamodel package using generated_package (after having generated Model code from genmodel)
- tried to register xmi and tdmodel resource factories
- tried those with Acceleo compiler preference set to Binary AND xmi

Also, I tried template.getParameter().get(0).getEType(), and I got an instance of org.eclipse.emf.ecore.impl.EClassImpl name "Project", which is also the first element of my xmi file. I couldn't navigate the same way with the loaded model, although I could see that it's an instance of org.eclipse.emf.ecore.impl.DynamicEObjectImpl named "Project".


(In reply to comment #2)
> Hi,
> 
> I tried to use the project that you have provided but I couldn't reproduce your
> problem as the complexity of the example provided made me stumble on several
> critical errors. If you have a simpler example with just the metamodel, a model
> generated by your m2m system andthe generator it should be easier. I tried with
> the generator and models in the project and its seems that the uri are correct
> but the dependencies between your projects are curious (why does the project
> containing the metamodel depends on the code generator? and not the other way
> around? it should not even compile) and launching the generator created several
> errors (NPEs in fr.inria.uml4tst.papyrus.core.Activator#start(...)).
> 
> You could try to put a breakpoint in the initialize method, in the constructor
> of the generator (TMmodel), and then you should compare the uri of the type of
> the variable of your template and the type of the element of your model after
> this:
> 
> URI moduleURI = createTemplateURI(moduleURL.toString());
> moduleURI = URI.createURI(moduleURI.toString(), true);
> module = (Module)ModelUtils.load(moduleURI, modulesResourceSet);
> 
> URI newModelURI = URI.createURI(modelURI.toString(), true);
> model = ModelUtils.load(newModelURI, modelResourceSet);
> targetFolder = folder;
> 
> In theory, you should get module.getOwnedModuleElement().get(0) casted as a
> template (org.eclipse.acceleo.model.mtl.Template) and then use
> template.getParameter().get(0).getEType(). Navigate in the same way in the
> loaded model, and then compare the uris of the element and/or the instances of
> their metaclasses (their EType), if those metaclasses does not share the same
> uri or if their are not assignable one to the other, then there is a problem
> with the compilation of your modules (I doubt it since you are using xmi
> resources) or with the m2m transformation.
> 
> Stephane Begaudeau
Comment 4 A Vernotte CLA 2011-08-18 05:57:01 EDT
Created attachment 201703 [details]
smaller plugin project that uses acceleo to generate code

To make it work extract the xmi file stored in the metamodel folder of the tdmodelgen project into a papyrus project. This xmi file is legit (modisco can browse it).
Comment 5 Ronald Krijgsheld CLA 2011-11-03 13:14:00 EDT
I seem to have an identical problem. I have defined a generator module file that refers to a metamodel uri in the form of http://.....  
This uri can also be resolved as a resource in my workspace in form of a/b/c/xxx.ecore. In the emtl file the a/b/c/xxx.ecore reference is stored and not the http://.... version.

So when running in my inner workbench the resource reference cannot be found. If a manually map the resource path in the package registry the problem is solved. But, this of course is a workaround for what looks like an issue in writing the emtl file.
Comment 6 Laurent Goubet CLA 2011-11-04 04:36:56 EDT
Alexandre, Ronald,

We'll try and have a look at this. This happens with the latest version of Acceleo, or are you using an older one?
Comment 7 Stephane Begaudeau CLA 2012-02-20 03:22:06 EST
From what I have seen with an user facing a similar problem, the issue seems to come from the use of the binary resource serialization (right click on your Acceleo project -> Properties -> Acceleo and select XMI resource serialization). This issue was created by the use of binary resources as the default option in Acceleo 3.1.0 (we changed this in 3.1.1).
Comment 8 Stephane Begaudeau CLA 2012-04-20 03:57:55 EDT
I'll close this issue as it is a known limitation of binary resource serialization (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=353981), we can make it work in one environment (workspace or plugin) but not in multiple ones without heavy changes. It works with XMI-based serialization. I'll add a line about it in the new documentation. The documentation of the generated Java launcher has been updated to reflect more precisely the situation.
Comment 9 Laurent Goubet CLA 2015-05-27 08:55:21 EDT
Closing resolved bugs