From 07514467e3ec27c0ec128ec30f63daa1646369a6 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 18 Mar 2019 09:27:43 +0100 Subject: [PATCH] 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. --- testsuite-osgi/pom.xml | 92 ++++++++++++------- .../io/netty/osgitests/OsgiBundleTest.java | 66 +++++-------- 2 files changed, 79 insertions(+), 79 deletions(-) diff --git a/testsuite-osgi/pom.xml b/testsuite-osgi/pom.xml index 9c378200dd..75c8a599bc 100644 --- a/testsuite-osgi/pom.xml +++ b/testsuite-osgi/pom.xml @@ -46,6 +46,40 @@ true + + + linux + + + linux + + + + + ${project.groupId} + netty-transport-native-epoll + ${project.version} + test + + + + + + mac + + + mac + + + + + ${project.groupId} + netty-transport-native-kqueue + ${project.version} + test + + + @@ -154,9 +188,14 @@ - org.ops4j.pax.exam - pax-exam-container-native - ${exam.version} + org.apache.felix + org.apache.felix.configadmin + 1.9.14 + + + org.apache.felix + org.apache.felix.framework + 6.0.2 test @@ -167,54 +206,36 @@ org.ops4j.pax.exam - pax-exam + pax-exam-container-native ${exam.version} test org.ops4j.pax.exam - pax-exam-spi + pax-exam-link-assembly ${exam.version} test - - org.ops4j.pax.exam - pax-exam-link-mvn - ${exam.version} - test - - - org.ops4j.pax.url - pax-url-wrap - 2.4.7 - - - - org.osgi - org.osgi.core - 6.0.0 - test - - - org.apache.felix - org.apache.felix.framework - 5.6.10 - test - - - org.ops4j.pax.exam - maven-paxexam-plugin + com.github.veithen.alta + alta-maven-plugin + 0.6.2 - generate-config - generate-depends-file + generate-test-resources + + %bundle.symbolicName%.link + %url% + + test + + @@ -222,6 +243,9 @@ maven-surefire-plugin ${skipOsgiTestsuite} + + ${project.build.directory}/generated-test-resources/alta + diff --git a/testsuite-osgi/src/test/java/io/netty/osgitests/OsgiBundleTest.java b/testsuite-osgi/src/test/java/io/netty/osgitests/OsgiBundleTest.java index 60034bddcc..a55a436d73 100644 --- a/testsuite-osgi/src/test/java/io/netty/osgitests/OsgiBundleTest.java +++ b/testsuite-osgi/src/test/java/io/netty/osgitests/OsgiBundleTest.java @@ -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 BUNDLES; + private static final Collection LINKS; static { - final Set 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 links = new HashSet(); - 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); } }