views:

186

answers:

3

I have 2 eclipse plugins that I am building; let's call them plugin A and plugin B...

Plugin A requires a license to run and Plugin B is free to the world. I have created an extension point in Plugin B to which Plugin A contributes (and in some cases overrides) data. I would like to find a way to disregard that data in plugin B if plugin A is not licensed (without have to check to see if the plugin can start).

Is there such a mechanism in eclipse that allows me to accomplish such a feat? My current workaround is to check to see if the plugin is started (via the Bundle) and if it isn't attempt to start it. If the plugin A is unlicensed I throw an Exception in the start() method.

Thanks.

A: 

Requirements

So, you are writing two plugins.

Plugin B has an extension point. If the user has the bundle for Plugin A, and the license, then plugin A should contribute extensions to the EP in plugin B.

Approaches

OSGi's security model is largely built atop the default Java Permissions and SecurityManager. There is a discussion in this presentation from Apache Felix. I expect it would be possible to build a licensing scheme around this.

You're workaround sounds like it could work, however, there are a couple of concerns:

  • stopping a bundle from starting may prevent any services being registered, but will it effect a change in the extension registry? i.e. those extensions registered using plugin.xml. I would guess that DS services would be ok, but I'd have to try it.
  • stopping the bundle may not be enough - can it be started again later on? I would probably want it UNINSTALLED.
  • an unlicensed bundle is an opportunity telling the user about licensing. So, how do you tell the user that the bundle was not licensed, and won't be able to be used, and btw, here's how you license it.

So far you haven't said anything about how the license is to be implemented. I'm guessing you'll go for a LicenseService, or even perhaps a singleton.

Do report back what you find.

jamesh
A: 

One possible solution I can think of is that you contribute a class from plugin A to Plugin B. Then, when plugin B reads the contribution items, it can try to create an instance of this class.

The class, from plugin A, can then throw some exception in the constructor if it is not licensed. This will tell plugin B that the information from plugin A can be disregarded.

A possible implementation in plugin B can look like this:

    IExtensionPoint extensionPoint = registry.getExtensionPoint("mypoint");
    IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
    for (int i = 0; i < elements.length; i++) {
      try {
        (License)elements[i].createExecutableExtension("class");
        // ..... Read any other items you need....
      }
      catch(LicenceException e){
        // Plugin is invalid, do not use
      }
    }
Mario Ortegón
+1  A: 

Shouldn't A check its license itself and not-override/not-contribute any data (or override with providing identical data) if it is not licensed? Why place the burden of license checking on B when essentially B doesn't care (as it's free).

I'd opt for A to start in a limited mode if the license is not found. You might also - as jamesh suggested - want to give the user the opportunity to provide the license, e.g. with an additional A-UI plugin informing the user about the missing license and offering to license.

Olaf