diff --git a/build.gradle b/build.gradle index 7222394227..0995aa5735 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import aQute.bnd.gradle.BundleTaskConvention buildscript { repositories { @@ -303,7 +304,6 @@ configure(rootProject) { project -> } } - jar { classifier = 'original' @@ -319,6 +319,14 @@ configure(rootProject) { project -> check.dependsOn jacocoTestReport shadowJar { + configure { + it.convention.plugins.bundle = new BundleTaskConvention(it) + doLast { + buildBundle() + } + } + bnd(bndOptions) + classifier = null dependsOn(project.tasks.jar) diff --git a/src/jarFileTest/java/reactor/netty/AbstractJarFileTest.java b/src/jarFileTest/java/reactor/netty/AbstractJarFileTest.java index 50439fae6b..84814b1860 100644 --- a/src/jarFileTest/java/reactor/netty/AbstractJarFileTest.java +++ b/src/jarFileTest/java/reactor/netty/AbstractJarFileTest.java @@ -28,11 +28,12 @@ */ class AbstractJarFileTest { + static Path jarFilePath; static Path root; static { try { - Path jarFilePath = Paths.get(System.getProperty("jarFile")); + jarFilePath = Paths.get(System.getProperty("jarFile")); URI jarFileUri = new URI("jar", jarFilePath.toUri().toString(), null); FileSystem fileSystem = FileSystems.newFileSystem(jarFileUri, emptyMap()); root = fileSystem.getPath("/"); diff --git a/src/jarFileTest/java/reactor/netty/JarFileShadingTest.java b/src/jarFileTest/java/reactor/netty/JarFileShadingTest.java index 89e95fce5a..38a4db808a 100644 --- a/src/jarFileTest/java/reactor/netty/JarFileShadingTest.java +++ b/src/jarFileTest/java/reactor/netty/JarFileShadingTest.java @@ -15,17 +15,29 @@ */ package reactor.netty; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.assertj.core.api.ListAssert; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.*; /** - * This test must be executed with Gradle because it requires a shadow JAR + * This test must be executed with Gradle because it requires a shadow JAR. + * For example it can be run with {@code ./gradlew jarFileTest --tests *JarFileShadingTest} */ public class JarFileShadingTest extends AbstractJarFileTest { @@ -59,6 +71,55 @@ public void testMetaInf() throws Exception { } } + @Test + public void testManifestContent() throws IOException { + ZipFile jar = new ZipFile(jarFilePath.toString()); + ZipEntry manifest = jar + .stream() + .filter(ze -> ze.getName().equals("META-INF/MANIFEST.MF")) + .findFirst() + .get(); + + String version = jarFilePath.getFileName().toString() + .replace("reactor-netty-", "") + .replace("-original.jar", "") + .replace(".jar", ""); + //for the case where there is a customVersion. OSGI only want 4 components to the version, + //so BND would simply remove the 4th dot between customVersion and RELEASE/BUILD-SNAPSHOT. + String osgiVersion = Arrays.stream(version.split("\\.", 4)) + .map(comp -> comp.replace(".", "")) + .collect(Collectors.joining(".")); + + try (InputStream inputStream = jar.getInputStream(manifest); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, UTF_8))) { + String lines = reader.lines() + //we eliminate the intermediate details of import-package & co + //since we won't assert them -> so that assertion error is more readable + .filter(s -> !s.startsWith(" ")) + .collect(Collectors.joining("\n")); + assertThat(lines) + .as("base content") + .contains( + "Implementation-Title: reactor-netty", + "Implementation-Version: " + version, + "Automatic-Module-Name: reactor.netty" + ); + assertThat(lines) + .as("OSGI content") + .contains( + "Bundle-Name: reactor-netty", + "Bundle-SymbolicName: io.projectreactor.netty.reactor-netty", + "Import-Package: ", //only assert the section is there + "Require-Capability:", + "Export-Package:", //only assert the section is there + "Bundle-Version: " + osgiVersion + ); + } + catch (IOException ioe) { + fail("Coudn't inspect the manifest", ioe); + } + } + @SuppressWarnings("unchecked") private ListAssert assertThatFileList(Stream path) { return (ListAssert) assertThat(path)