介绍Eclipse的Buddy策略

*Eclipse插件之间关系


---Eclipse的每一个bundle都有自己独立的classloader;


---插件资源的交互通过MENIFEST.MF中"Export-Package, Require-Bundle, Import-Package"等属性控制;


---插件是不能相互依赖的.


以上三点基本概括了Eclipse插件之间的关系.


 


*那么, 如下问题:


若插件B依赖了插件A,那么插件A是否还能得到插件B中的类或者其他资源呢?


答案就是通过Eclipse提供的buddy策略,可以使2个插件能够互相之间获取资源,就像他们互相依赖一样.


 


*如何使用buddy


---先看看定义(摘自eclipse帮助文档,见参考网址,这里就不翻译了.)


Eclipse-BuddyPolicy: <value>


registered - indicates that the buddy mechanism will consult bundles that have been registered to it. Bundle willing to be registered to a particular bundle add in their manifest: "Eclipse-RegisterBuddy: <bundleSymbolicName>";
dependent - indicates that the classes/resources will be looked up transitively in all the dependent of the bundle;
global - indicates that the classes/resources will be looked up in the global pool of exported package;
app - indicates that the application classloader will be consulted;
ext - indicates that the extensiont classloader will be consulted;
boot - indicates that the boot classloader will be consulted.
---说明


1)在MENIFEST中定义'Eclipse-BuddyPolicy',就说明这个插件具备在不直接依赖其他插件的情况下,具备找到其他插件中资源的能力;


2)'Eclipse-BuddyPolicy'可以设置各种值,以此找到其他classloader,并以此获取其中的内容;


3)最细力度的控制是设置为"registered"时,此时要在其他插件也做设置,但我觉得这是效率最好的方式吧.


举例,PluginA设置"Eclipse-BuddyPolicy:registered",


则此时PluginB必须设置"Eclipse-RegisterBuddy:PluginA's Bundle-SymbolicName", 且PluginB依赖PluginA,


那么,pluginA将能找到PluginB中的可见资源.


4)在registered和dependent时,pluginA能看到pluginB中的所有资源(意为,pluginB非export的包也能找到);


global时,pluginA就只能看到pluingB中暴露的包了.


我觉得这也不是啥缺陷,毕竟A根本不知到它的朋友具体有啥.


 


*示例


---说明


我写了两个测试插件,


eclipse.example.policy.buddy(配置Eclispe-BuddyPolicy), 和eclipse.example.policy.buddy.register1;


并在eclipse.example.policy.buddy.TestBuddy中调用register1中的资源, 通过配置MENIFEST.MF考察各种取值情况.


因为很简单,就不在此具体说明了.


---地址


博客园: http://files.cnblogs.com/bronte/example-buddy-policy.zip (压缩包内有2个插件)


或者


SVN:https://ext-eclipse.googlecode.com/svn/trunk/example/dzh/ (下面有这2个插件)


 


*总结


---eclipse实现了自己的classloader机制,  而且可以通过在MENIFEST.MF中配置, 灵活又使用方便;


---buddy策略是一种classloader机制, 与插件依赖关系不同, 它显得更加积极,同时降低插件间的耦合度.


 


*参考


http://www.eclipsezone.com/articles/eclipse-vms/


http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html(帮助文档)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值