How do I easily query a running Eclipse for its installed Features?

我与影子孤独终老i 提交于 2019-12-06 14:58:29

This code gets the collection of IUs which are managed by the profile of the currently running system:

/**
 * This Activator informs user about the IUs which are currently installed in
 * the running environment.
 * 
 * This code is intended for demo only and should be much more defensive for
 * production use.
 * 
 * @author Ilya Shinkarenko
 * 
 */
public class SelfInformerActivator extends Plugin {

@Override
public void start(final BundleContext ctx) throws Exception {
    super.start(ctx);

    ServiceReference<IProvisioningAgentProvider> sr = ctx.getServiceReference(IProvisioningAgentProvider.class);
    IProvisioningAgentProvider agentProvider = ctx.getService(sr);
    URI p2InstanceURI = null; // myself
    final IProvisioningAgent agent = agentProvider.createAgent(p2InstanceURI);

    IProfileRegistry regProfile = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);

    IProfile profileSelf = regProfile.getProfile(IProfileRegistry.SELF);

    IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();

    //This is what you need:
    IQueryResult<IInstallableUnit> allIUs = profileSelf.query(query, new NullProgressMonitor());

    //Let's output it:
    Iterator<IInstallableUnit> iterator = allIUs.iterator();
    while (iterator.hasNext()) {
        IInstallableUnit iu = iterator.next();
        System.out.println(iu);
    }

}

}

There was very little traffic on this question. I attribute that to the odd nature of the requirement that is driving this development.

Well, it seems that those requirements have changed, and I will no longer be needing to programmatically uninstall Eclipse Features based on a revoked license. Therefore I will stop researching how to do this for now.

If you're looking to solve this issue to, feel free to contact me by leaving a comment here, or answering this question with another question. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!