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
parent f1bc4569c1
commit 07514467e3
2 changed files with 79 additions and 79 deletions

View File

@ -46,6 +46,40 @@
<skipOsgiTestsuite>true</skipOsgiTestsuite>
</properties>
</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>
<dependencies>
@ -154,9 +188,14 @@
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<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>
</dependency>
<dependency>
@ -167,54 +206,36 @@
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-spi</artifactId>
<artifactId>pax-exam-link-assembly</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</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>
<build>
<plugins>
<plugin>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>maven-paxexam-plugin</artifactId>
<groupId>com.github.veithen.alta</groupId>
<artifactId>alta-maven-plugin</artifactId>
<version>0.6.2</version>
<executions>
<execution>
<id>generate-config</id>
<goals>
<goal>generate-depends-file</goal>
<goal>generate-test-resources</goal>
</goals>
<configuration>
<name>%bundle.symbolicName%.link</name>
<value>%url%</value>
<dependencySet>
<scope>test</scope>
</dependencySet>
</configuration>
</execution>
</executions>
</plugin>
@ -222,6 +243,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>${skipOsgiTestsuite}</skip>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/generated-test-resources/alta</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>

View File

@ -19,20 +19,16 @@ package io.netty.osgitests;
import static org.junit.Assert.assertFalse;
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
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.url;
import static org.osgi.framework.Constants.FRAMEWORK_BOOTDELEGATION;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -43,45 +39,25 @@ import io.netty.util.internal.PlatformDependent;
@RunWith(PaxExam.class)
public class OsgiBundleTest {
private static final Pattern SLASH = Pattern.compile("/", Pattern.LITERAL);
private static final String DEPENCIES_LINE = "# dependencies";
private static final String GROUP = "io.netty";
private static final Collection<String> BUNDLES;
private static final Collection<String> LINKS;
static {
final Set<String> artifacts = new HashSet<>();
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;
final Set<String> links = new HashSet<String>();
while (true) {
final String line = r.readLine();
if (line == null) {
// End-of-file
break;
}
// 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();
final File directory = new File("target/generated-test-resources/alta/");
File[] files = directory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return (name.startsWith("io.netty") || name.startsWith("com.barchart.udt")) && name.endsWith(".link");
}
} catch (IOException e) {
throw new ExceptionInInitializerError(e);
});
if (files == null) {
throw new IllegalStateException(directory + " is not found or is not a directory");
}
BUNDLES = artifacts;
for (File f: files) {
links.add(f.getName());
}
LINKS = links;
}
@Configuration
@ -91,10 +67,10 @@ public class OsgiBundleTest {
// Avoid boot delegating sun.misc which would fail testCanLoadPlatformDependent()
options.add(frameworkProperty(FRAMEWORK_BOOTDELEGATION).value("com.sun.*"));
options.add(systemProperty("pax.exam.osgi.unresolved.fail").value("true"));
options.addAll(Arrays.asList(junitBundles()));
options.add(junitBundles());
for (String name : BUNDLES) {
options.add(mavenBundle(GROUP, name).versionAsInProject());
for (String link : LINKS) {
options.add(url("link:classpath:" + link));
}
return options.toArray(new Option[0]);
@ -103,11 +79,11 @@ public class OsgiBundleTest {
@Test
public void testResolvedBundles() {
// 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
public void testCanLoadPlatformDependent() {
assertFalse(PlatformDependent.hasUnsafe());
assertFalse(PlatformDependent.addressSize() == 0);
}
}