Skip to content

Commit

Permalink
Adjust testsuite-osgi to resolve bundles from local build (netty#8944)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
normanmaurer authored Mar 18, 2019
1 parent eab8491 commit d0fb41e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 88 deletions.
96 changes: 57 additions & 39 deletions testsuite-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -146,12 +180,6 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-rxtx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport-sctp</artifactId>
Expand All @@ -166,74 +194,64 @@
</dependency>

<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<version>1.9.14</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>${exam.version}</version>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>6.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<artifactId>pax-exam-junit4</artifactId>
<version>${exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-spi</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-link-mvn</artifactId>
<artifactId>pax-exam-link-assembly</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>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>${skipOsgiTestsuite}</skip>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/generated-test-resources/alta</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
Expand Down
70 changes: 21 additions & 49 deletions testsuite-osgi/src/test/java/io/netty/osgitests/OsgiBundleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@
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.wrappedBundle;
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;
Expand All @@ -44,45 +39,25 @@

@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<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;
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
Expand All @@ -92,13 +67,10 @@ public final Option[] config() {
// 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(mavenBundle("com.barchart.udt", "barchart-udt-bundle").versionAsInProject());
options.add(wrappedBundle(mavenBundle("org.rxtx", "rxtx").versionAsInProject()));
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]);
Expand All @@ -107,11 +79,11 @@ public final Option[] config() {
@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);
}
}

0 comments on commit d0fb41e

Please sign in to comment.