OSGIバンドルをpax-maven-buildでビルドし、同時にpax-examでテストしようとしています。次のpax-examテスト構成でテストできるバンドルがプロビジョニングされています。
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class OSGILoaderTest {
@Inject
protected BundleContext bundleContext;
@Configuration
public Option[] config() throws MalformedURLException {
String projectRoot = // a path to my project
return options(
junitBundles(),
equinox(),
bundle(projectRoot + "libs/org.eclipse.core.variables_3.2.500.v20110511.jar"),
bundle(projectRoot + "libs/org.eclipse.core.contenttype_3.4.100.v20110423-0524.jar"),
bundle(projectRoot + "libs/org.eclipse.core.expressions_3.4.300.v20110228.jar"),
// etc...
);
}
@Test
public void getBundleContext() throws RodinDBException {
IRodinDB rodinDB = RodinCore.getRodinDB();
assertNotNull(rodinDB);
}
}
ここでは、私が提供したjarファイルからIRodinDBインスタンスにアクセスできることがわかります。
これで、プロビジョニングされたすべてのjarを使用する独自のバンドルをコード化できました。しかし、たとえば、自分のコードをテストすることすらできません。
@Test
public void checkAccessToRodinDbTest() {
VTGService service = null;
assertTrue(true);
}
コンパイル時にエラーが発生します:
[エラー]目標org.ops4j:maven-pax-plugin:1.5:testCompile(default-testCompile)の実行に失敗しました:コンパイルに失敗しました
[エラー]シンボルが見つかりません
[エラー]シンボル:クラスVTGService
maven-compiler-pluginのデフォルトの動作で予想されるのとは逆に、テストコンパイルでは「src / main/java」を認識できないようです。しかし、私の場合、mavenがコンパイラプラグインを使用せず、代わりにmaven-pax-pluginを使用していることがわかります。
問題は、pax-examを使用して自分のバンドルをテストするにはどうすればよいですか?
update1
ops4j pax mavenプラグイン( POM内でのPaxプラグインの使用のセクション)で利用可能な基本的な例でも同じ問題が発生しているように見えるため、これは最近のバージョンのmaven-pax-pluginの問題のようです。
update2
Dmytroからの要求に応じて、これは私のバンドルのpom.xmlです。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<relativePath>../poms/compiled/</relativePath>
<groupId>fr.xlim.ssd.vtg.build</groupId>
<artifactId>compiled-bundle-settings</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<properties>
<bundle.symbolicName>fr.xlim.ssd.vtg.bundle</bundle.symbolicName>
<bundle.namespace>fr.xlim.ssd.vtg.bundle</bundle.namespace>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>fr.xlim.ssd.vtg</groupId>
<artifactId>fr.xlim.ssd.vtg.bundle</artifactId>
<version>0.1-SNAPSHOT</version>
<name>${bundle.symbolicName}</name>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<type>pom</type>
<groupId>${project.parent.groupId}</groupId>
<artifactId>provision</artifactId>
<optional>true</optional>
</dependency>
<!-- not needed as equinox bundle are available in provision -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
<optional>true</optional>
</dependency-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-inject</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-mvn</artifactId>
<version>1.3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
これが最も洗練されたソリューションかどうかはわかりませんが、質問のソースコードのように独自のバンドルをインポートできるときに、新しいMavenプロジェクトを作成しました。
同じMavenプロジェクトでテストするための新しいバンドルとして自分のJavaソースを直接追加するエレガントな方法はありますか?それは不可能かもしれません(バンドルアセンブリ操作はコンパイルとテストの後に行われるため)...