0

有一个测试失败,因为IllegalStateExceptionfrom Platform.getPlugin("...")which 调用@Deprecated org.eclipse.core.runtime.Platform.getPluginRegistry()“仅在安装了兼容层时才有效,否则不得使用”。

此测试在开发期间在工作空间中工作,但在由 Maven Tycho Surefire 运行时失败(可重现)。我收集到这与此有关org.eclipse.core.runtime.compatibility,因此尝试在以下位置执行此操作pom.xml

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-surefire-plugin</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        ...     
        <dependencies>
            <dependency>
                <type>p2-installable-unit</type>
                <artifactId>org.eclipse.core.runtime.compatibility</artifactId>
            </dependency>
        </dependencies>
        <bundleStartLevel>
            <bundle>
                <id>org.eclipse.core.runtime.compatibility</id>
                <level>4</level>
                <autoStart>true</autoStart>
            </bundle>
        </bundleStartLevel>
    </configuration>

不幸的是,即使有这个(上面)它仍然不起作用 - 我做错了什么?

作为解决此问题的替代答案,我想我可以尝试在测试中调整该行以使用不推荐使用的其他 API Platform.getPlugin()- 但是如何在不使用任何不推荐使用的情况下获得给定 ID 的 org.eclipse.core.runtime.Plugin需要此兼容层的 API 会导致我出现问题吗?

4

1 回答 1

1

实际上只是Platform.getBundle()没有Platform.getPlugin()做到这一点。

此外,以防万一其他人遇到这个问题,额外的依赖配置确实有效——它只会在我的特定测试用例中导致另一个不相关的 IllegalStateException,这让我感到困惑。

于 2016-01-27T18:10:54.377 回答