Skip to content

Plugin guide for developers

stevekmcc edited this page Aug 29, 2018 · 3 revisions

This page contains information about how the plugin works, and how to modify or extend it for your own use. The plugin source code is available from here.

Launching the plugin

When the plugin starts it will search for an existing open API connection to MetaEdit+. If it finds one, it will ask for all the graphs in all opened projects in MetaEdit+ and show them in the view. If the plugin doesn’t find an API connection it will look in the root directory of the current Eclipse workspace for a settings file, ‘default.mer’, that contains MetaEdit+ launch parameters. If it finds the settings file, the plugin asks the user's permission to launch MetaEdit+, log in, open projects and start the API server in MetaEdit+.

When using the plugin for first time there is no settings file and no open API connection to MetaEdit+. In this case the plugin tries to calculate the values that are needed for launching MetaEdit+ and shows them in a dialog to user. When the user has checked and edited them if needed, MetaEdit+ can be launched by clicking the ‘Open MetaEdit+’ button. The launch parameters are also saved in the ‘default.mer’ file in the workspace root directory, and will be read when the plugin is next launched without an API connection.

Below you can see a state diagram showing the plugin initialization process.

Instructions for Metamodelers

Below you can find intructions for metamodelers. When writing generators the integration to Eclipse needs to be taken into account. The generator output location may differ from the usual generation location. Being able to generate different types of project (Java, Android, MIDP) to Eclipse, they are separated from each other by the project names. This leads to situation where Eclipse cannot expect the project name to be same as the top graph name as this used to be. Additionally, the main class name is also passed to Eclipse along the project name. The information is shared by writing it to a file named 'plugin.ini' located at MetaEdit+ working directory. The file is used to transform information in both directions between MetaEdit+ and Eclipse.

The generation and import process

The generation and import process contains stages in which the plugin writes a plugin.ini file for MetaEdit+, a generator for the selected graph is run in MetaEdit+, the generated Eclipse project (if any) is imported in Eclipse, opened, built and launched in Eclipse automatically. Let's look next at the individual states in more detail. You may also test these by running the 'Digital Watch' example available in MetaEdit+.

In the first stage a plugin.ini file for MetaEdit+ is written in the MetaEdit+ working directory. Once the user has chosen to run a generator the file is created. The plugin.ini file contains information from the application (Eclipse in this case) that calls MetaEdit+. It also contains the Eclipse workspace path in which the MetaEdit+ generator is supposed to generate the source code files. Below you can see an example of the plugin.ini file content.

IDE=eclipse
workspace=C:\user\Documents and settings\workspace\

The file and its content allow the generator in MetaEdit+ to see that it is being used from another program. The generator can thus change its behaviour, e.g. instead of compiling and opening generated code itself, it can just generate the source code and project resource files that are needed for importing and building the project in Eclipse. The plugin removes the plugin.ini file at the end of the process.

While generating the source code, MetaEdit+ writes the main class name and the project name in the ini file during the generation. Eclipse then reads these values, imports the project that is read from the file, compiles and runs the main class. In Digital Watch generators the value from the main class is left empty. This means that Eclipse will only import the generated project but it will not try to launch them.

For example normal Java project generation from Eclipse will make the generator to write in the plugin.ini file

classToLaunch=com.metacase.watch.generated.WatchModels

Android generation would cause the generator to write

classToLaunch=
projectName=WatchModels_android

that would tell the Eclipse plugin not to run any class after importing the project to Eclipse.

The project import automates manual actions like choosing to create a new Eclipse project from the File menu and going through the wizard to create a new project. While these actions could be left to the user, the plugin aims to automate integration between code generated from MetaEdit+ and Eclipse. To provide this automation the MetaEdit+ generator creates Eclipse project resource files that are needed for opening the project in Eclipse, and the Eclipse plugin provides the project import, build and launch commands.

Writing your own generator

The most common scenario for the plugin is for the generated source code to end up in an Eclipse project and be compiled and run from there. To do that, the plugin and generator must work together, following this interface:

  • Name the generator 'Autobuild'
  • Read the Eclipse workspace directory from the plugin.ini file created by the plugin
  • Generate the source files under that directory
  • Generate an Eclipse project file in that directory, with the same name as the graph, and referring to the generated source code
    • or look at the Digital Watch demo for writing the main class name and project name to Eclipse

Extending the plugin

You can easily modify the plugin to add extra functions that you'd like, or to change the existing behaviour. MetaEdit+ commands, for example commit and abandon or editing the graphs programmatically, are available via the API similarly to the commands that are used in this plugin. For more information, see the API section in the MetaEdit+ manual and the source code of this plugin.

The instructions of how to export and install your plugin are here.

Clone this wiki locally