This is an old revision of the document!
Tutorial: Plugins
Learning Objectives:
- What does a plugin do?
- System plugins
- Develop custom plugin
- Deploy custom plugin
- Sharing custom plugin
Develop custom plugin
Set plugin development environment using Eclipse IDE:
- create a java project
- add toplugin.jar to build path (project properties)
Create plugin package Create plugin class inheriting from PluginAncestor class Add @TO_PLUGIN annotation to the class Implement required methods Add your plugin functions, declare as public functions Compile and fix errors
package com.mine.plugin;
import com.testoptimal.plugin.MScriptInterface.IGNORE_INHERITED_METHOD;
import com.testoptimal.plugin.MScriptInterface.TO_PLUGIN;
import com.testoptimal.plugin.PluginAncestor;
@IGNORE_INHERITED_METHOD
@TO_PLUGIN
public class MyPlugin extends PluginAncestor {
@Override
public String getPluginID() {
return "MYPLUGIN";
}
@Override
public String getPluginDesc() {
return "My Plugin";
}
@NOT_MSCRIPT_METHOD
@Override
public void start() throws Exception {
System.out.println("My Plugin started");
}
@NOT_MSCRIPT_METHOD
@Override
public void close() {
System.out.println("My Plugin closed");
}
public String doSomething (String something_p) {
System.out.println("My plugin: " + something_p);
return "Done";
}
}
By default, all public methods declared as well as inherited are exposed as MScript function. To exclude certain methods from being exposed as MScript function, add annotation @NOT_MSCRIPT_METHOD to the method. Add annotation @IGNORE_INHERITED_METHOD to the plugin class to exclude inherited methods from exposed as MScript functions.
Write your junit test to test the plugin functions.
Deploy Custom Plugin: Export project as jar file Copy plugin jar file to /lib folder Register your plugin package in config.properties
plugin.packages=your_plugin_package_path
Restart TestOptimal server
Use Custom Plugin: Open an existing model or create a new model Select SCRIPT tab Click on “P” icon on SCRIPT tab toolbar Check the checbox for your custom plugin Your plugin should show up on CodeAssist list as “$'pluginID'”, e.g. $MYPLUGIN CodeAssist on your custom plugin should automatically be added.