【问题标题】:Configure a p2 update repository programmatically以编程方式配置 p2 更新存储库
【发布时间】:2011-03-16 07:54:17
【问题描述】:

Eclipse wiki 中有一篇文章如何通过将静态 conf 文件添加到您的产品中来配置用户的 RCP 应用程序的 p2 默认存储库:

Equinox/p2/Adding Self-Update to an RCP Application - Configuring the user's default repositories

当用户更改一些配置细节时,我想在 Java 类中以编程方式执行相同的操作。我找不到合适的 p2 API 文档。

【问题讨论】:

标签: java eclipse-rcp rcp p2


【解决方案1】:

将此解决方案用于基于 Eclipse 3.7 的应用程序:

final ProvisioningUI ui = ProvUIActivator.getDefault().getProvisioningUI();
IArtifactRepositoryManager artifactManager = ProvUI.getArtifactRepositoryManager(ui.getSession());
artifactManager.addRepository(new URI(UPDATE_SITE_URL);

IMetadataRepositoryManager metadataManager = ProvUI.getMetadataRepositoryManager(ui.getSession());
metadataManager.addRepository(new URI(UPDATE_SITE_URL);

对于 ProvUIProvisioningUI,您必须导入包 org.eclipse.equinox.p2.uiorg.eclipse。 equinox.p2.operations(等等)。

【讨论】:

  • 谢谢,这很有帮助。
【解决方案2】:

我找到了解决方案。这很容易 - 不幸的是没有文档......

    // from bundle org.eclipse.equinox.p2.console
    import org.eclipse.equinox.internal.p2.console.ProvisioningHelper;

    URI repoUri = new URI(UPDATE_SITE_URL);
    try {
        ProvisioningHelper.addMetadataRepository(repoUri);         
    } catch( Exception e ) {
        LOG.warn("Can not add update repository: " + repoUri);           
    }
    try {
        ProvisioningHelper.addArtifactRepository(repoUri);          
    } catch( Exception e ) {
        LOG.warn("Can not add update repository: " + repoUri);
    }

【讨论】:

  • ProvisioningHelper 类的方法是内部的。外面无法访问:(
【解决方案3】:

此外,您可以使用 ElementUtils 添加多个存储库,也可以对它们进行排序。

MetadataRepositoryElement[] element = new MetadataRepositoryElement[links.length];
    for (int i = 0; i < links.length; i++) {
        element[i] = new MetadataRepositoryElement(null, new URI(links[i]), true);
        element[i].setNickname("Link-"+i);
    }
    ElementUtils.updateRepositoryUsingElements(element, null);

这些链接将按字母顺序显示。

【讨论】:

    【解决方案4】:

    这个问题的谷歌查询很高,但仍然没有发布的好方法:

    如果有人像我一样通过谷歌找到这个页面,我已经解决了这个问题。您可以使用 org.eclipse.equinox.internal.p2.ui.model.ElementUtils.updateRepositoryUsingElements 以编程方式设置存储库。完整代码可见here.

    【讨论】:

      猜你喜欢
      • 2012-05-26
      • 2019-03-28
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      相关资源
      最近更新 更多