如何轻松查询正在运行的Eclipse的安装功能? [英] How do I easily query a running Eclipse for its installed Features?

查看:167
本文介绍了如何轻松查询正在运行的Eclipse的安装功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个具有相当于此要求的Eclipse功能。如果用户撤销了许可证,则功能必须能够被自动卸载。

I'm building an Eclipse Feature that has a requirement that amounts to this... The Feature must be able to be uninstalled automatically if the user has his license revoked.

如果你想要更多的背景信息,这里是另一个我问过的问题关于这个主题。

If you want more background information about that, Here is another question that I've asked on this topic.

感谢有关这个问题的答案,我已经试图学习Eclipse p2导演api。我发现一些看起来很有用的类这里

Thanks to the answers on that question, I've been trying to learn the Eclipse p2 director api. I've found some classes that look useful here

我一直在尝试实例化其中的一个我的代码中的类,但没有运气。
我一直在阅读帮助文档,我一直在迷失。

I've been trying to instantiate one of these classes in my code, but with no luck yet. I've been reading the help documentation, and I'm getting kind of lost in it all.

我被卡住了,因为我需要向OperationFactory提供一组IInstallableUnit对象。

I'm stuck because I have a need to supply the OperationFactory with a collection of IInstallableUnit objects.

private void scheduleUninstallOperationJob(
        Collection<? extends IVersionedId> toUninstall) 
{
    OperationFactory oFactory = new OperationFactory();
    Collection<URI> repos = null;
    UninstallOperation op = null;
    try {
        op = oFactory.createUninstallOperation(toUninstall, repos, null);
    } catch (ProvisionException e) {
        e.printStackTrace();
    }
    IStatus result = op.resolveModal(null);
    if (result.isOK()) {
        op.getProvisioningJob(null).schedule();
    }
}

我没有看到任何方式轻松问运行Eclipse的实例给我当前安装的InstallableUnits的集合,以便我可以轻松地将要卸载的一个文件传递给 OperationFactory.createUninstallOperation()方法。

I don't see any way to easily ask the running instance of Eclipse to give me the collection of currently installed InstallableUnits so that I can easily pass the one I want to uninstall to the OperationFactory.createUninstallOperation() method.

我已经尝试使用Eclipse源代码作为示例,但是我发现的代码是org.eclipse.equinox.p2.ui.ProvisioningUI,并且紧密耦合到用于UI的UI手动卸载InstallableUnits。此代码还使用可怕的Eclipse 内部软件包中的代码,如果可能,我想避免使用。

I've tried using Eclipse source code as an example, but the code that I have found is the org.eclipse.equinox.p2.ui.ProvisioningUI, and it's tightly coupled to the UI that is used when manually uninstalling InstallableUnits. This code also uses code that is in the dreaded Eclipse internal packages which I would like to avoid using if possible.

感谢您的考虑,Trace

Thank you for your consideration, Trace

推荐答案

此代码获取由当前运行的系统的配置文件管理的IU的集合:

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);
    }

}

}

这篇关于如何轻松查询正在运行的Eclipse的安装功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆