Introduction

Plugins are software programs that can be dynamically added to existing programs to add / enhance functionality. They are also called Add-ons or Bundles (the OSGi term). You may have seen plugins in the software that you use, Internet browsers, text/graphics editors, games, etc. Examples include Adobe Flash and Adobe Reader for browsers, and countless Photoshop filters. Users can search for plugins and choose ones that address their needs. Users can add a new plugin (download and install) whenever they want. They can remove a plugin if they no longer need it. The plugins can also be updated dynamically when the author(s) make changes.

IGB uses OSGi to implement plug-ins

The java standard for Plugins is OSGi (http://www.osgi.org). This is what IGB (written in java) uses. The OSGi term for a Plugin is Bundle. They mean the same thing.

An OSGi bundle is a jar file. It must have a MANIFEST.MF file with the OSGi headers (see below).

An OSGi bundle can (usually will) have a special java class called an Activator. This class must extend org.osgi.framework.BundleActivator, and implement the start() and stop() methods. The activator class is specified in the Bundle-Activator MANIFEST.MF header (see below). These methods are called when the bundle is started and stopped.

When a program is running with OSGi, the OSGi framework dynamically handles installing / uninstalling, activating (starting), deactivating (stopping), and upgrading bundles.

OSGi caches bundles, saving them to a directory on the local hard disk, so that they don't need to be downloaded every time. So you can work offline after you have loaded IGB.

IGB uses OSGi Services to allow bundles to add new implementations of existing IGB elements. The new implementations will show up as soon as the bundle is started. Examples include IGB tabs and graph manipulation functions.

Extension Points

IGB has several "extension points" designed specifically for plugins. These are interfaces or abstract classes that are implemented or extended by plugin versions. Usually the Activator for the plugin will register the plugin as a service in the start() method:

The extension points include:

com.affymetrix.genometryImpl.operator.Operator - operates on a selection of tracks from the GraphAdjuster tab or popup menu

Developing IGB bundles

IGB bundles are OSGi compatible, so they should have an Activator and they must have a MANIFEST.MF file that is found in the META-INF directory. These are compiled and jarred with all required classes, jars, and resources. The resulting jar is the bundle. This can then be uploaded to the bundle repository. At that point, any one can use the bundle with IGB. IGB uses the Apache Felix OSGi implementation, but this could change, so no Felix specific code should be used. In the Activator class, there is a start() and stop() method. This is where you want to put all the code to start and stop the bundle.

MANIFEST.MF requirements

In the MANIFEST.MF file, there are several headers that need to be specified - fill in parenthesis below:

Plug-ins tab

If you look at the Plug-ins tab, you will see the Bundle-SymbolicName under the Name column, the Bundle-Description under the Description column, and the Bundle-Version under the Version column. If the Bundle-DocURL is there, the Name cell will have a blue info icon that links to this URL.

Import-Package and Require-Bundle don't overlap, you can specify a requirement in one or the other, but Import-Package is recommended over Require-Bundle. To have a multi line header, start the continuation line after a blank in column 1.

Put a blank line at the end of the manifest.mf file - due to a bug in felix.

The igb, genometry and genoviz projects can by accessed as bundles. If a class/method is needed from igb/genometry/genoviz, it must be public, and the package must be exported in the MANIFEST.MF Export-Package list of the bundle that contains the class (igb, genometry or genoviz).

If you want to add a tab panel as a bundle, there is a helper abstract class, com.affymetrix.igb.window.service.WindowActivator, that you can extend.

The order that OSGi starts the bundles is not specified, so at any given time, one bundle cannot assume that another bundle has been started. So, if your bundle needs access to other bundles or services (like IGBService), you will not be sure when the bundle is available. For Services, like IGBService and WindowService, you can use a ServiceTracker to be notified when the required service is available - see WindowActivator for an example.

In the IGB source code repository, in the plugins/ directory, you will find several embedded bundles that IGB uses. You can look through these to help you understand bundles.

Sample plug-in

To create our plugin, we will create three files, the MANIFEST.MF file, an activator (OSGi term), and a transformer (IGB term).

We will create a bundle that adds a new graph function.

Create the following MANIFEST.MF file:

Note: There are spaces at the beginning of the extension lines, and a blank line at the end)

Now, create the Activator, mypackage.MyActivator.java

mypackage.MyActivator.java

And create the Transformer, mypackage.MyTransformer.java

mypackage.MyTransformer.java

Now, compile and jar these files into MyTransformer.jar (the jar command has a -m option for the manifest file).

At this point, you want to put your jar into a web server using OBR (see above).

To add the plugin to a web server without OBR, in the plugins directory, from the command line run

where IGB_HOME is your checked-out copy of the genoviz-trunk repository from Sourceforge.net.

this will create a repository.xml file listing all the bundles and their requirements.

make sure the repository.xml file and the bundles directory are accessible to the web server.

in IGB, open the File>Preferences page, Plugin Repositories tab

click the Add ... button at the bottom

enter the web server URL for the directory that has the repositories.xml file that you created - you can use whatever you want for the name.

Click the "Add Server" button

close the Preferences page.

Open the Plugins tab

you should see your bundle in the table, click on the install checkbox.

Once you have installed your bundle, select a graph track on the main view, and open the Graph Adjuster tab. Now if you click on the Transformation drop down, you will see MyTransformer in the list. Select it and click the Go button, and you will see a new track using your bundle.

To create plug-ins using Eclipse

To create plug-ins using NetBeans

Including a Bundle in the IGB Distribution

Some bundles are included in the normal IGB distribution. Above we discussed how to build an "external" bundle for use with IGB. Here are the additional things you need to do to include a bundle with IGB. Such bundles are sometimes referred to as "internal".

Put your bundle in our svn repository in the "plugins" folder.

Add your bundle to the list of include.bundles in build.properties.

Add a line to the optional bundle section of build.xml. This might be avoided in future if we can figure out how to get this elsewhere.