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

Build fs2 with JDK 8 #2659

Closed
wants to merge 14 commits into from
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [3.0.2, 2.12.15, 2.13.6]
java: [adoptium@17]
java: [adoptium@8, adoptium@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
java: [adoptium@17]
java: [adoptium@8]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
java: [adoptium@17]
java: [adoptium@8, adoptium@17]
runs-on: ${{ matrix.os }}
steps:
- name: Download target directories (3.0.2)
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ val NewScala = "2.13.6"
ThisBuild / crossScalaVersions := Seq("3.0.2", "2.12.15", NewScala)

ThisBuild / githubWorkflowEnv += ("JABBA_INDEX" -> "https://github.com/typelevel/jdk-index/raw/main/index.json")
ThisBuild / githubWorkflowJavaVersions := Seq("adoptium@17")
ThisBuild / githubWorkflowJavaVersions := Seq("adoptium@8", "adoptium@17")

ThisBuild / spiewakCiReleaseSnapshots := true

Expand Down
51 changes: 51 additions & 0 deletions io/jvm/src/main/java/fs2/io/net/StandardSocketOptionsCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.net.StandardSocketOptions;

import javax.management.RuntimeErrorException;

final class StandardSocketOptionsCompat {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodHandle SO_REUSEPORT_METHOD_HANDLE = initSoReusePortMethodHandle();

private static MethodHandle initSoReusePortMethodHandle() {
try {
return LOOKUP.findStaticGetter(StandardSocketOptions.class, "SO_REUSEPORT", java.net.SocketOption.class);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

static final java.net.SocketOption<Boolean> SO_REUSEPORT = initSoReusePort();

private static java.net.SocketOption<Boolean> initSoReusePort() {
try {
return (java.net.SocketOption<Boolean>) SO_REUSEPORT_METHOD_HANDLE.invokeExact();
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}
}
82 changes: 82 additions & 0 deletions io/jvm/src/main/java/fs2/io/net/tls/SSLParametersCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net.tls;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import javax.net.ssl.SSLParameters;

final class SSLParametersCompat extends SSLParameters {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodType SET_ENABLE_RETRANSMISSIONS_METHOD_TYPE = MethodType.methodType(void.class,
boolean.class);
private static final MethodHandle SET_ENABLE_RETRANSMISSIONS_METHOD_HANDLE = initSetEnableRetransmissionsMethodHandle();
private static final MethodType SET_MAXIMUM_PACKET_SIZE_METHOD_TYPE = MethodType.methodType(void.class, int.class);
private static final MethodHandle SET_MAXIMUM_PACKET_SIZE_METHOD_HANDLE = initSetMaximumPacketSizeMethodHandle();

private static MethodHandle initSetEnableRetransmissionsMethodHandle() {
try {
return LOOKUP.findVirtual(SSLParametersCompat.class, "setEnableRetransmissions",
SET_ENABLE_RETRANSMISSIONS_METHOD_TYPE);
} catch (NoSuchMethodException e) {
try {
return LOOKUP.findVirtual(SSLParametersCompat.class, "fauxSetEnableRetransmissions",
SET_ENABLE_RETRANSMISSIONS_METHOD_TYPE);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

private static MethodHandle initSetMaximumPacketSizeMethodHandle() {
try {
return LOOKUP.findVirtual(SSLParametersCompat.class, "setMaximumPacketSize", SET_MAXIMUM_PACKET_SIZE_METHOD_TYPE);
} catch (NoSuchMethodException e) {
try {
return LOOKUP.findVirtual(SSLParametersCompat.class, "fauxSetMaximumPacketSize",
SET_MAXIMUM_PACKET_SIZE_METHOD_TYPE);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

void setEnableRetransmissionsCompat(boolean enableRetransmissions) throws Throwable {
SET_ENABLE_RETRANSMISSIONS_METHOD_HANDLE.invokeExact(this, enableRetransmissions);
}

void setMaximumPacketSizeCompat(int maximumPacketSize) throws Throwable {
SET_MAXIMUM_PACKET_SIZE_METHOD_HANDLE.invokeExact(this, maximumPacketSize);
}

private void fauxSetEnableRetransmissions(boolean setEnableRetransmissions) {
}

private void fauxSetMaximumPacketSize(int maximumPacketSize) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net.unixsocket;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.ProtocolFamily;
import java.nio.channels.ServerSocketChannel;

final class ServerSocketChannelCompat {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodType OPEN_METHOD_TYPE = MethodType.methodType(ServerSocketChannel.class,
ProtocolFamily.class);
private static final MethodHandle OPEN_METHOD_HANDLE = initOpenMethodHandle();

private static MethodHandle initOpenMethodHandle() {
try {
return LOOKUP.findStatic(ServerSocketChannel.class, "open", OPEN_METHOD_TYPE);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

static ServerSocketChannel open(ProtocolFamily family) throws Throwable {
return (ServerSocketChannel) OPEN_METHOD_HANDLE.invokeExact(family);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net.unixsocket;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.ProtocolFamily;
import java.nio.channels.SocketChannel;

final class SocketChannelCompat {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodType OPEN_METHOD_TYPE = MethodType.methodType(SocketChannel.class, ProtocolFamily.class);
private static final MethodHandle OPEN_METHOD_HANDLE = initOpenMethodHandle();

private static MethodHandle initOpenMethodHandle() {
try {
return LOOKUP.findStatic(SocketChannel.class, "open", OPEN_METHOD_TYPE);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

static SocketChannel open(ProtocolFamily family) throws Throwable {
return (SocketChannel) OPEN_METHOD_HANDLE.invokeExact(family);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net.unixsocket;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.net.StandardProtocolFamily;

final class StandardProtocolFamilyCompat {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final MethodHandle UNIX_METHOD_HANDLE = initUnixMethodHandle();

private static MethodHandle initUnixMethodHandle() {
try {
return LOOKUP.findStaticGetter(StandardProtocolFamily.class, "UNIX", StandardProtocolFamily.class);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

static final StandardProtocolFamily UNIX = initUnix();

private static StandardProtocolFamily initUnix() {
try {
return (StandardProtocolFamily) UNIX_METHOD_HANDLE.invokeExact();
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013 Functional Streams for Scala
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package fs2.io.net.unixsocket;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.net.SocketAddress;

final class UnixDomainSocketAddressCompat {
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
private static final Class<?> UNIX_DOMAIN_SOCKET_ADDRESS_CLASS = initUnixDomainSocketAddressClass();

private static final MethodType OF_METHOD_TYPE = MethodType.methodType(UNIX_DOMAIN_SOCKET_ADDRESS_CLASS,
String.class);
private static final MethodHandle OF_METHOD_HANDLE = initOfMethodHandle();

private static Class<?> initUnixDomainSocketAddressClass() {
try {
return Class.forName("java.net.UnixDomainSocketAddress");
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}

private static MethodHandle initOfMethodHandle() {
try {
return LOOKUP.findStatic(UNIX_DOMAIN_SOCKET_ADDRESS_CLASS, "of", OF_METHOD_TYPE);
} catch (Throwable t) {
throw new ExceptionInInitializerError(t);
}
}

static SocketAddress of(String pathname) throws Throwable {
return (SocketAddress) OF_METHOD_HANDLE.invoke(pathname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private[net] trait SocketOptionCompanionPlatform {
boolean(StandardSocketOptions.SO_REUSEADDR, value)

def reusePort(value: Boolean): SocketOption =
boolean(StandardSocketOptions.SO_REUSEPORT, value)
boolean(StandardSocketOptionsCompat.SO_REUSEPORT, value)

def sendBufferSize(value: Int): SocketOption =
integer(StandardSocketOptions.SO_SNDBUF, value)
Expand Down
2 changes: 1 addition & 1 deletion io/jvm/src/main/scala/fs2/io/net/tls/TLSEngine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private[tls] object TLSEngine {
)
}
}
case SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN =>
case _ /* SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN */ =>
unwrapHandshake
}

Expand Down
Loading