A PDI-enabled bundle is just a standard OSGI bundle which contains a Blueprint Beans file declaring the PDI plugin classes. While Blueprint is only one of many different ways of registering OSGI Service classes, it's the only one supported by the Bridge today. The reason for this has to due with the fact that PDI's PluginRegistry is not only a service locator, but also a factory for Object types (Metas). We may extend support to other registration mechanisms in the future if there's interest from the community.
Generating a Bundle
The easiest way to create a bundle is to create a maven project using maven-bundle-plugin or to base your project on one of our examples. Apache Karaf supplies a Maven Archtype which will automatically build a skeleton project for you.
As with any OSGI Bundle using the Blueprint Beans Container, the beans file must be placed within the OSGI-INF/blueprint folder of the jar. If you use the archtype project generator, one will be created ready for you to customize. The name of the blueprint beans file is not important, only the location. It's also possible to have more than one beans file per bundle though they will be treated separately.
PDI plugins with annotated classes can take advantage of the Pentaho Namespace extensions for blueprint. This is the recommended approach for developing PDI plugins in OSGI. You don't have to use the annotations, but not using them will make the XML configuration much more verbose. Details on how to use the PDI Plugin Annotations are available here: Writing your own Pentaho Data Integration Plug-In
Example using namespace extensions:
In this example the StepBeforeStartMonitor class has the Annotations required for ExtensionPoint PluginTypes. Notice you have to pass the type of the plugin to the <pen:di-plugin> tag, but otherwise everything else will be handled automatically for you.
Step plugins require a little more configuration as multiple classes are involved to support a Step Plugin. You must provide a mapping from the Kettle class to a bean within the blueprint file servicing it for the plugin.
It is possible to register DI plugins without using the annotations and the namespace extensions. However there's no advantage to doing so. The example below is included for the rare case that this is required.
If you're relying on BND or the maven-bundle-plugin, it may fail to add packages required to make the Pentaho Namespace work. If so manually define the following imports: org.pentaho.di.osgi, org.pentaho.di.core.plugins
Handling Dependent Jars
There are a couple options for handling dependencies. You can embed the dependent libraries within the bundle. Or you can build a Karaf Feature for your plugin which installs your plugin bundle and all dependencies atomically. If you do go the feature route another option available for deployment is packaging together your feature file and all of its dependencies into a KAR (Karaf Archive). This allows single artifact deployment of your bundle and all of it's dependencies. KARs are the recommended deployment package for plugin developers.
OSGI Bundles support embedding dependent jars within the bundle. The result is commonly referred to as a "super-bundle" or "fat-bundle". The maven-bundle-plugin automates this process as detailed Here in the "Embedding dependencies" section. While this option will work, any library embedded within a bundle is only usable by that bundle. It's much better to use either of the following options which allow such dependent libraries to be shared between bundles.
Karaf eases the burden of deploying many different OSGI bundles which collectively support some feature, in our case PDI plugins, by allowing you to describe all dependent bundles in an XML document and assigning them a Feature name See Karaf Site for more detail. Once your Feature XML file is properly installed within the Karaf instance, it can be started and stopped atomically. You can also configure Karaf to start your feature automatically while PDI is initializing.
While you can create Feature files manually, Karaf provides a Maven plugin to automatically create a Feature XML based on Maven dependencies see Karaf's documentation for more information. The Step example project includes a sub-module which builds a Feature using this technique.
KARs are simply zip files which contain your Feature XML and all dependent bundles. Karaf supplies a Maven plugin to automate the creation of KARs from Feature XML files. The Step example project demonstrates the usage of this plugin. For more information see Karaf's documentation
There are a couple of examples available in the PDI-OSGI-Bridge repository:
TODO: Add more examples of real plugin