我正在使用 Tycho 构建和测试一些 eclipse 插件。我有一个包含许多平台特定片段的包。我还有一个测试包,它使用 tycho-surefire-plugin 来测试具有平台特定片段的原始包。但是,Tycho 并未将当前平台的片段纳入测试运行时。
所有特定于平台的片段看起来都像下面列出的 win64 片段 list 。 (实际上总共有六个片段,一个用于我需要支持的每个平台组合。)
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Liferay AUI Upgrade Tool Win64
Bundle-SymbolicName: com.liferay.laut.win32.win32.x86_64;singleton:=true
Bundle-Version: 1.0.2.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Fragment-Host: com.liferay.ide.alloy.core
Eclipse-BundleShape: dir
Eclipse-PlatformFilter: (& (osgi.ws=win32)(osgi.os=win32)(osgi.arch=x86_64))
Bundle-Vendor: Liferay, Inc.
示例 win64 片段 pom.xml 的 <build>
节
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<configuration>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
当我尝试执行我的 Tycho 构建并且它运行 surefire 测试插件时(无论我尝试使用哪个操作系统),正确的平台片段没有添加到运行时中。
我看过 various posts在 stackoverflow 上关于类似的问题,但在那些情况下,加载到测试运行时的片段不是带有操作系统过滤器的特定于平台的片段。
最佳答案
这是一个很好的问题 - 但如果您知道正确的技巧,幸运的是解决方案并不复杂:只需配置 Tycho 以将包含所有片段的功能包含到测试运行时中。
在
eclipse-feature
中创建一个特征包括所有的模块 native 片段。确保平台过滤每个 插件正确:在 feature.xml 编辑器的 Plug-Ins 选项卡上, 您需要选择每个片段适用的正确 os/ws/arch 到。这是一些手动操作,但通常可以重复使用 将您的片段包含到 p2 存储库/更新站点的功能。使用以下 POM 配置将此功能包含到测试运行时:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho-version}</version> <configuration> <dependency-resolution> <extraRequirements> <requirement> <type>eclipse-feature</type> <id>fragment-containing-feature</id> <versionRange>0.0.0</versionRange> </requirement> </extraRequirements> </dependency-resolution> </configuration> </plugin>
一个潜在的陷阱是 <environments>
eclipse-feature
的配置模块:您不需要该模块的任何特殊功能;只需让模块继承 <environments>
来自父 POM 的配置。请注意,父 POM 应配置您的构建支持的所有环境 - 只有片段模块需要覆盖全局配置。
关于java - 如何让 Tycho 将特定于平台的片段加载到任何操作系统的测试运行时中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20876695/