Plugin Development

Suggest edits
Documentation > Developers

Content:

1 - Get ready
2 - Build your plugin
3 - Import your plugin


OpenMOLE is a pluggable platform. It means that you can easily write your own extension and plug it into OpenMOLE. This tutorial explains how to write an OpenMOLE plugin using Scala and SBT. OpenMOLE is based on the JVM so you can create OpenMOLE plugins using Scala or any other JVM based languages such as Java, Groovy, Clojure, Jython, etc.

Get ready 🔗

You will need the following tools to design your plugin:
  • The git software.
  • SBT, the Scala Building Tool.
git clone https://github.com/openmole/myopenmoleplugin.git
This repository contains a template to help you create OpenMOLE plugins easily. The hello directory contains the source code of the plugin and the materials to build it:
package myopenmoleplugin

object Hello {
  def world(i: Int) = i * 2
}

Build your plugin 🔗

The file @b{build.sbt} contains the building instructions for SBT. The most important part are the OSGi instructions:
enablePlugins(SbtOsgi)

OsgiKeys.exportPackage := Seq("myopenmoleplugin.*")

OsgiKeys.importPackage := Seq("*;resolution:=optional")

OsgiKeys.privatePackage := Seq("*")

OsgiKeys.requireCapability := """osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))""""
  • exportPackage instruction makes the @code{myopenmoleplugin} package visible to OpenMOLE.
  • importPackage instruction means that every package that is not included into the plugin should be imported.
  • privatePackage means that every package in the project, or in the dependencies, should be embedded except for the package starting by the \"scala\" word. The scala packages provided by OpenMOLE will be used by the plugin instead.
To build the plugin, execute @code{sbt osgiBundle}. SBT will then construct the plugin in target/scala-3.x.x/myopenmoleplugin_3.x.x-1.0.jar. This JAR file contains the classes you have developed (*.class) along with the metadata relative to imports and exports in the MANIFEST.INF file:
META-INF/MANIFEST.MF
myopenmoleplugin/
myopenmoleplugin/Hello$.class
myopenmoleplugin/Hello.class
You can check in the MANIFEST.MF that your namespace is exported.

Import your plugin 🔗

To enable your plugin in OpenMOLE, either use the plugin panel in the GUI, or use the option -p:
openmole -p target/scala-2.12/myopenmoleplugin_3.x.x-1.0.jar
You can now use the Hello object in your workflows:
// Declare the variable
val i = Val[Int]
val j = Val[Int]

// Hello task
val hello = ScalaTask("val j = myopenmoleplugin.Hello.world(i)") set (
  inputs += i,
  outputs += (i, j),
  plugins += pluginsOf(myopenmoleplugin.Hello)
)

DirectSampling(
  evaluation = hello,
  sampling = i in (0 to 2)
) hook display