How can I make Tycho load platform specific fragment into the test runtime for any OS?
Asked Answered
T

1

9

I'm using Tycho to build and test some eclipse plugins. I have one bundle that has many platform specific fragments. I also have one test bundle that is using tycho-surefire-plugin to test the original bundle that has the platform specific fragments. However, Tycho is not including the current platform's fragment into the test runtime.

All of the platform specific fragments look like the win64 fragment manifest listed below. (There are actually six fragments in total, one for each platform combination I need to support.)

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.

Example win64 fragment pom.xml's <build> section

<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>

When I try to execute my Tycho build and it runs the surefire test plugin (no matter which OS I try), the correct platform fragment is not added into the runtime.

I've seen various posts on stackoverflow about similar questions but in those cases the fragments loaded into the test runtime were not platform-specific fragments with OS filters.

Throstle answered 2/1, 2014 at 5:8 Comment(0)
P
10

This is a good question - but if you know the right trick, the solution is fortunately not complicated: Simply configure Tycho to include the feature which contains all fragments into the test runtime.

  1. Create a feature in an eclipse-feature module which includes all the native fragments. Make sure that the platform filters for each plug-in is correct: On the Plug-Ins tab of the feature.xml editor, you need to select the correct os/ws/arch that each fragment applies to. This is some manual effort, but typically can re-use this feature to include your fragments into a p2 repository/update site.

  2. Include this feature into the test runtime with the following POM configuration:

    <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>
    

A potential pitfall is the <environments> configuration of the eclipse-feature module: You don't need anything special for that module; just have the module inherit the <environments> configuration from the parent POM. Note that the parent POM shall configure all the environments your build supports - and only the fragment modules need to override the global configuration.

Palladium answered 2/1, 2014 at 10:37 Comment(3)
So for this fragment-containing-feature, what if that feature is being built by the current maven reactor? I mean the fragment I'm trying to test is also the same fragment that is being built (as well as the containing feature). Can this construct support this?Throstle
I've tried to do my best to build a multi-module test case for this here: github.com/gamerson/liferay-ide-sandbox/tree/master/… However when I run this test from commandline on my windows64bit environment it fails as the unit test is unable to find the readme.txt from the fragments.Throstle
In your test project, you have configured the extraRequirements on the tycho-surefire-plugin. This has no effect. The extraRequirements must be configured on the target-platform-configuration plugin.Palladium

© 2022 - 2024 — McMap. All rights reserved.