“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
问题解答:
-
0,1,2
这些数字有些随意,它们只用于分隔一组属性(
requires
或
units
或者其他的)。这个
要求
这里使用“2”仅仅是因为我从pde.build生成的大型p2.inf中复制了它,而忘记了像使用units.0那样更改它。
-
所有这些都是必要的吗?
对。第二
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)。但是,当前每个包只能应用一个配置片段,因此当您像这样添加自己的配置片段时,默认值不再应用于包。
-
主机要求。InstallableUnitFragments页面只描述片段是什么,没有关于如何创建片段的引用。上面提到了Biefly
Customizing Metadata
第页,但没有解释。
文档,wiki上有很多东西
p2 category
. 页面上的
touchpoint instructions
可能很有趣。有一些帮助
help.eclipse.org
但总的来说,我认为这比现有的文档要高级一些。