Adjust testsuite-osgi to resolve bundles from local build (#8944)

Motivation:

testsuite-osgi currently resolve its bundles from the local / remote maven repository, which means you will need to do `mvn install` before it can pick up the bundles. Beside this this also means that you may pick up old versions if you forgot to call `install` before running it.

Modifications:

Use alta-maven-plugin to be able to resolve bundles from the local build directory during the build.

Result:

No need to install jars before running the OSGI testsuite and ensure we always test with the latest jars.
This commit is contained in:
Norman Maurer 2019-03-18 09:27:43 +01:00 committed by GitHub
parent eab849176b
commit d0fb41e529
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 89 deletions

View File

@ -46,6 +46,40 @@
<skipOsgiTestsuite>true</skipOsgiTestsuite> <skipOsgiTestsuite>true</skipOsgiTestsuite>
</properties> </properties>
</profile> </profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles> </profiles>
<dependencies> <dependencies>
@ -146,12 +180,6 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-rxtx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>netty-transport-sctp</artifactId> <artifactId>netty-transport-sctp</artifactId>
@ -166,9 +194,14 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.ops4j.pax.exam</groupId> <groupId>org.apache.felix</groupId>
<artifactId>pax-exam-container-native</artifactId> <artifactId>org.apache.felix.configadmin</artifactId>
<version>${exam.version}</version> <version>1.9.14</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>6.0.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -179,54 +212,36 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.ops4j.pax.exam</groupId> <groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId> <artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version> <version>${exam.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.ops4j.pax.exam</groupId> <groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-spi</artifactId> <artifactId>pax-exam-link-assembly</artifactId>
<version>${exam.version}</version> <version>${exam.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-wrap</artifactId>
<version>2.4.7</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.6.10</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.ops4j.pax.exam</groupId> <groupId>com.github.veithen.alta</groupId>
<artifactId>maven-paxexam-plugin</artifactId> <artifactId>alta-maven-plugin</artifactId>
<version>0.6.2</version>
<executions> <executions>
<execution> <execution>
<id>generate-config</id>
<goals> <goals>
<goal>generate-depends-file</goal> <goal>generate-test-resources</goal>
</goals> </goals>
<configuration>
<name>%bundle.symbolicName%.link</name>
<value>%url%</value>
<dependencySet>
<scope>test</scope>
</dependencySet>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -234,6 +249,9 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<skip>${skipOsgiTestsuite}</skip> <skip>${skipOsgiTestsuite}</skip>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/generated-test-resources/alta</additionalClasspathElement>
</additionalClasspathElements>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -19,21 +19,16 @@ package io.netty.osgitests;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty; import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
import static org.ops4j.pax.exam.CoreOptions.junitBundles; import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty; import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.wrappedBundle; import static org.ops4j.pax.exam.CoreOptions.url;
import static org.osgi.framework.Constants.FRAMEWORK_BOOTDELEGATION; import static org.osgi.framework.Constants.FRAMEWORK_BOOTDELEGATION;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -44,45 +39,25 @@ import io.netty.util.internal.PlatformDependent;
@RunWith(PaxExam.class) @RunWith(PaxExam.class)
public class OsgiBundleTest { public class OsgiBundleTest {
private static final Pattern SLASH = Pattern.compile("/", Pattern.LITERAL); private static final Collection<String> LINKS;
private static final String DEPENCIES_LINE = "# dependencies";
private static final String GROUP = "io.netty";
private static final Collection<String> BUNDLES;
static { static {
final Set<String> artifacts = new HashSet<String>(); final Set<String> links = new HashSet<String>();
final File f = new File("target/classes/META-INF/maven/dependencies.properties");
try {
final BufferedReader r = new BufferedReader(new FileReader(f));
try {
boolean haveDeps = false;
while (true) { final File directory = new File("target/generated-test-resources/alta/");
final String line = r.readLine(); File[] files = directory.listFiles(new FilenameFilter() {
if (line == null) { @Override
// End-of-file public boolean accept(File dir, String name) {
break; return (name.startsWith("io.netty") || name.startsWith("com.barchart.udt")) && name.endsWith(".link");
}
// We need to ignore any lines up to the dependencies
// line, otherwise we would include ourselves.
if (DEPENCIES_LINE.equals(line)) {
haveDeps = true;
} else if (haveDeps && line.startsWith(GROUP)) {
final String[] split = SLASH.split(line);
if (split.length > 1) {
artifacts.add(split[1]);
}
}
}
} finally {
r.close();
} }
} catch (IOException e) { });
throw new ExceptionInInitializerError(e); if (files == null) {
throw new IllegalStateException(directory + " is not found or is not a directory");
} }
for (File f: files) {
BUNDLES = artifacts; links.add(f.getName());
}
LINKS = links;
} }
@Configuration @Configuration
@ -92,13 +67,10 @@ public class OsgiBundleTest {
// Avoid boot delegating sun.misc which would fail testCanLoadPlatformDependent() // Avoid boot delegating sun.misc which would fail testCanLoadPlatformDependent()
options.add(frameworkProperty(FRAMEWORK_BOOTDELEGATION).value("com.sun.*")); options.add(frameworkProperty(FRAMEWORK_BOOTDELEGATION).value("com.sun.*"));
options.add(systemProperty("pax.exam.osgi.unresolved.fail").value("true")); options.add(systemProperty("pax.exam.osgi.unresolved.fail").value("true"));
options.addAll(Arrays.asList(junitBundles())); options.add(junitBundles());
options.add(mavenBundle("com.barchart.udt", "barchart-udt-bundle").versionAsInProject()); for (String link : LINKS) {
options.add(wrappedBundle(mavenBundle("org.rxtx", "rxtx").versionAsInProject())); options.add(url("link:classpath:" + link));
for (String name : BUNDLES) {
options.add(mavenBundle(GROUP, name).versionAsInProject());
} }
return options.toArray(new Option[0]); return options.toArray(new Option[0]);
@ -107,11 +79,11 @@ public class OsgiBundleTest {
@Test @Test
public void testResolvedBundles() { public void testResolvedBundles() {
// No-op, as we just want the bundles to be resolved. Just check if we tested something // No-op, as we just want the bundles to be resolved. Just check if we tested something
assertFalse("At least one bundle needs to be tested", BUNDLES.isEmpty()); assertFalse("At least one bundle needs to be tested", LINKS.isEmpty());
} }
@Test @Test
public void testCanLoadPlatformDependent() { public void testCanLoadPlatformDependent() {
assertFalse(PlatformDependent.hasUnsafe()); assertFalse(PlatformDependent.addressSize() == 0);
} }
} }