Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Launch a transformation by code
[Acceleo] Launch a transformation by code [message #799133] Wed, 15 February 2012 13:38 Go to next message
JM Gauthier is currently offline JM GauthierFriend
Messages: 25
Registered: June 2011
Junior Member
Hi,

I am working on a transformation M2T with Acceleo, and I would like to transform a xmi file myFile.xmi which is conform to a meta model into a vhdl-ams file. The transformation work fine with the Run Configuration from Eclipse. But now I wish to automate this transformation by java code.

I am trying to use the java class generated by Acceleo like this :

URI modelURI = URI.createFileURI("/test/myFile.xmi");
File folder = new File("/test/");
List<String> arguments = new ArrayList<String>();

Xmi2Vhdlfile generator = new Xmi2Vhdlfile(modelURI, folder, arguments);
generator.doGenerate(new BasicMonitor());


This code is situated in another class in order to launch the transformation from a plugin.

Actually, I am trying to do as the main in the Xmi2Vhdlfile.java. Moreover, I use the registerPackages method as it is explain to register my Vhdlams meta model:

if (!isInWorkspace(VhdlamsPackage.class)) {
                 // The normal package registration if your metamodel is in a plugin.
                 resourceSet.getPackageRegistry().put(VhdlamsPackage.eNS_URI, VhdlamsPackage.eINSTANCE);
             } else {
                 // The package registration that will be used if the metamodel is not deployed in a plugin.
                 // This should be used if your metamodel is in your workspace and if you are using binary resource serialization.
                 resourceSet.getPackageRegistry().put("/myproject/MyVhdlMetamodel.ecore", VhdlamsPackage.eINSTANCE);
            }


The problem is when the code above is launched, I get the classic error :

The generation failed 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. It could also come from a missing [comment @main/]
in the template used as the entry point of the generation.


What is weird, is that the vhdlams metamodel is well registered in the EMF Registry..

So, is my code correct to do the transformation ? Is it a good practice ?(like the main method)
Moreover do I have to use the registerResourceFactories method to explain Acceleo that my source model is a xmi file ?

Thanks for advance.

Edit : I am using Acceleo SDK 3.2.0 with Eclipse Indigo MDT SR1

[Updated on: Wed, 15 February 2012 13:50]

Report message to a moderator

Re: [Acceleo] Launch a transformation by code [message #800589 is a reply to message #799133] Fri, 17 February 2012 08:50 Go to previous messageGo to next message
JM Gauthier is currently offline JM GauthierFriend
Messages: 25
Registered: June 2011
Junior Member
Hi,

I can do a minimalist project with a Xmi file and a little meta model if necessary...

Thanks!
Re: [Acceleo] Launch a transformation by code [message #800775 is a reply to message #800589] Fri, 17 February 2012 13:33 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

This issue is mostly related to the use of the binary serialization with a meta-model in the workspace. You should change this setting by right clicking on your Acceleo project then Properties -> Acceleo and change the serialization to XMI. XMI is now the default setting since Acceleo 3.1.1.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau & @acceleo
Google+: stephane.begaudeau & acceleo
Blog: http://stephanebegaudeau.tumblr.com
Acceleo Documentation: http://docs.obeonetwork.com/acceleo
Re: [Acceleo] Launch a transformation by code [message #800814 is a reply to message #800589] Fri, 17 February 2012 14:38 Go to previous message
JM Gauthier is currently offline JM GauthierFriend
Messages: 25
Registered: June 2011
Junior Member
Hi,

So for those who have the same problem, the following explains my errors :

First, the acceleo project which contains the .mtl file must be configured with XMI serialization (right-click on the project -> Acceleo Compiler -> Check XMI).

Then I have generated the Acceleo UI (New->Other->Acceleo Model to Text -> Acceleo UI Launcher Project). This will generate a plugin which contains several java classes.
Then instead of using the java generated by Acceleo with the .mtl file, I have used the GenerateAll.java class generated by the Acceleo UI project. Moreover I have taken the piece of code of the Action class (generated by the Acceleo UI Project too) to launch the transformation :

RunnableWithProgress operation = new IRunnableWithProgress() {
    public void run(IProgressMonitor monitor) {
        URI modelURI = URI.createPlatformResourceURI("YOUR MODEL PATH", true);
	List<String> arguments = new ArrayList<String>();
	try {
		IContainer target = project.getFolder("YOUR TARGET FOLDER");
		GenerateAll generator = new GenerateAll(modelURI, target, arguments);
		generator.doGenerate(monitor);
	} catch (IOException e) {
		IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
		Activator.getDefault().getLog().log(status);
	}
     }
};
try {
	PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
} catch (InvocationTargetException e) {
	IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
	Activator.getDefault().getLog().log(status);
} catch (InterruptedException e) {
	IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
	Activator.getDefault().getLog().log(status);
}


This piece of code can be placed wherever to launch the transformation.

Finally, I don't use the registerPackages method anymore, cause my metamodel is registered via an extension point : org.eclipse.emf.ecore.generated_package

I would like to thanks Stéphane Bégaudeau for his help this morning!

Thank you Stéphane for all your explanations!! I was blocked long time on this problem and you take time for this. I appreciate a lot!

Previous Topic:[Acceleo] running an installed module from workbench
Next Topic:[Acceleo] Tool chain
Goto Forum:
  


Current Time: Fri Apr 26 04:23:24 GMT 2024

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

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

Back to the top