代码之家  ›  专栏  ›  技术社区  ›  Miles Sabin

在Equinox中,是否可以将OSGi包标记为从其包含功能的p2.inf开始?

  •  8
  • Miles Sabin  · 技术社区  · 15 年前

    我有一个Eclipse特性,其中包括几个包。我想告诉P2在安装该功能时将其中一个捆绑包标记为已启动。这可以使用bundles自己的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)
    

    但是到目前为止,我尝试过的排列都没有任何效果:就像什么都没有发生一样,包没有标记为已启动,也没有报告任何错误)。

    任何提示都是非常欢迎的。这是日食春分伽利略(3.5.2)……关于太阳神的答案也非常有用。

    1 回复  |  直到 15 年前
        1
  •  9
  •   Andrew Niefer    15 年前

    “units..”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$ will get replaced by the version from the feature that the p2.inf belongs to. 请注意“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

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

    2. 所有这些都是必要的吗?

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

      用于“安装”

      units.0.instructions.install=install bundle(捆绑包:$工件); units.0.instructions.uninstall=uninstall bundle(bundle:$artifact);

      这个 instructions.install instructions.uninstall 请参阅P2流程的各个阶段。这个 installBundle uninstallBundle 请参阅OSGi意义上的安装/卸载。必须先将包安装到OSGi系统中,然后才能执行其他操作。这基本上包括将其添加到config.ini或org.eclipse.equinox.simpleconfigurator/bundles.info文件中。

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

    3. 主机要求。InstallableUnitFragments页面只描述片段是什么,没有关于如何创建片段的引用。上面提到了Biefly Customizing Metadata 第页,但没有解释。

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