我正在运行以下代码来迭代已安装的功能
IBundleGroup[] bundleGroups = Platform.getBundleGroupProviders()[0].getBundleGroups();
但是,此代码不返回在产品首次运行后安装的功能。我在“安装详细信息”对话框的“功能”选项卡(帮助->关于->安装详细信息)下没有看到这些已安装的功能,但是在“已安装的软件”选项卡下却看到了它们。是否有其他API可以获取这些功能?
为此,最好使用P2 API。这是一个示例,它可能如何工作(未经测试,但您会明白的):
Set<IInstallableUnit> findFeatures() throws ProvisionException {
Set<IInstallableUnit> result = Sets.newHashSet();
// 1. initialize necessary p2 services
BundleContext ctx = FrameworkUtil.getBundle(getClass()).getBundleContext();
ServiceReference<IProvisioningAgentProvider> ref = ctx.getServiceReference(IProvisioningAgentProvider.class);
IProvisioningAgentProvider agentProvider = ctx.getService(ref);
String profileId = IProfileRegistry.SELF; // the profile id for the currently running system
URI location = null; // the location for the currently running system is null
IProvisioningAgent provisioningAgent = agentProvider.createAgent(location);
IProfileRegistry profileRegistry = (IProfileRegistry) provisioningAgent.getService(IProfileRegistry.SERVICE_NAME);
IProfile p2Profile = profileRegistry.getProfile(profileId);
// 2. create a query (check QueryUtil for options)
IQuery<IInstallableUnit> query = QueryUtil.createIUGroupQuery();
// 3. perform query
IQueryResult<IInstallableUnit> queryResult = p2Profile.query(query, null);
result = queryResult.toSet();
return result;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句