Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Acceleo/FAQ

< Acceleo
Revision as of 08:03, 24 June 2010 by Unnamed Poltroon (Talk) (New page: =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...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 {
     registerResourceFactories();
     registerPackages();
     registerLibraries();
 
     super.execute();
   }
 
   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'.");
     }
   }
 }

Back to the top