1

我正在构建一个 Eclipse 功能,该功能的要求相当于...如果用户的许可证被吊销,该功能必须能够自动卸载。

如果您想了解更多相关背景信息,这是就该主题提出的另一个问题。

感谢该问题的答案,我一直在尝试学习 Eclipse p2 director api。我在这里找到了一些看起来很有用的类

我一直试图在我的代码中实例化这些类之一,但还没有运气。我一直在阅读帮助文档,但我有点迷失了。

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

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()方法。

我尝试使用 Eclipse 源代码作为示例,但我发现的代码是 org.eclipse.equinox.p2.ui.ProvisioningUI,它与手动卸载 InstallableUnits 时使用的 UI 紧密耦合。这段代码还使用了可怕的 Eclipse内部包中的代码,如果可能的话,我想避免使用这些代码。

谢谢你的考虑,追踪

4

2 回答 2

2

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

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

}

}

于 2012-05-22T14:30:49.150 回答
0

这个问题的流量很少。我将其归因于推动这一发展的需求的奇怪性质。

好吧,似乎这些要求已经改变,我将不再需要基于撤销的许可证以编程方式卸载 Eclipse 功能。因此,我将暂时停止研究如何做到这一点。

如果您想解决此问题,请随时通过在此处发表评论或用另一个问题回答此问题与我联系。:)

于 2012-03-30T18:45:14.397 回答