【问题标题】:OSGi-bundles not activating when run by Tycho surefire由 Tycho surefire 运行时 OSGi 捆绑包未激活
【发布时间】:2014-11-27 15:03:24
【问题描述】:

我有几个在 Eclipse 中构建的 OSGi 包,它们使用普通清单管理的依赖项和使用 Maven Tycho 的外部构建。

在 Equinox 上的 Eclipse 内运行包可以正常工作。使用 Tycho 构建它们效果很好。

现在我想使用 Tycho Surefire 运行集成测试,为此我创建了一个包含一些基本测试的简单测试包。正在测试的包依赖于 OSGi 容器中存在的一些其他包和一些小的启动级别调整才能正确运行 - 就像我说的,当在 Equinox 上正常运行时,包本身启动得非常好。

所以为了模仿 Tycho Surefire,我在测试包的 pom.xml 中指定了以下内容:

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

有趣的是,测试失败了。经过一番研究,我发现了如何在测试运行失败期间/之后访问 OSGi 控制台以进一步调查问题 (OSGi console after running tycho tests)。

我的发现是,尽管 OSGi 容器中存在所有必要的捆绑包(所有传递派生的捆绑包和所有手动指定的捆绑包),但只有具有独特 &lt;bundleStartLevel&gt; 的捆绑包已启动(加上 OSGi-core-bundles当然)。

因此,鉴于上述示例,我的发现是,虽然 org.hibernate.osgiorg.hibernate.entitymanager 都已解决,但只有第一个处于“活动”状态。这显然会扰乱整个启动过程,我的猜测是,如果捆绑包按预期启动,测试会运行良好。

当我查看“正常”的 Eclipse-OSGi-Launch 配置时,有一个参数“默认自动启动”默认设置为 true。我在 Tycho Surefire 文档中没有找到类似的内容,但是否有可能为某些捆绑包设置特定的启动级别以某种方式覆盖其他捆绑包的自动启动?至少我不会猜到 Tycho 默认情况下根本不会自动启动任何捆绑包......

如果能提供任何有关如何进一步调查该问题的提示,或任何有关如何让 Tycho 启动我的捆绑包而无需为每个捆绑包指定不同启动级别的线索,我将不胜感激。

【问题讨论】:

  • 是否有 Equinox 系统属性可以启动所有捆绑包?如果是,您可以尝试将其设置为systemProperty。我不确定你是否会被bug 356193 击中。

标签: java maven eclipse-plugin tycho tycho-surefire-plugin


【解决方案1】:

如果还有人遇到这个问题:

从 Tycho 0.23 开始,捆绑包自动启动是可配置的。

<configuration>
  <defaultStartLevel>
    <level>7</level>
    <autoStart>true</autoStart>
  </defaultStartLevel>
</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-31
    • 2014-01-12
    • 2011-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多