Question

I am running the following code to iterate over installed feature

IBundleGroup[] bundleGroups = Platform.getBundleGroupProviders()[0].getBundleGroups();

However, this code does not return features that were installed after the initial running of the product. I don't see these installed features under "Features" tab of the Installation Details Dialog (Help -> About -> Installation Details), but do see them under "Installed Software" tab. Is there a different API to get these features?

Was it helpful?

Solution

Better use P2 API for that. Here's an example how it may work (untested, but you will get the idea):

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top