Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGi-bundles not activating when run by Tycho surefire

I have several OSGi bundles that are built in Eclipse using normal manifest-managed dependencies and external builds with Maven Tycho.

Running the bundles inside of Eclipse on Equinox works fine. Building them with Tycho works fine.

Now I want to use Tycho Surefire to run integration tests and for that I created a simple test bundle that contains some basic tests. The bundles under test rely on some other bundles present in the OSGi-container and some minor start level tweaks in order to run correctly - like I said, the bundles themself start up perfectly fine when running them normally on Equinox.

So to mimic that for Tycho Surefire, I specified the following in the pom.xml of the test bundle:

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>0.21.0</version>
            <configuration>
                <bundleStartLevel>
                    <bundle>
                        <id>org.hibernate.osgi</id>
                        <level>6</level>
                        <autoStart>true</autoStart>
                    </bundle>
                    <!-- plus a few more bundles in the real pom.xml -->
                </bundleStartLevel>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <configuration>
                <dependency-resolution>
                    <extraRequirements>
                        <requirement>
                            <type>eclipse-plugin</type>
                            <id>org.hibernate.entitymanager</id>
                            <versionRange>4.2.12.Final</versionRange>
                        </requirement>
                        <requirement>
                            <type>eclipse-plugin</type>
                            <id>org.hibernate.osgi</id>
                            <versionRange>4.2.12.Final</versionRange>
                        </requirement>
                        <!-- plus a few more bundles in the real pom.xml -->
                    </extraRequirements>
                </dependency-resolution>
            </configuration>
        </plugin>
    </plugins>
</build>

Interestingly, the tests failed. After some research I found out how I can access the OSGi console during/after the failed test run to investigate the problem further (OSGi console after running tycho tests).

My findings are, that although all necessary bundles (all transitively derived bundles and all manually specified ones) are present in the OSGi-container only the ones with a distinctive <bundleStartLevel> have been started (plus the OSGi-core-bundles of course).

So given the above example, my findings are that while both org.hibernate.osgi and org.hibernate.entitymanager have been resolved, only the first is in the 'ACTIVE' state. This obviously messes up the whole startup and my guess is that the tests would run fine if the bundles would start up as expected.

When I look at a "normal" Eclipse-OSGi-Launch configuration, there is a parameter "Default Auto-Start" that is set to true by default. I did not find anything like that in the Tycho Surefire documentation, but is it possible that setting a specific start level for some bundles somehow overrides the auto start of other bundles? At least I wouldn't guess that Tycho isn't auto starting any bundles at all by default...

I'd appreciate any hints on how to investigate that issue further or any clues for how I can get Tycho to start my bundles without having to specify a distinct start level for each.

like image 501
sina Avatar asked Nov 27 '14 15:11

sina


1 Answers

If anyone is still stumbling onto this:

Since Tycho 0.23 the bundle auto start is configurable.

<configuration>
  <defaultStartLevel>
    <level>7</level>
    <autoStart>true</autoStart>
  </defaultStartLevel>
</configuration>
like image 140
sina Avatar answered Nov 09 '22 21:11

sina