Chapter 3. Execution

Kermeta workbench allows to run your Kermeta code in several ways.

3.1. Using a Run configuration

For those who already know how to run Java applications, this is a similar approach but for Kermeta files.

You'll need to create a new run configuration from the "Run/Run..." menu.

Run menu

Figure 3.1. Run menu


[Caution]Caution
The run menu is available only with some perspectives. If you don't see the run menu, switch to the Kermeta perspective.

In the dialog, you selects the file, the main class and the main operation that must be run.

Search buttons will help you to find these elements in your files.

[Caution]Caution
The search button may not work properly if your file contains errors.
Kermeta run configuration - main tab

Figure 3.2. Kermeta run configuration - main tab


Two annotations in your Kermeta code allow you to save time while creating run configurations. The @mainClass and @mainOperation are used to fill field when creating a new configuration.

Ex:

@mainClass "automaton::Derterminization"
@mainOperation "main"

Then, once you have your configuration, you can run it by all the means provided by Eclipse. Ie. "Run Last Launched", " Run History", ... available in the menus or in the toolbars.

[Tip]Tip
A shortcut allows you to quickly start a Kermeta run configuration. It is available in the popup menu of *.kmt files. The " Run As/Kermeta App " button runs an existing configuration and the " Run As/Run... " button opens the configuration dialog.
Run shortcut to run configuration on the kmt files

Figure 3.3. Run shortcut to run configuration on the kmt files


The operation arguments field allow you to pass some strings as parameters of the operation you are launching.

Optionnaly, in the common Tab of the Kermeta run configuration, you can:

  • save your configuration in a file, so you can share it with other users: in "Common" tab button "Shared file"

  • specify where the stdio outputs must be sent. Typically, this can be in the Eclipse console or in a file.

3.2. Run using a ant file

It is possible to run a Kermeta program from ant using the RunCommandLine.java from a java task.

You'll have to correctly set the classpath and the argument

[Give more details on that]

[Warning]Warning
This method need to know precisely which jar you use. If you update any of the required plugins (kermeta, emf, ecore , ...) the directory containing the jar will change because eclipse uses the version number as part of the directory name. You'll have to manually change your ant file in order to reflect the update.

3.3. Run the interpreter with a Java command line

The Interpreter provides different facades in order to run a Kermeta program. The RunCommandLine class allows to pass the name of: the Kermeta source file, and optionnaly the name of the class and the opertation to run.

You can create a Java application LaunchConfiguration that will run the interpreter with your Kermeta file.

Java run configuration main tab

Figure 3.4. Java run configuration main tab


Be careful, you must select "Include external jars when searching for a main class".

Java run configuration arguments

Figure 3.5. Java run configuration arguments


The output level of interpreter traces can be set using a log4j configuration file. The concrete file to use is set by the java property "kermeta.log4j.configurationfile.name". A sample of log4j configuration file is located in the textEditor plugin.

Exemple add the following in the VM arguments box: -Dkermeta.log4j.configurationfile.name= "../../plugins/fr.irisa.triskell.kermeta.texteditor_0.0.4/kermeta_log4j_configuration.xml"

The classpath must be carefully set using the jar of Kermeta, the jar of Ecore and of emf.

Java run configuration classpath (using the interpreter jars in the texteditor)

Figure 3.6. Java run configuration classpath (using the interpreter jars in the texteditor)


[Tip]Tip
This RunCommandLine class or one of its sibling can also be used by any of your java programs.For more information please see the Javadoc reference of RunCommandLine.
[Warning]Warning
This method need to know precisely which jar you use. If you update any of the required plugins (kermeta, emf, ecore , ...) the directory containing the jar will change because eclipse use the version number as part of the directory name. You'll have to manually change to ant file in order to reflect the update.

3.3.1. Command line options

The command line needs several options to run properly a kermeta program.

.

  • -C : (takes 1 argument) Qualified name of the class to run

    ex: myPackage::MyClass

    Note that it will not instanciate the class (ie. self will return void)

  • -H : (takes 0 argument) Display the help

  • -T : (takes 0 argument) Run as a test suite

  • -P : (takes 0 argument) Display Profiling info

  • -K : (takes 1 argument) Location for kermeta standard unit(framerwork.km) (KermetaUnit.STD_LIB_URI variable)

  • -O : (takes 1 argument) Name of the operation to run

  • -U : (takes 1 argument) URI of the unit file that must be loaded

  • -M : (takes 1 argument) Indicate a file containing URI_MAP (This is usefull to solve some model loading troubles)

Other values on the command line will be passed as string to the operation

Exemple of arguments for a kermeta program:

-P -U ../ModelEngineeringCourse/transfo/add_observer.kmt -C pattern_macros::Main -O main -K lib/framework.km ../models/needs_observer.ecore Compteur Afficheur 

3.3.2. About the URI map

When you run a kermeta program outside of Eclipse, the uri of type platform:// are not correctly resolved.

This option allow to specify a file that contains mapping to help to resolve those uri.

This uri map file uses the syntax of java properties files.

Exemple of uri.map file which maps some platform:// urls into file:// urls

#
"platform:/plugin/fr.irisa.triskell.kermeta/"        "file:/C:/eclipse3.0.2/eclipse/plugins/fr.irisa.triskell.kermeta_0.0.16/"
"platform:/resource/fr.irisa.triskell.kermeta/"        "file:/C:/eclipse3.0.2/eclipse/workspace/fr.irisa.triskell.kermeta/"