Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Two input models in Acceleo(generating code from two input models...)
Two input models in Acceleo [message #1396809] Tue, 08 July 2014 20:35 Go to next message
Naif Mokhayesh is currently offline Naif MokhayeshFriend
Messages: 31
Registered: November 2011
Member
Hi,

I need to generate code from two independent models. In other word I need to use two input models each one conforming to metamodel.

for instance :

[comment encoding = UTF-8 /]
[module mainModule('ABC', 'PN')]

[template public main(aPackage : ABC::Package , aNet : PN::Net)]
[comment @main/]
......

[/template]


In Acceleo Run configuration we can only set the path of the first model (instance of the 1st meta-model) but I can not set the second meta-model.

I modified launcher java class according to http://stackoverflow.com/questions/11782134/load-2-different-input-models-in-acceleo

Moreover I have tried the suggestion in the following posts, but unfortunately I failed to pass 2 input model for the transformation

https://www.eclipse.org/forums/index.php/m/931864/?srch=two+input+models#msg_931864
https://www.eclipse.org/forums/index.php/m/769582/?srch=two+input+models#msg_769582

any example of how to pass two (independent) input models in Acceleo.

Thanks
Re: Two input models in Acceleo [message #1718230 is a reply to message #1396809] Mon, 21 December 2015 13:21 Go to previous messageGo to next message
dorraaaa Z is currently offline dorraaaa ZFriend
Messages: 29
Registered: June 2012
Junior Member
Hello,

I have the same problem, please is there someone that help us

Tahnks
Re: Two input models in Acceleo [message #1737019 is a reply to message #1396809] Tue, 05 July 2016 07:18 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Hi,

I have also the same problem, someone help me! Here is the error message: An internal error occurred during: "Launching Generate".
Could not find public template generateElement in module generate.

I have a simple code:
[comment encoding = UTF-8 /]
[**
* The documentation of the module generate.
*/]
[module generate('http://www.mm1.nl/1.0', 'http://www.mm2.com/1.0')]


[**
* The documentation of the template generateElement.
* @param aStateMachine
*/]
[template public generateElement(aStateMachine : StateMachine, st : statemachine)]
[comment @main/]
[file (aStateMachine.name, false, 'UTF-8')]
[st.s_name/]
[/file]
[/template]

I have tried to modify Generate.java as mentioned in the links provided above. How can I handle this problem?
Re: Two input models in Acceleo [message #1737025 is a reply to message #1737019] Tue, 05 July 2016 07:56 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

This is a basic use case that should be working seamlessly. "Could not find public template generateElement in module generate." means that you likely haven't exported the package containing your main template (see the MANIFEST.MF file, on the "runtime" tab). Likewise, your generator project needs to have dependencies ("dependencies" tab of the same file) on the projects that contain your two metamodels.

If you've properly set that up, please provide us with a sample with which we can reproduce the issue.

Laurent Goubet
Obeo
Re: Two input models in Acceleo [message #1737039 is a reply to message #1737025] Tue, 05 July 2016 09:11 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Hi Laurent,

The package containing the main template is exported. I will attach the entire project so that you can reproduce the error and see the problem. You can find the models and meta-models in the models folder.

Thanks in advance,
Habtamu

[Updated on: Wed, 06 July 2016 08:56]

Report message to a moderator

Re: Two input models in Acceleo [message #1737056 is a reply to message #1737039] Tue, 05 July 2016 11:48 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
I can't reproduce exactly the issue since I'm missing quite a few bits (I don't have a workspace with both gmf and acceleo and you also have a hardcoded url to a sc model in the generate.java) but... There are quite a few things here that will rub acceleo the wrong way.

First things first, we recommand not to have the metamodels in the same workspace as your generators, since this will have us compile them with incorrect URIs in the references. You should have the metamodels in a first workspace, then use a runtime eclipse application to develop your generators (or have the metamodel plugins installed in the eclipse you use to develop the acceleo generators) in order to avoid these issues.

Second, Acceleo requires you to have generated the code of your metamodels before using them. As I see it you only have the ecore files but haven't generated the model code.

Please look into these first and see if it solves the issue.

Laurent Goubet
Obeo
Re: Two input models in Acceleo [message #1737059 is a reply to message #1737056] Tue, 05 July 2016 12:12 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Hi Laurent, I just put meta-models if you want to reproduce the issue. For myself, I have metamodel plugins installed. For gmf, you can open the file and remove the gmf part of the model. I will remove and attach the file so that you don't need gmf. My problem here is when I have two models not with one model. With one model, it works perfectly. How can I use two models in acceleo since it is not possible to tell the second model in acceleo launcher? I have tried to modify generate.java to load the second model but that is not working.

Thanks,
Habtamu

[Updated on: Wed, 06 July 2016 08:57]

Report message to a moderator

Re: Two input models in Acceleo [message #1737065 is a reply to message #1737059] Tue, 05 July 2016 12:44 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
By the way two of the instance models i want to use are Sensor.im.asd and Sensor.sc, so in the hard-coded part in Generate.java should be replaced with the path of one of these two models.

Thanks!
Re: Two input models in Acceleo [message #1737070 is a reply to message #1737065] Tue, 05 July 2016 13:14 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Okay, sorry I misunderstood the state you were in.

All you need to do in your case is push another argument into the list of parameters to your main template, as states on the stackoverflow answer linked in the first post here. You can do so by simply overriding "getArguments" in the generated launcher. Something like the following will work (I've also overriden "postInitialize" to make sure I only load the additional model once):

    private EObject additionalArgument;

    @Override
    protected void postInitialize() {
    	super.postInitialize();
    	Resource modelResource = model.eResource();
    	URI modelURI = modelResource.getURI();
    	URI additionalModel = modelURI.trimSegments(1).appendSegment("Sensor.sc");
    	try {
			EObject additionalModelRoot = ModelUtils.load(additionalModel, modelResource.getResourceSet());
			EObject statemachine = null;
			Iterator<EObject> children = additionalModelRoot.eAllContents();
			while (children.hasNext() && !(statemachine instanceof sc.statemachine)) {
				statemachine = children.next();
			}
			if (statemachine instanceof sc.statemachine) {
				additionalArgument = statemachine;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    @Override
    public List<? extends Object> getArguments() {
    	List<Object> args = new ArrayList<>();
    	args.add(additionalArgument);
    	return args;
    }



Laurent Goubet
Obeo
Re: Two input models in Acceleo [message #1737074 is a reply to message #1737070] Tue, 05 July 2016 13:53 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Hi Laurent,

Thank you very much! I have no package called sc and class called statemachine. What should I do to reference them? Are they supposed to be referenced from the plugin that I already created for the meta-model?

Thanks in advance!
Re: Two input models in Acceleo [message #1737075 is a reply to message #1737074] Tue, 05 July 2016 14:10 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
They are references to your metamodel's generated code. As I mentionned above you really should generate its code for Acceleo to work properly. You could also ignore that part and manually select the one object you want to pass as second parameter (the statemachine from the "Sensor.sc" model), but I don't know if it'll work without the code being generated.

You mentionned that you had the metamodels installed, the "sc.statemachine" class should be in there, but you need a direct dependency towards your metamodel plugins in order to have it available.

Laurent Goubet
Obeo
Re: Two input models in Acceleo [message #1737119 is a reply to message #1737075] Tue, 05 July 2016 21:23 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Thank you! Now it runs without error, but it cannot generate a text. One thing I did was that I changed the order of the arguments in template because it generate error " Argument types mismatch for module element generateElement."
[comment encoding = UTF-8 /]
[**
 * The documentation of the module generate.
 */]
[module generate('http://www.altran.nl/verum/asd/1.0', 'http://www.conformiq.com/EMF/1/SimpleStatechart')]


[**
 * The documentation of the template generateElement.
 * @param aStateMachine
 */]
[template public generateElement(st : statemachine , aStateMachine : StateMachine)]
[comment @main/]
[file (aStateMachine.name, false, 'UTF-8')]
[aStateMachine.name/]
[/file]
[/template]


Any idea why it doesn't generate text?

Thanks in advance!
Re: Two input models in Acceleo [message #1737143 is a reply to message #1737119] Wed, 06 July 2016 06:42 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

If it does call your template (and creates the file), but doesn't generate text, your issue is that "aStateMachine.name" is empty. That was the case when I tried your generator at least. Try inputting static text in there:

[file ('static_file_name', false, 'UTF-8')]
static text field
[aStateMachine.name/]
[/file]


Laurent Goubet
Obeo
Re: Two input models in Acceleo [message #1737149 is a reply to message #1737143] Wed, 06 July 2016 07:01 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
hi Laurent,

It does not create a file at all. Sorry I did't make that clear.

Thanks in advance!
Re: Two input models in Acceleo [message #1737165 is a reply to message #1737149] Wed, 06 July 2016 08:09 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Have you tried with a static name for your file as in the exceprt above?
Re: Two input models in Acceleo [message #1737169 is a reply to message #1737165] Wed, 06 July 2016 08:22 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
Yes I did.
[comment encoding = UTF-8 /]
[**
 * The documentation of the module generate.
 */]
[module generate('http://www.altran.nl/verum/asd/1.0', 'http://www.conformiq.com/EMF/1/SimpleStatechart')]


[**
 * The documentation of the template generateElement.
 * @param aStateMachine
 */]
[template public generateElement(st : statemachine , aStateMachine : StateMachine)]
[comment @main/]
[file ('test.java', false, 'UTF-8')]
int y;
int x;
[/file]
[/template]


Thanks!
Re: Two input models in Acceleo [message #1737209 is a reply to message #1737169] Wed, 06 July 2016 12:47 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Then most likely you're generating the file someplace you're not expecting Smile.

http://i.imgur.com/UphcSYv.png

The "target" field here is the folder in which your file(s) will be generated. It's workspace-relative.
Re: Two input models in Acceleo [message #1737218 is a reply to message #1737209] Wed, 06 July 2016 13:02 Go to previous messageGo to next message
Habtamu Tolera is currently offline Habtamu ToleraFriend
Messages: 20
Registered: June 2016
Junior Member
I don't think so! When you successfully generate a file, you normally see a confirmation that a file has generated in certain amount of time. This is not the case now.
Re: Two input models in Acceleo [message #1737225 is a reply to message #1737218] Wed, 06 July 2016 13:25 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
With the configuration above, and the template you initially provided me, Acceleo properly generates a file in the "gen" folder as specified. If it's not doing it for you then you either have something logged in your error log or a file generated somewhere unexpected. The confirmation telling you that a file generation happened is not foolproof and will not be shown on some launch configs.
Previous Topic:[Acceleo 3] Multiple metamodels
Next Topic:UML metamodel not found in createing Acceleo project
Goto Forum:
  


Current Time: Thu Mar 28 22:18:41 GMT 2024

Powered by FUDForum. Page generated in 0.05343 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top