我正在运行以下代码来迭代已安装的功能
IBundleGroup[] bundleGroups = Platform.getBundleGroupProviders()[0].getBundleGroups();
但是,此代码不会返回在初次运行产品后安装的功能。我没有在"功能"下看到这些已安装的功能。 “安装详细信息”对话框的选项卡(“帮助” - >“关于 - >安装详细信息”),但确实可以在"已安装软件"标签。是否有不同的API来获取这些功能?
答案 0 :(得分:3)
更好地使用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;
}