[Acceleo] Launch a transformation by code [message #799133] |
Wed, 15 February 2012 13:38 |
JM Gauthier 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 #800814 is a reply to message #800589] |
Fri, 17 February 2012 14:38 |
JM Gauthier 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!
|
|
|
Powered by
FUDForum. Page generated in 0.04172 seconds