Documentation > Developers
OpenMOLE is a plugable 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.
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:
This JAR file contains the classes you have developed (*.class) along with the metadata relative to imports and exports in the
You can check in the MANIFEST.MF that you namespace is exported.
You can now use the
Get ready 🔗
You will need the following tools to design your plugin: The first step is to clone the github repository for OpenMOLE plugins:git clone git://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 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))""""
-
exportPackageinstruction makes themyopenmolepluginpackage visible to OpenMOLE. -
importPackageinstruction means that every package that is not included into the plugin should be imported. -
privatePackagemeans 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.
sbt osgiBundle.
SBT will then construct the plugin in target/scala-2.12/myopenmoleplugin_2.12-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 you 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_2.12-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 hook DisplayHook(),
sampling = i in (0 to 2)
)