限制插件之间提供的扩展点数据

时间:2023-02-05 12:18:35

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

我正在构建2个eclipse插件;让我们称他们为插件A​​和插件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).

插件A需要运行许可证,插件B对全世界都是免费的。我在插件B中创建了一个扩展点,插件A为其贡献(在某些情况下会覆盖)数据。如果插件A未获得许可,我想找到一种方法来忽略插件B中的数据(无需检查插件是否可以启动)。

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.

在日食中是否有这样的机制可以让我完成这样的壮举?我目前的解决方法是检查插件是否已启动(通过Bundle)以及是否尝试启动它。如果插件A未经许可,我在start()方法中抛出异常。

3 个解决方案

#1


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).

如果没有许可,A不应该检查其许可本身而不是覆盖/不提供任何数据(或覆盖提供相同的数据)?为什么当B基本上不关心(因为它是免费的)时,将许可检查的负担放在B上。

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.

如果找不到许可证,我会选择A以限制模式启动。您也可以 - 正如jamesh建议的那样 - 希望为用户提供提供许可证的机会,例如:使用额外的A-UI插件通知用户缺少许可证并提供许可证。

#2


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.

插件B有一个扩展点。如果用户拥有插件A的包和许可证,那么插件A应该在插件B中为EP提供扩展。

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.

OSGi的安全模型主要是在默认的Java Permissions和SecurityManager之上构建的。 Apache Felix在本演示文稿中进行了讨论。我希望围绕这个建立一个许可方案是可能的。

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.
  • 阻止启动捆绑包可能会阻止任何服务被注册,但它是否会影响扩展注册表的更改?即使用plugin.xml注册的那些扩展。我猜DS服务没问题,但我必须尝试一下。

  • 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.

到目前为止,您还没有说明如何实施许可证。我猜你会去找LicenseService,甚至可能是单身人士。

Do report back what you find.

请报告您找到的内容。

#3


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.

我能想到的一个可能的解决方案是你从插件A贡献一个类到插件B.然后,当插件B读取贡献项时,它可以尝试创建这个类的实例。

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的类可以在构造函数中抛出一些异常。这将告诉插件B可以忽略来自插件A的信息。

A possible implementation in plugin B can look like this:

插件B中的可能实现可能如下所示:

    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
      }
    }

#1


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).

如果没有许可,A不应该检查其许可本身而不是覆盖/不提供任何数据(或覆盖提供相同的数据)?为什么当B基本上不关心(因为它是免费的)时,将许可检查的负担放在B上。

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.

如果找不到许可证,我会选择A以限制模式启动。您也可以 - 正如jamesh建议的那样 - 希望为用户提供提供许可证的机会,例如:使用额外的A-UI插件通知用户缺少许可证并提供许可证。

#2


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.

插件B有一个扩展点。如果用户拥有插件A的包和许可证,那么插件A应该在插件B中为EP提供扩展。

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.

OSGi的安全模型主要是在默认的Java Permissions和SecurityManager之上构建的。 Apache Felix在本演示文稿中进行了讨论。我希望围绕这个建立一个许可方案是可能的。

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.
  • 阻止启动捆绑包可能会阻止任何服务被注册,但它是否会影响扩展注册表的更改?即使用plugin.xml注册的那些扩展。我猜DS服务没问题,但我必须尝试一下。

  • 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.

到目前为止,您还没有说明如何实施许可证。我猜你会去找LicenseService,甚至可能是单身人士。

Do report back what you find.

请报告您找到的内容。

#3


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.

我能想到的一个可能的解决方案是你从插件A贡献一个类到插件B.然后,当插件B读取贡献项时,它可以尝试创建这个类的实例。

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的类可以在构造函数中抛出一些异常。这将告诉插件B可以忽略来自插件A的信息。

A possible implementation in plugin B can look like this:

插件B中的可能实现可能如下所示:

    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
      }
    }