您的位置:首页 > 编程语言 > Java开发

eclipse中如何获得feature与plugin的list

2009-02-24 21:34 453 查看
eclipse中如何获得feature与plugin的list
做一些基于eclipse的开发,如RCP,经常需要查找当前platform中所有已经安装的feature和plug-in。其实,eclipse的“about eclipse platform”对话框就需要使用这个功能。通过阅读该对话框的代码,作者发现了以下方法。约定本文中Plugin与Bundle概念相同。
1.获得所有feature的list
首先,通过Platform,得到一个IBundleGroupProvider数组;
然后,通过IBundleGroupProvider,获得相应的IBundleGroup数组;
最后,通过IBundleGroup,得到Bundle数组。
代码如下:
for (int i=0;i<providers.length;i++){
IBundleGroupProvider provider = providers[i];
System.out.println("Provider name: "+ provider.getName());
IBundleGroup[] groups=provider.getBundleGroups();

for (int j=0;j<groups.length;j++){
IBundleGroup group = groups[j];
System.out.println(" Feature name: "+group.getName());
}
}
2. 获得plug-in的list
原本可以通过上例的IBundleGroup列出,每个BundleGroup下的Bundle。但是,考虑到有的Plugin不属于任何一个feature,所以上述方法得到的bundle list可能不完全。通过BundleContext的getBundles()方法,可以达到这个目的。但是,如果某些class没有继承Bundle,Plugin或者BundleActivator,就无法获得BundleContext参数。因此,需要采用另一种方式得到所有bundle list。不通过BundleContext获得bundle list的代码如下:
BundleDescription[] descriptions = Platform.getPlatformAdmin().getState().getBundles();
for (int i=0;i<descriptions.length;i++){
System.out.println("Bundle name:"+descriptions[i].getSymbolicName());
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息