Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: produce a no-dependencies shaded Mutiny jar #1613

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions no-deps/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-project</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>mutiny-no-deps</artifactId>
<name>SmallRye Mutiny - Shaded library</name>
<description>Variant of Mutiny with shaded dependencies</description>

<properties>
<revapi.skip>true</revapi.skip>
</properties>

<dependencies>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<createSourcesJar>true</createSourcesJar>
<shadeSourcesContent>true</shadeSourcesContent>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/jandex.idx</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/maven/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.jctools:jctools-core</artifact>
<includes>
<include>org/jctools/queues/atomic/unpadded/**</include>
<include>org/jctools/queues/MessagePassingQueue*</include>
<include>org/jctools/queues/IndexedQueueSizeUtil*</include>
<include>org/jctools/queues/QueueProgressIndicators*</include>
<include>org/jctools/queues/SupportsIterator*</include>
<include>org/jctools/queues/BaseLinkedQueue*</include>
<include>org/jctools/queues/LinkedQueueNode*</include>
<include>org/jctools/queues/atomic/AtomicQueueUtil*</include>
<include>org/jctools/queues/atomic/AtomicReferenceArrayQueue*</include>
<include>org/jctools/queues/atomic/SequencedAtomicReferenceArrayQueue*</include>
<include>org/jctools/queues/atomic/LinkedQueueAtomicNode*</include>
<include>org/jctools/util/SpscLookAheadUtil*</include>
<include>org/jctools/util/Pow2*</include>
<include>org/jctools/util/RangeUtil*</include>
<include>org/jctools/util/UnsafeAccess*</include>
</includes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries></manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.jctools</pattern>
<shadedPattern>io.smallrye.mutiny.shaded.org.jctools</shadedPattern>
</relocation>
<relocation>
<pattern>io.smallrye.common</pattern>
<shadedPattern>io.smallrye.mutiny.shaded.io.smallrye.common</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<configuration>
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
<includes>
<include>io/smallrye/mutiny/**/*.class</include>
</includes>
<excludes>
<exclude>io/smallrye/mutiny/shaded/**/*.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jandex-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
8 changes: 8 additions & 0 deletions no-deps/src/main/java/io/smallrye/mutiny/nodeps/Empty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.smallrye.mutiny.nodeps;

/**
* This is used as a placeholder to force the maven-javadoc-plugin to create a javadoc jar.
* Yes, you read it right :-)
*/
public interface Empty {
}
58 changes: 58 additions & 0 deletions no-deps/src/test/java/io/smallrye/mutiny/nodeps/ShadingIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.smallrye.mutiny.nodeps;

import static org.junit.jupiter.api.Assertions.*;

import java.time.Duration;
import java.util.List;
import java.util.Queue;

import org.junit.jupiter.api.Test;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.helpers.queues.Queues;
import io.smallrye.mutiny.subscription.BackPressureStrategy;

public class ShadingIT {

@Test
public void check_class_relocation() throws ClassNotFoundException {
Class.forName("io.smallrye.mutiny.shaded.org.jctools.queues.BaseLinkedQueue");
Class.forName("io.smallrye.mutiny.shaded.org.jctools.queues.atomic.unpadded.BaseLinkedAtomicUnpaddedQueue");
Class.forName("io.smallrye.mutiny.shaded.io.smallrye.common.annotation.CheckReturnValue");
}

@Test
public void check_factories() {
List<Queue<String>> queues = List.of(
Queues.createSpscArrayQueue(256),
Queues.createSpscUnboundedArrayQueue(256),
Queues.createSpscChunkedArrayQueue(256),
Queues.createMpscQueue(),
Queues.createSpscUnboundedQueue(256),
Queues.createMpscArrayQueue(256));

queues.forEach(queue -> {
queue.add("foo");
queue.add("bar");
assertEquals("foo", queue.poll());
assertEquals("bar", queue.poll());
assertNull(queue.poll());
assertTrue(queue.getClass().getCanonicalName().contains("shaded"));
});
}

@Test
public void multi_emitter() {
Multi<Integer> multi = Multi.createFrom().emitter(emitter -> {
for (int i = 0; i < 100; i++) {
emitter.emit(i);
}
emitter.complete();
}, BackPressureStrategy.BUFFER);

List<Integer> suite = multi.collect().asList().await().atMost(Duration.ofSeconds(5));
assertEquals(100, suite.size());
assertEquals(0, suite.get(0));
assertEquals(99, suite.get(99));
}
}
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<module>bom</module>
<module>math</module>
<module>workshop-examples</module>
<module>no-deps</module>
</modules>

<properties>
Expand Down Expand Up @@ -124,6 +125,8 @@
<find-and-replace-maven-plugin.version>1.1.0</find-and-replace-maven-plugin.version>
<jreleaser-maven-plugin.version>1.14.0</jreleaser-maven-plugin.version>
<cyclonedx-maven-plugin.version>2.8.1</cyclonedx-maven-plugin.version>
<maven-shade-plugin.version>3.5.3</maven-shade-plugin.version>
<maven-failsafe-plugin.version>3.2.5</maven-failsafe-plugin.version>
</properties>

<dependencyManagement>
Expand Down
Loading