Search code examples
eclipseeclipse-pdep2

Eclipse P2 IUQuery alway has empty result


I try to use eclipse P2 to enable a tool of mine for auto-updating itself on eclipse start up. While doing so, I want to use an UpdateOperation which is only suited to "my" feature with id "my.feature.id". Whenever this query gets issued in an eclipse installation it has an empty result and thus nothing to update.

So: How do I use the QueryUtil right to get a collection containing only my feature for update as input for an UpdateOperation?

The following method is called when wanting to start the update on eclipse start up:

public class P2Util {
    public static IStatus checkForUpdates(IProvisioningAgent agent, IProgressMonitor monitor) {
        ProvisioningSession session = new ProvisioningSession(agent);
        IQuery<IInstallableUnit> query = QueryUtil.createLatestQuery(QueryUtil.createIUQuery("my.feature.id"));
        UpdateCheckActivator.info("Update Query Expression: " + query.getExpression());
        IProfileRegistry registry= (IProfileRegistry)agent.getService(IProfileRegistry.SERVICE_NAME);
        IProfile profile= registry.getProfile(IProfileRegistry.SELF);
        IQueryResult<IInstallableUnit> result = profile.query(query, monitor);
        Set<IInstallableUnit> unitsForUpdate = result.toUnmodifiableSet();
         UpdateOperation operation = new UpdateOperation(session, unitsForUpdate);
    }
}

Solution

  • The solution is very simple but confusing at first. The query trying to find features with "my.feature.id" was querying for the wrong id.

    In the feature.xml of my feature it is "my.feature.id" but the installable unit gets for unobvious reasons the suffix "feature.group". If one adds this to the id in the query, you get the correct result and the update operation succeeds as expected.