【问题标题】:In Equinox Is it possible to to mark an OSGi bundle as started from its containing feature's p2.inf?在 Equinox 中是否可以将 OSGi 包标记为从其包含功能的 p2.inf 开始?
【发布时间】:2011-03-05 20:55:46
【问题描述】:

我有一个 Eclipse 功能,其中包括几个捆绑包。我想告诉 p2 在安装该功能时将其中一个捆绑包标记为已启动。这可以像这样使用捆绑包自己的 META-INF/p2.inf,

instructions.configure = markStarted(started: true)

但我想在功能级别而不是捆绑级别执行此操作(相关捆绑是第三方,如果可能,我不希望以任何方式对其进行修改)。

一些研究让我找到了this document,这表明应该可以将配置指令移动到包含功能的 p2.inf 中。我已经尝试了所有显而易见的事情,例如,

units.0.id = <bundle symbolic name>
units.0.instructions.configure = \
  org.eclipse.equinox.p2.touchpoint.eclipse.markStarted(started: true)

但到目前为止,我尝试过的所有排列都没有任何效果:因为没有任何反应,捆绑包没有标记为已启动,也没有报告错误)。

任何指针都会非常受欢迎。与 Eclipse Equinox Galileo (3.5.2) 一起使用......与 Helios 相关的答案也将非常有用。

【问题讨论】:

    标签: eclipse equinox p2


    【解决方案1】:

    “单位.#”。 p2.inf 条目会创建一个新的Installable Unit,它们不会修改其他现有的 IU。

    您基本上必须创建一个完整的Installable Unit fragment。该片段具有相关说明并附加到您的捆绑包的 IU。然后你需要从你的功能中添加一个需求到这个新的 IU。

    PDE/Build 在构建产品时会自动执行此操作。您可以通过创建一个小 rcp 产品构建来查看生成的 p2.inf,该构建具有您的捆绑包的起始级别。
    在产品构建中生成的 p2.inf 将是 buildDirectory/features/org.eclipse.pde.build.container.feature/product/p2.inf

    这是我从一个构建中修改的示例,该构建设置了org.eclipse.equinox.common 的起始级别。 $version$ 将被 p2.inf 所属功能的版本替换。请注意“hostRequirements”,它指定了我们作为片段的捆绑包。

    #create a requirement on the IU fragment we are creating
    requires.2.namespace=org.eclipse.equinox.p2.iu
    requires.2.name=configure.org.eclipse.equinox.common
    requires.2.range=[$version$,$version$]
    requires.2.greedy=true
    
    #create a IU frament named configure.org.eclipse.equinox.common
    units.0.id=configure.org.eclipse.equinox.common
    units.0.version=$version$
    units.0.provides.1.namespace=org.eclipse.equinox.p2.iu
    units.0.provides.1.name=configure.org.eclipse.equinox.common
    units.0.provides.1.version=$version$
    units.0.instructions.install=installBundle(bundle:${artifact});
    units.0.instructions.uninstall=uninstallBundle(bundle:${artifact});
    units.0.instructions.unconfigure=setStartLevel(startLevel:-1);markStarted(started:false);
    units.0.instructions.configure=setStartLevel(startLevel:2);markStarted(started:true);
    units.0.hostRequirements.1.namespace=osgi.bundle
    units.0.hostRequirements.1.name=org.eclipse.equinox.common
    units.0.hostRequirements.1.range=[3.6.0.v20100503,3.6.0.v20100503]
    units.0.hostRequirements.1.greedy=false
    units.0.hostRequirements.2.namespace=org.eclipse.equinox.p2.eclipse.type
    units.0.hostRequirements.2.name=bundle
    units.0.hostRequirements.2.range=[1.0.0,2.0.0)
    units.0.hostRequirements.2.greedy=false
    units.0.requires.1.namespace=osgi.bundle
    units.0.requires.1.name=org.eclipse.equinox.common
    units.0.requires.1.range=[3.6.0.v20100503,3.6.0.v20100503]
    units.0.requires.1.greedy=false
    

    问题的答案:

    1. 0、1、2

      这些数字有些随意,它们仅用于将一组属性(requiresunits 或其他)与另一组属性分开。这里的requires 使用了“2”,只是因为我从 pde.build 生成的大型 p2.inf 中复制了它,而忘记像我做units.0 一样更改它。

    2. 这一切有必要吗?

      是的。需要 type=bundle 上的第二个 hostRequirements。在 Helios 中,除了翻译片段外,一个 IU 只能附加一个片段。通常,可以使用默认 IU 来设置所有 osgi 捆绑包的默认启动级别。为了选择我们的自定义片段而不是默认片段,它必须具有更高的“特异性”,即满足的主机要求的数量。

      对于“安装”

      units.0.instructions.install=installBundle(bundle:${artifact}); units.0.instructions.uninstall=uninstallBundle(bundle:${artifact});

      instructions.installinstructions.uninstall 指的是 p2 过程的阶段。 installBundleuninstallBundle 指的是 OSGi 意义上的安装/卸载。必须先将捆绑包安装到 OSGi 系统中,然后才能执行任何其他操作。这基本上涉及将其添加到 config.ini 或 org.eclipse.equinox.simpleconfigurator/bundles.info 文件中。

      大多数 p2 安装已经包含一个默认配置 IU,它将安装并设置捆绑包的默认启动级别 (4)。但是,目前每个包只能应用一个配置片段,因此当您像这样添加自己的配置片段时,默认值不再应用于您的包。

    3. 主机要求。可安装的单元片段页面仅描述了片段是什么,没有关于如何创建片段的参考。在Customizing Metadata 页面上简要提到了它,但没有解释。

      文档,在 wiki 上的 p2 category 下有一堆东西。 touchpoint instructions 上的页面可能很有趣。 help.eclipse.org 有一些帮助,但总的来说,我认为这比有文档的内容要高级一些。

    【讨论】:

    • 看来这里有不少魔力。你能解释一下 0's、1's 和 2's 的意义……它们是任意的(在这种情况下,为什么从 requires.2 而不是 requires.0 开始?)还是由上下文决定?另外,所有这些都是必要的吗?例如 units.0.instructions.install 对我来说看起来是多余的。更一般地说,这些东西记录在哪里?例如,您说它是 hostRequirements 条目,它指定这是哪个捆绑包的片段,但在您链接到描述可安装单元片段的页面上没有提到这个。
    • 只是为了确保我已经正确理解了编号的任意性,如果将“requires.2”始终替换为“requires.0”,其含义是否会保持不变? “units.0.provides.1”替换为“units.0.provides.0”; “units.0.hostRequirements.1”替换为“units.0.hostRequirements.0”; “units.0.hostRequirements.2”替换为“units.0.hostRequirements.1”; “units.0.requires.1” by “units.0.requires.0”
    猜你喜欢
    • 1970-01-01
    • 2017-01-19
    • 2014-11-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2011-03-06
    • 2018-08-14
    • 2012-07-10
    相关资源
    最近更新 更多