Export a generator as an Eclipse Plug-in

Abstract
This document explains how one may export a generator as a Plug-In. The generator is then deployable in any Eclipse instance.
It describes the process to export the generator and the use of the Module Launcher helping users to setup a generator project in a few clicks


Cédric Brun, Obeo (France)

Generator settings

Every Acceleo generator project is also an Eclipse Plug-In project. It means the generator has a plugin.xml file and a Manifest.mf file in its META-INF folder

Plug-In Settings files
Figure :Plug-In Settings files

In order to be buildable as a plugin, an Acceleo generator should extend the fr.obeo.acceleo.gen.module extension point.

In order to do that, edit the Manifest.mf file , then clic on the Extensions tab, then on Add....

Add extension
Figure :Add extension

Now choose the fr.obeo.acceleo.gen.module extension point and click on Finish.

You should now create a module child by right-clicking on the extension point.

Creating a module
Figure :Creating a module

The module settings are only used by the Module Launcher, which use is described in the last part of this tutorial. If you don't need the Module Launcher then setting accurate property values here is not mandatory.

Module default settings
Figure :Module default settings
Exported files during the build
Figure :Exported files during the build
Make sure all the files used in the generator are exported, check in the build tab that every required file is checked, especially the .mt files and the plugin.xml file.

Export the generator

Building a generator follows the same process as building a standard Eclipse plugin. Right-click on the project and choose Export... then Deployable plug-ins and fragments.

Export as plugin></td>
        </tr>

        <caption align= Figure :Export as plugin

Click on "Next"

Build settings
Figure :Build settings
Build settings
Figure :Build settings (next)

Eclipse will start building the project as soon as you click on Finish. A Jar file will be created in the output folder.

Builded plugin
Figure :Builded plugin

You may install this plugin in any Eclipse instance by copying the file in its plugins folder.

Settings for the Module Launcher

With a few more settings you'll be able to use the project initialization environment : the Module Launcher.

The Module Launcher provides ready to use generators. It will provide yours according to the following conditions :

  • You have to define a generic chain file with parameters.
  • You have to describe this parameters in the fr.obeo.acceleo.gen.module extension point.

Start by creating a .chain file launching the generation and put it in any folder of your generator project (here we chose the default folder).

Creating a generic chain file Figure :Creating a generic chain file

Then you have to define the needed parameters by editing the Parameter Files attribute of the .chain file root element. Here our generator needs 3 parameters : the input model, the output folder and the log file.

.chain parameters
Figure :.chain parameters

You now need to describe these parameters in the extension point, then the Module Launcher will be able to prompt the user for their values.

Edit the plugin.xml file and go in the Extensions tab. Fill-in the required values for the Module: title, module's description, the path to the generic .chain file and optionally the module's category.

Module settings
Figure :Module settings

We'll now specify each .chain parameter, right click on the Module in the extensions editor and add as much children as you have parameters defined in your chain file (3 in our case).

Parameters in the extension point
Figure :Parameters in the extension point

You should define every parameter of the .chain file with its description, its type (file, folder or project), the file's extension and optionaly a default file to initialize the content.

Parameter : output folder
Figure :Parameter : output folder
Parameter : input model
Figure :Parameter : input model
The declaration order of these parameters should be the same as in the .chain parameters, these parameters will be substituted with the user values.

That's it ! You may now use the generator in a few clicks, you have to export it as a plugin and test it in a new Eclipse instance. Keep in mind to check the export parameters in the build tab, especially the fact that the default files used to initialize the parameters are exported during the build.

Exporting initialization files
Figure :Exporting initialization files

You may refer at the MindMap and Python2Ecore projects of the modules repository in order to have a working example.