简体   繁体   English

Eclipse插件兼容层(使用片段?)

[英]Eclipse plugin compatibility layer (using fragments?)

I've written an Eclipse plugin that depends on version 1.0 of another plugin (let's call it WidgetMaster). 我编写了一个Eclipse插件,它依赖于另一个插件的1.0版(我们称之为WidgetMaster)。 Now, version 2.0 of WidgetMaster has been released with interface changes on many of the classes I was using. 现在,已经发布了WidgetMaster的2.0版,其中包含了我正在使用的许多类的界面更改。 How can I continue to maintain one version of my plugin while supporting both versions of WidgetMaster? 如何在支持两个版本的WidgetMaster的同时继续维护我的插件的一个版本?

So far what I've come up with is: 到目前为止,我想出的是:

  1. Create my own interface for all the functionality provided by WidgetMaster. 为WidgetMaster提供的所有功能创建自己的界面。 This means I'd also have to create wrappers for all of their types I was using, which is a lot. 这意味着我还必须为我正在使用的所有类型创建包装器,这很多。
  2. For each supported version of WidgetMaster, create a Fragment project that implements my interface and all the wrapper classes in terms of that version's API. 对于WidgetMaster的每个受支持版本,创建一个Fragment项目,该项目实现我的接口以及该版本API的所有包装类。

This is going to be a significant amount of work because I currently use WidgetMaster classes throughout my plugin code. 这将是一项重要的工作,因为我目前在我的插件代码中使用WidgetMaster类。 If I will only be depending on a specific version of WidgetMaster from my Fragment projects, I will have to move and wrap all of that. 如果我只依赖于我的Fragment项目中特定版本的WidgetMaster,我将不得不移动并包装所有这些。 Also, 99% of the wrappers will be the same from version to version but I'll still have to copy them to each Fragment. 此外,99%的包装器从版本到版本都是相同的,但我仍然需要将它们复制到每个片段。

Is this the right approach or is there a better way to handle this situation? 这是正确的方法还是有更好的方法来处理这种情况?

The Adapter pattern seems like the right way, if you really want to provide continual support for the different versions of the WidgetMaster plug-in, for long term scope. 如果你真的想为长期范围的WidgetMaster插件的不同版本提供持续支持,那么适配器模式似乎是正确的方式。

For a shorter support time, I'd duplicate the plug-in and leverage my version control system and its merging capabilities. 为了缩短支持时间,我会复制插件并利用我的版本控制系统及其合并功能。 I'd create a different branch that uses the most recent version of WidgetMaster. 我创建了一个使用最新版WidgetMaster的不同分支。 So I'd have two versions of my plug-in, each would use the different versions of WidgetMaster, calling to the specific version's API call. 所以我有两个版本的插件,每个版本都会使用不同版本的WidgetMaster,调用特定版本的API调用。 Make sure that your VCS has been informed of the merge resolution once it's all set so that future merges do not overwrite the API call customization (eg ours strategy with git merge). 一旦设置完毕,确保已经通知您的VCS合并解决方案,以便将来的合并不会覆盖API调用自定义(例如ours git merge策略)。

The two different approaches have overheads but at different times. 这两种不同的方法在不同的时间都有开销。 The Adapter approach has a bigger initial overhead while the VCS approach would be quicker to setup. 适配器方法具有更大的初始开销,而VCS方法将更快地设置。 But once the adapters have been implemented, the overhead is minimal, while the VCS approach will always have the merging overhead. 但是一旦实现了适配器,开销就会很小,而VCS方法总是会产生合并开销。

As a side note, I wonder if OSGi fragments are really the best option for you to setup the version to use of WidgetMaster (if you pick the Adapter approach). 作为旁注,我想知道OSGi片段是否真的是您设置WidgetMaster版本的最佳选择(如果您选择适配器方法)。 I am no OSGi expert , but you could look into OSGi service factories to give you the right version of WidgetMaster . 我不是OSGi专家 ,但您可以查看OSGi服务工厂,为您提供正确版本的WidgetMaster There are more evolved ways apparently to accomplish dependency injection with OSGi: Apache Felix Maven SCR Plugin , Blueprint Container , Apache Felix iPojo . 显然有更多的演进方式来完成OSGi的依赖注入: Apache Felix Maven SCR插件Blueprint ContainerApache Felix iPojo This SO question seems to cover the question of DI in OSGi. 这个SO问题似乎涵盖了OSGi中DI的问题。

Good luck! 祝好运! I'd like to know which route you take, as I'll face some similar challenge soon! 我想知道你走哪条路,因为我很快就会遇到类似的挑战!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM