Skip to content

Commit

Permalink
feat(compat): Provide JDK11 compatibilty through Multi-Release JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion committed Sep 14, 2023
1 parent c2fc6e5 commit 0108ed6
Show file tree
Hide file tree
Showing 8 changed files with 794 additions and 41 deletions.
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ plugins {
id('io.github.joselion.pretty-jupiter') version '3.0.1'
id('io.github.joselion.strict-null-check') version '3.0.0'
id('io.github.gradle-nexus.publish-plugin') version '2.0.0-rc-1'
id('me.champeau.mrjar') version '0.1.1'
id('name.remal.sonarlint') version '3.3.8'
}

group = 'io.github.joselion'

multiRelease {
targetVersions(11, 17, 20)
}

java {
sourceCompatibility = JavaLanguageVersion.of(17)
toolchain {
languageVersion = JavaLanguageVersion.of(20)
vendor = JvmVendorSpec.ORACLE
}
withJavadocJar()
Expand Down Expand Up @@ -101,19 +104,23 @@ dependencies {
because('version 9.0.75 has a security vulnerability')
}
}

testImplementation('org.assertj:assertj-core:3.24.2')
testImplementation('org.mockito:mockito-core:5.5.0')
}

testing {
suites {
test {
configureEach {
useJUnitJupiter('5.10.0')
dependencies {
implementation('org.assertj:assertj-core:3.24.2')
implementation('org.mockito:mockito-core:5.5.0')
}
}
}
}

java17Test.useJUnitPlatform()
java20Test.useJUnitPlatform()

prettyJupiter {
duration.threshold = 150
}
Expand Down
2 changes: 2 additions & 0 deletions buildscript-gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ io.github.joselion.strict-null-check:io.github.joselion.strict-null-check.gradle
io.github.joselion:maybe:3.2.0=classpath
io.github.joselion:pretty-jupiter:3.0.1=classpath
io.github.joselion:strict-null-check:3.0.0=classpath
me.champeau.gradle.mrjar:plugin:0.1.1=classpath
me.champeau.mrjar:me.champeau.mrjar.gradle.plugin:0.1.1=classpath
name.remal.gradle-plugins.sonarlint:sonarlint:3.3.8=classpath
name.remal.sonarlint:name.remal.sonarlint.gradle.plugin:3.3.8=classpath
empty=
32 changes: 16 additions & 16 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ commons-codec:commons-codec:1.15=checkstyle
commons-collections:commons-collections:3.2.2=checkstyle
commons-io:commons-io:2.11.0=sonarlintCoreClasspath
info.picocli:picocli:4.7.4=checkstyle
net.bytebuddy:byte-buddy-agent:1.14.6=testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.6=testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy-agent:1.14.6=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.14.6=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
net.sf.saxon:Saxon-HE:12.3=checkstyle
org.antlr:antlr4-runtime:4.11.1=checkstyle
org.apache.commons:commons-compress:1.21=sonarlintCoreClasspath
Expand All @@ -39,16 +39,16 @@ org.apache.tomcat.embed:tomcat-embed-el:9.0.75=sonarlintCoreClasspath
org.apache.tomcat.embed:tomcat-embed-jasper:9.0.75=sonarlintCoreClasspath
org.apache.tomcat:tomcat-annotations-api:9.0.80=sonarlintCoreClasspath
org.apache.xbean:xbean-reflect:3.7=checkstyle
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
org.assertj:assertj-core:3.24.2=testCompileClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=java17TestCompileClasspath,java20TestCompileClasspath,testCompileClasspath
org.assertj:assertj-core:3.24.2=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.checkerframework:checker-qual:3.27.0=checkstyle
org.codehaus.plexus:plexus-classworlds:2.6.0=checkstyle
org.codehaus.plexus:plexus-component-annotations:2.1.0=checkstyle
org.codehaus.plexus:plexus-container-default:2.1.0=checkstyle
org.codehaus.plexus:plexus-utils:3.3.0=checkstyle
org.codehaus.woodstox:stax2-api:4.2.1=sonarlintCoreClasspath
org.eclipse.jdt:ecj:3.33.0=sonarlintCoreClasspath
org.eclipse.jdt:org.eclipse.jdt.annotation:2.2.700=compileClasspath,testCompileClasspath
org.eclipse.jdt:org.eclipse.jdt.annotation:2.2.700=compileClasspath,java17CompileClasspath,java17TestCompileClasspath,java20CompileClasspath,java20TestCompileClasspath,testCompileClasspath
org.eclipse.jdt:org.eclipse.jdt.core:3.33.0=sonarlintCoreClasspath
org.eclipse.platform:org.eclipse.core.commands:3.10.300=sonarlintCoreClasspath
org.eclipse.platform:org.eclipse.core.contenttype:3.8.100=sonarlintCoreClasspath
Expand All @@ -64,17 +64,17 @@ org.jacoco:org.jacoco.ant:0.8.10=jacocoAnt
org.jacoco:org.jacoco.core:0.8.10=jacocoAnt
org.jacoco:org.jacoco.report:0.8.10=jacocoAnt
org.javassist:javassist:3.28.0-GA=checkstyle
org.junit.jupiter:junit-jupiter-api:5.10.0=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.10.0=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.10.0=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter:5.10.0=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.10.0=testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.10.0=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.10.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:5.10.0=java17TestRuntimeClasspath,java20TestRuntimeClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:5.10.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter:5.10.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-commons:1.10.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-engine:1.10.0=java17TestRuntimeClasspath,java20TestRuntimeClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-launcher:1.10.0=testRuntimeClasspath
org.junit:junit-bom:5.10.0=testCompileClasspath,testRuntimeClasspath
org.mockito:mockito-core:5.5.0=testCompileClasspath,testRuntimeClasspath
org.objenesis:objenesis:3.3=testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.junit:junit-bom:5.10.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.mockito:mockito-core:5.5.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.objenesis:objenesis:3.3=java17TestRuntimeClasspath,java20TestRuntimeClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=java17TestCompileClasspath,java17TestRuntimeClasspath,java20TestCompileClasspath,java20TestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.osgi:org.osgi.service.prefs:1.1.2=sonarlintCoreClasspath
org.osgi:osgi.annotation:8.0.1=sonarlintCoreClasspath
org.ow2.asm:asm-commons:9.5=jacocoAnt
Expand Down Expand Up @@ -107,4 +107,4 @@ org.sonarsource.xml:sonar-xml-plugin:2.10.0.4108=sonarlintCoreClasspath
org.xmlresolver:xmlresolver:5.2.0=checkstyle
xerces:xercesImpl:2.12.2=sonarlintCoreClasspath
xml-apis:xml-apis:1.4.01=sonarlintCoreClasspath
empty=annotationProcessor,runtimeClasspath,testAnnotationProcessor
empty=annotationProcessor,java17AnnotationProcessor,java17RuntimeClasspath,java17TestAnnotationProcessor,java20AnnotationProcessor,java20RuntimeClasspath,java20TestAnnotationProcessor,runtimeClasspath,testAnnotationProcessor
9 changes: 5 additions & 4 deletions src/main/java/io/github/joselion/maybe/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static <E extends Throwable> EffectHandler<E> fromEffect(final ThrowingRu
* In other words, the following code
* <pre>
* Optional.of(value)
* .map(str -> Maybe.fromResolver(() -> decode(str)));
* .map(str -&gt; Maybe.fromResolver(() -&gt; decode(str)));
* </pre>
* Is equivalent to
* <pre>
Expand Down Expand Up @@ -166,7 +166,7 @@ public static <S, T, E extends Throwable> Function<S, ResolveHandler<T, E>> part
* In other words, the following code
* <pre>
* Optional.of(value)
* .map(msg -> Maybe.fromEffect(() -> sendMessage(msg)));
* .map(msg -&gt; Maybe.fromEffect(() -&gt; sendMessage(msg)));
* </pre>
* Is equivalent to
* <pre>
Expand Down Expand Up @@ -341,7 +341,8 @@ public boolean equals(final Object obj) {
return true;
}

if (obj instanceof final Maybe<?> other) {
if (obj instanceof Maybe<?>) {
final var other = (Maybe<?>) obj;
return other.toOptional().equals(value);
}

Expand Down Expand Up @@ -370,7 +371,7 @@ public int hashCode() {
public String toString() {
return value
.map(Object::toString)
.map("Maybe[%s]"::formatted)
.map(it -> String.format("Maybe[%s]", it))
.orElse("Maybe.nothing");
}
}
36 changes: 25 additions & 11 deletions src/main/java/io/github/joselion/maybe/util/Either.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Jose Luis Leon
* @since v3.0.0
*/
public sealed interface Either<L, R> {
public interface Either<L, R> {

/**
* Factory method to create an {@code Either} instance that contains a
Expand Down Expand Up @@ -174,17 +174,23 @@ default Optional<R> rightToOptional() {
*
* @param <L> the {@code Left} data type
* @param <R> the {@code Right} data type
* @param value the left value
*/
record Left<L, R>(L value) implements Either<L, R> {
class Left<L, R> implements Either<L, R> {

private final L value;

/**
* Compact constructor to validate the value is not null.
*
* @param value the value of the instance
*/
public Left {
public Left(final L value) {
Objects.requireNonNull(value, "An Either cannot be created with a null value");
this.value = value;
}

L value() {
return this.value;
}

@Override
Expand Down Expand Up @@ -242,7 +248,8 @@ public boolean equals(final Object obj) {
return true;
}

if (obj instanceof final Left<?, ?> left) {
if (obj instanceof Left<?, ?>) {
final var left = (Left<?, ?>) obj;
return this.value.equals(left.leftOrNull());
}

Expand All @@ -256,7 +263,7 @@ public int hashCode() {

@Override
public String toString() {
return "Either[Left: %s]".formatted(this.value);
return String.format("Either[Left: %s]", this.value);
}
}

Expand All @@ -265,17 +272,23 @@ public String toString() {
*
* @param <L> the {@code Left} data type
* @param <R> the {@code Right} data type
* @param value the right value
*/
record Right<L, R>(R value) implements Either<L, R> {
class Right<L, R> implements Either<L, R> {

private final R value;

/**
* Compact constructor to validate the value is not null.
*
* @param value the value of the instance
*/
public Right {
public Right(final R value) {
Objects.requireNonNull(value, "An Either cannot be created with a null value");
this.value = value;
}

R value() {
return this.value;
}

@Override
Expand Down Expand Up @@ -333,7 +346,8 @@ public boolean equals(final Object obj) {
return true;
}

if (obj instanceof final Right<?, ?> right) {
if (obj instanceof Right<?, ?>) {
final var right = (Right<?, ?>) obj;
return this.value.equals(right.rightOrNull());
}

Expand All @@ -347,7 +361,7 @@ public int hashCode() {

@Override
public String toString() {
return "Either[Right: %s]".formatted(this.value);
return String.format("Either[Right: %s]", this.value);
}
}
}
Loading

0 comments on commit 0108ed6

Please sign in to comment.