Jump to: navigation, search

Difference between revisions of "Acceleo/FAQ"

m (How to write '[' or ']' in the generated code?)
Line 102: Line 102:
=How to write '[' or ']' in the generated code?=
=How to write '[' or ']' in the generated code?=
If you want to have the '[' or the ']' symbol, use ['['/] or [']'/].
'''Q''' : I need to generate open brackets ( ''['' ) or close brackets ( '']'' ) through Acceleo. How can I escape them?
'''A''' : The ''['' and '']'' symbols can be generated through respectively '''[ '[' /]''' and '''[ ']' /]'''.

Revision as of 10:53, 26 July 2010

My generation fails with a 'package not found' exception

Q : Whenever I launch an Acceleo generation, it fails with the message package with URI '*' not found'.

A : This error message indicates that the package which NsURI is '*' hasn't been registered in the Package registry. Most of the time, that means you either a) launched your program standalone and didn't register the package correctly or b) you haven't installed the plug-in that provides that metamodel.

Solving it is easy : it is a matter of registering the needed packages (and, optionally, resource factories). How is it done? Here is the most classic example with UML :

Package with uri 'http://www.eclipse.org/uml2/2.1.0/UML' not found.

What do I need to do for my UML model to be loadable :

EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE); Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);

The same goes for every metamodel you might need, simply change UMLPackage by XxxPackage according to your metamodel. The Resource Factory is mandatory for UML, but your metamodel might not need one; simply ignore this line if you don't have a custom factory.

You need these two lines to be before the point where your model is loaded. For Acceleo, this is done in the generated Java launcher : simply change the implementation of the registerPackages and registerResourceFactories method to add these needed lines.

How can I run a generation in a standalone environment?

Q : Can I run an Acceleo generation outside of Eclipse?

A : Yes, Acceleo has been developed with standalone execution in mind. All you have to do is to launch the main method of the generated Java launcher.

How can I compile my mtl files in a standalone environment?

Q : Can I use the Acceleo compiler to recompile mtl files outside of Eclipse?

A : Yes, though this requires a little more work than "simply" launching the generation. The easiest is to define your own ANT task for that job. It should extend the AcceleoCompiler ANT task that's provided along with Acceleo (the latest version of the jar containing this class can be retrieved here, or you could simply look at its source code and reproduce something similar).

The bare minimum your class would need in order to compile mtl files in a standalone environment would be :

 public class AcceleoStandaloneCompiler extends AcceleoCompiler {
   public void execute() throws BuildException {
   public void registerResourceFactories() {
     Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
     Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(IAcceleoConstants.EMTL_FILE_EXTENSION, new EMtlResourceFactoryImpl());
     // Uncomment the following if you need to use UML models
     // Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
   public void registerPackages() {
     // Uncomment if you need to use UML models
     // EPackage.Registry.INSTANCE.put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
     // Uncomment if you need to use UML models saved with on old version of MDT/UML (you might need to change the URI's version number)
     // EPackage.Registry.INSTANCE.put("http://www.eclipse.org/uml2/2.1.0/UML", UMLPackage.eINSTANCE);
   public void registerLibraries() {
     CodeSource acceleoModel = MtlPackage.class.getProtectionDomain().getCodeSource();
     if (acceleoModel != null) {
       String libraryLocation = acceleoModel.getLocation().toString();
       if (libraryLocation.endsWith(".jar")) {
         libraryLocation = "jar:" + libraryLocation + '!';
       URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/acceleo/mtl/3.0/mtlstdlib.ecore"), URI.createURI(libraryLocation + "/model/mtlstdlib.ecore"));
       URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/acceleo/mtl/3.0/mtlnonstdlib.ecore"), URI.createURI(libraryLocation + "/model/mtlnonstdlib.ecore"));
     } else {
       System.err.println("Coudln't retrieve location of plugin 'org.eclipse.acceleo.model'.");

Can Acceleo work with ClearCase?

Q : I have to (re)generate files in (a) project(s) that is versionned using ClearCase. Will Acceleo ask for check out when generating?

A : Yes, but you'll have to cope with two limitations : first, you have to change the generated Java launcher and second, you will no longer be able to launch your generations in a standalone mode. The modification that has to be done is to override the getGenerationStrategy() method of the generated launcher. Specifically, you want it to look like :

 public IAcceleoGenerationStrategy getGenerationStrategy() {
   return new WorkspaceAwareStrategy();

Do not forget to remove the @generated tag from the Javadoc of this method (or change it to @generated NOT)!

How to migrate from Acceleo 2 to Acceleo 3?

Acceleo 3 has some differences with Acceleo 2, especially for the new syntax elements based on the Model-to-text OMG standard.

The question is : How to create the 3.x '.mtl' file from the 2.x '.mt' file?


The tooling will initialize the migration process... Just right click on the Acceleo 2.x project.


We know that the migration can't be perfect, because the MTL standard is statically typed. Sometimes you need human understanding to provide the right context and get the right equivalence. You will probably have to change the way you organize your code generators. We are confident that Acceleo 2.x users will move easily to Acceleo 3.0.

Don't worry, the Acceleo Team will continue to maintain the 2.x syntax of Acceleo. However, the new major versions and the new features will take place on Eclipse.org.

There aren't a lot of differences between the old version of acceleo and the new one. It's not so long to migrate from a syntax to another. Acceleo 3.0 comes with an equivalence documentation.

How to write '[' or ']' in the generated code?

Q : I need to generate open brackets ( [ ) or close brackets ( ] ) through Acceleo. How can I escape them?

A : The [ and ] symbols can be generated through respectively [ '[' /] and [ ']' /].