This plugin is a simple demonstration of how to write an optional service. An optional service allows you to have
a plugin run with or without a component. In other words, this plugin will be able to work even when a component
that it depends on is unavailable.
In this example we have a component (Foo) which depends on a GreenHopper component (com.atlassian.greenhopper.GreenHopper).
We use Foo in our servlet (MyServlet) to test whether or not it is available.
MyServlet uses FooAccessor which, in a safe manner, checks whether or not the necessary GreenHopper component is available.
If GreenHopper is not available, it simply returns null for getFoo().
If GreenHopper is available, it finds the required GreenHopper components (through FooServiceFactory) and creates a Foo.
FooAccessor checks for the new existence of GreenHopper upon every accessor attempt. This, combined with the use of
DynamicImport-Package, allows the plugin to automatically detect that GreenHopper is available. This plugin does *not*
have to be restarted to detect this, nor does it get disabled or fail to load.
To test it out:
mvn clean jira:run
Go to http://localhost:2990/jira/plugins/servlet/optionalservice/myservlet. You will see GreenHopper *is not* present.
Go to http://localhost:2990/jira/plugins/servlet/upm and install GreenHopper.
Go to http://localhost:2990/jira/plugins/servlet/optionalservice/myservlet. You will see GreenHopper *is* present.