Opening Rhapsody and Running a Plugin from the Command Line
Overview
The IBM help page for the Rhapsody command line states that you can run a plugin using the following command line switch:
-cmd=call <plugin> <parameters>
However it is a little light on the details. Here's what you really need to know:
The HEP File
Plugins are defined in a HEP file and typically have two parts:
- The plugin definition : defines the location of the jar/class files
- The menu definition : defines the Rhapsody menu item(s) that invoke the plugin
ApplicableTo
The menu definition includes an applicableTo entry. If this is empty then the menu item appears on the main Tools menu, otherwise it appears on the right-click menu of the element types specified in the applicableTo list.
In the example below, (1) is the plugin definition, (2) and (3) are menu definitions that invoke that plugin:
[helpers]numberOfElements=3name1=SIMPLE_PLUGINJavaMainClass1=com.ibm.rhapsody.samples.basic.SimplePlugin_LauncherJavaClassPath1=./eclipse/binisPlugin1=1helperTriggers1=name2=Invoke Helper From Right ClickisPluginCommand2=1command2=SIMPLE_PLUGINapplicableToNonStrict2=Project,PackageisVisible2=1helperTriggers2=name3=Invoke Helper From Tools MenuisPluginCommand3=1command3=SIMPLE_PLUGINapplicableToNonStrict3=isVisible3=1helperTriggers3=
The RPUserPlugin
Plugins are defined in java by extending RPUserPlugin. There are three methods that Rhapsody will call depending on how the user - or the command line - has made the invocation:
- OnMenuItemSelect (String menu)
- RhpPluginInvokeItem
- RhpPluginInvokeItem (String args)
OnMenuItemSelect(String menuItem)
This function is called by Rhapsody if the user has invoked it by right-clicking on a model element.
@Overridepublic void OnMenuItemSelect( String menuItem ){rpApp.writeToOutputWindow( null, "Basic Plugin Invoked\n" );theApp.goOnSelect( menuItem );}
RhpPluginInvokeItem
This function is called by Rhapsody if the user has invoked it from the tools menu OR from a command line with no arguments (see below)
@Overridepublic void RhpPluginInvokeItem(){// This method is called when the user invokes the helper from the tools menu or from a command line with no argumentstheApp.goOnInvoke();}
RhpPluginInvokeItem (String args)
This function is called by Rhapsody if the user has invoked it from the tools menu OR from a command line with arguments (see below)
@Overridepublic void RhpPluginInvokeItem( String args ){// This method is called when the user invokes the helper from a command line with argumentstheApp.goOnInvokeWithArgs( args );}
Invoking a Plugin from the Command Line
With the above in mind, to invoke a plugin from the command line use the syntax below:
-cmd=call "PLUGIN arg1 arg2"
- PLUGIN should be the name of the plugin definition from the HEP file (Not the menu entry)
- The surrounding quotes are optional, Rhapsody will use the first argument* fo find the right plugin and everything after that will be sent as the arguments
- Make sure you have implemented the necessary RhpPlugin method(s) as described above
*See call_extended below. Also note that the other arguments cannot contain spaces - if they do they should be wrapped in single quotes.
Example:
C:\IBM\RhapsodyX\rhapsody.exe -cmd=open C:\IBM\RhapsodyX\Share\Profiles\CommandLinePluginSample\CommandLinePluginSample.rpyx -cmd=call "SIMPLE_PLUGIN arg1 arg2"
Sample Project
You can download an example here: Sample
The sample contains an eclipse project with some simple functionality to demonstrate launching the plugin manually and from the command line. To use it, unzip it - edit the batch files with the correct paths for your environment and then run them.
Call Extended
Since this is a windows command line, arguments cannot contain spaces. In such cases you may use -cmd=call_extended instead which looks for quotes and strips them off, for example to run M2M (which contains a space in the plugin name):
-cmd=call_extended "M2M Engine" "-filePath c:/Work/Transforms/UML.rpyx -ruleset SysMLToUML"