最好使用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;
}