diff --git a/0001-Add-enxio-classes-from-jnr-unixsocket.patch b/0001-Add-enxio-classes-from-jnr-unixsocket.patch new file mode 100644 index 0000000..4bb5c94 --- /dev/null +++ b/0001-Add-enxio-classes-from-jnr-unixsocket.patch @@ -0,0 +1,449 @@ +From c9e2b0f565074474613c8fbee6dde86a9fcd2395 Mon Sep 17 00:00:00 2001 +From: Mat Booth +Date: Sat, 8 Dec 2018 10:39:47 +0000 +Subject: [PATCH] Add enxio classes from jnr-unixsocket + +These classes are removed from jnr-unixsocket and packaged here instead +to avoid split-package problems in OSGi systems. +--- + .../AbstractNativeDatagramChannel.java | 79 ++++++++++ + .../channels/AbstractNativeSocketChannel.java | 101 +++++++++++++ + src/main/java/jnr/enxio/channels/Common.java | 136 ++++++++++++++++++ + .../enxio/channels/NativeSocketChannel.java | 46 ++---- + 4 files changed, 325 insertions(+), 37 deletions(-) + create mode 100644 src/main/java/jnr/enxio/channels/AbstractNativeDatagramChannel.java + create mode 100644 src/main/java/jnr/enxio/channels/AbstractNativeSocketChannel.java + create mode 100644 src/main/java/jnr/enxio/channels/Common.java + +diff --git a/src/main/java/jnr/enxio/channels/AbstractNativeDatagramChannel.java b/src/main/java/jnr/enxio/channels/AbstractNativeDatagramChannel.java +new file mode 100644 +index 0000000..a48d6bc +--- /dev/null ++++ b/src/main/java/jnr/enxio/channels/AbstractNativeDatagramChannel.java +@@ -0,0 +1,79 @@ ++/* ++ * Copyright (C) 2016 Fritz Elfert ++ * ++ * This file is part of the JNR project. ++ * ++ * Licensed under the Apache License, Version 2.0 (the "License"); ++ * you may not use this file except in compliance with the License. ++ * You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++package jnr.enxio.channels; ++ ++import java.io.IOException; ++import java.nio.ByteBuffer; ++import java.nio.channels.ByteChannel; ++import java.nio.channels.DatagramChannel; ++import java.nio.channels.spi.SelectorProvider; ++ ++public abstract class AbstractNativeDatagramChannel extends DatagramChannel ++ implements ByteChannel, NativeSelectableChannel { ++ ++ private final Common common; ++ ++ public AbstractNativeDatagramChannel(int fd) { ++ this(NativeSelectorProvider.getInstance(), fd); ++ } ++ ++ AbstractNativeDatagramChannel(SelectorProvider provider, int fd) { ++ super(provider); ++ common = new Common(fd); ++ } ++ ++ public void setFD(int fd) { ++ common.setFD(fd); ++ } ++ ++ public final int getFD() { ++ return common.getFD(); ++ } ++ ++ @Override ++ protected void implCloseSelectableChannel() throws IOException { ++ Native.close(common.getFD()); ++ } ++ ++ @Override ++ protected void implConfigureBlocking(boolean block) throws IOException { ++ Native.setBlocking(common.getFD(), block); ++ } ++ ++ public int read(ByteBuffer dst) throws IOException { ++ return common.read(dst); ++ } ++ ++ @Override ++ public long read(ByteBuffer[] dsts, int offset, ++ int length) throws IOException { ++ return common.read(dsts, offset, length); ++ } ++ ++ public int write(ByteBuffer src) throws IOException { ++ return common.write(src); ++ } ++ ++ @Override ++ public long write(ByteBuffer[] srcs, int offset, ++ int length) throws IOException { ++ return common.write(srcs, offset, length); ++ } ++ ++} +diff --git a/src/main/java/jnr/enxio/channels/AbstractNativeSocketChannel.java b/src/main/java/jnr/enxio/channels/AbstractNativeSocketChannel.java +new file mode 100644 +index 0000000..65ead06 +--- /dev/null ++++ b/src/main/java/jnr/enxio/channels/AbstractNativeSocketChannel.java +@@ -0,0 +1,101 @@ ++/* ++ * Copyright (C) 2016 Marcus Linke ++ * ++ * This file is part of the JNR project. ++ * ++ * Licensed under the Apache License, Version 2.0 (the "License"); ++ * you may not use this file except in compliance with the License. ++ * You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++package jnr.enxio.channels; ++ ++import java.io.IOException; ++import java.nio.ByteBuffer; ++import java.nio.channels.ByteChannel; ++import java.nio.channels.SocketChannel; ++import java.nio.channels.spi.SelectorProvider; ++ ++import jnr.constants.platform.Shutdown; ++ ++public abstract class AbstractNativeSocketChannel extends SocketChannel ++ implements ByteChannel, NativeSelectableChannel { ++ ++ private final Common common; ++ ++ public AbstractNativeSocketChannel(int fd) { ++ this(NativeSelectorProvider.getInstance(), fd); ++ } ++ ++ AbstractNativeSocketChannel(SelectorProvider provider, int fd) { ++ super(provider); ++ common = new Common(fd); ++ } ++ ++ public void setFD(int fd) { ++ common.setFD(fd); ++ } ++ ++ public final int getFD() { ++ return common.getFD(); ++ } ++ ++ @Override ++ protected void implCloseSelectableChannel() throws IOException { ++ Native.close(common.getFD()); ++ } ++ ++ @Override ++ protected void implConfigureBlocking(boolean block) throws IOException { ++ Native.setBlocking(common.getFD(), block); ++ } ++ ++ public int read(ByteBuffer dst) throws IOException { ++ return common.read(dst); ++ } ++ ++ @Override ++ public long read(ByteBuffer[] dsts, int offset, ++ int length) throws IOException { ++ return common.read(dsts, offset, length); ++ } ++ ++ public int write(ByteBuffer src) throws IOException { ++ return common.write(src); ++ } ++ ++ @Override ++ public long write(ByteBuffer[] srcs, int offset, ++ int length) throws IOException { ++ return common.write(srcs, offset, length); ++ } ++ ++ @Override ++ public SocketChannel shutdownInput() throws IOException { ++ int n = Native.shutdown(common.getFD(), SHUT_RD); ++ if (n < 0) { ++ throw new IOException(Native.getLastErrorString()); ++ } ++ return this; ++ } ++ ++ @Override ++ public SocketChannel shutdownOutput() throws IOException { ++ int n = Native.shutdown(common.getFD(), SHUT_WR); ++ if (n < 0) { ++ throw new IOException(Native.getLastErrorString()); ++ } ++ return this; ++ } ++ ++ private static final int SHUT_RD = Shutdown.SHUT_RD.intValue(); ++ private static final int SHUT_WR = Shutdown.SHUT_WR.intValue(); ++} +diff --git a/src/main/java/jnr/enxio/channels/Common.java b/src/main/java/jnr/enxio/channels/Common.java +new file mode 100644 +index 0000000..66ac609 +--- /dev/null ++++ b/src/main/java/jnr/enxio/channels/Common.java +@@ -0,0 +1,136 @@ ++/* ++ * Copyright (C) 2016 Fritz Elfert ++ * ++ * This file is part of the JNR project. ++ * ++ * Licensed under the Apache License, Version 2.0 (the "License"); ++ * you may not use this file except in compliance with the License. ++ * You may obtain a copy of the License at ++ * ++ * http://www.apache.org/licenses/LICENSE-2.0 ++ * ++ * Unless required by applicable law or agreed to in writing, software ++ * distributed under the License is distributed on an "AS IS" BASIS, ++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ++ * See the License for the specific language governing permissions and ++ * limitations under the License. ++ */ ++ ++package jnr.enxio.channels; ++ ++import java.io.IOException; ++import java.nio.ByteBuffer; ++ ++import jnr.constants.platform.Errno; ++ ++/** ++ * Helper class, providing common methods. ++ */ ++final class Common { ++ ++ private int _fd = -1; ++ ++ Common(int fd) { ++ _fd = fd; ++ } ++ ++ void setFD(int fd) { ++ _fd = fd; ++ } ++ ++ int getFD() { ++ return _fd; ++ } ++ ++ int read(ByteBuffer dst) throws IOException { ++ ++ ByteBuffer buffer = ByteBuffer.allocate(dst.remaining()); ++ ++ int n = Native.read(_fd, buffer); ++ ++ buffer.flip(); ++ ++ dst.put(buffer); ++ ++ switch (n) { ++ case 0: ++ return -1; ++ ++ case -1: ++ Errno lastError = Native.getLastError(); ++ switch (lastError) { ++ case EAGAIN: ++ case EWOULDBLOCK: ++ return 0; ++ ++ default: ++ throw new IOException(Native.getLastErrorString()); ++ } ++ ++ default: { ++ ++ return n; ++ } ++ } ++ } ++ ++ long read(ByteBuffer[] dsts, int offset, int length) ++ throws IOException { ++ long total = 0; ++ ++ for (int i = 0; i < length; i++) { ++ ByteBuffer dst = dsts[offset + i]; ++ long read = read(dst); ++ if (read == -1) { ++ return read; ++ } ++ total += read; ++ } ++ ++ return total; ++ } ++ ++ int write(ByteBuffer src) throws IOException { ++ ++ int r = src.remaining(); ++ ++ ByteBuffer buffer = ByteBuffer.allocate(r); ++ ++ buffer.put(src); ++ ++ buffer.position(0); ++ ++ int n = Native.write(_fd, buffer); ++ ++ if (n >=0 ) { ++ if (n < r) { ++ src.position(src.position()-(r-n)); ++ } ++ } else { ++ switch (Native.getLastError()) { ++ case EAGAIN: ++ case EWOULDBLOCK: ++ src.position(src.position()-r); ++ return 0; ++ default: ++ throw new IOException(Native.getLastErrorString()); ++ } ++ } ++ ++ return n; ++ } ++ ++ long write(ByteBuffer[] srcs, int offset, int length) ++ throws IOException { ++ ++ long result = 0; ++ int index = 0; ++ ++ for (index = offset; index < length; index++) { ++ result += write(srcs[index]); ++ } ++ ++ return result; ++ } ++ ++} +diff --git a/src/main/java/jnr/enxio/channels/NativeSocketChannel.java b/src/main/java/jnr/enxio/channels/NativeSocketChannel.java +index 445ba1a..082ead1 100644 +--- a/src/main/java/jnr/enxio/channels/NativeSocketChannel.java ++++ b/src/main/java/jnr/enxio/channels/NativeSocketChannel.java +@@ -29,7 +29,7 @@ import java.nio.channels.spi.SelectorProvider; + public class NativeSocketChannel extends AbstractSelectableChannel + implements ByteChannel, NativeSelectableChannel { + +- private final int fd; ++ private final Common common; + private final int validOps; + + public NativeSocketChannel(int fd) { +@@ -42,18 +42,18 @@ public class NativeSocketChannel extends AbstractSelectableChannel + + NativeSocketChannel(SelectorProvider provider, int fd, int ops) { + super(provider); +- this.fd = fd; ++ common = new Common(fd); + this.validOps = ops; + } + + @Override + protected void implCloseSelectableChannel() throws IOException { +- Native.close(fd); ++ Native.close(common.getFD()); + } + + @Override + protected void implConfigureBlocking(boolean block) throws IOException { +- Native.setBlocking(fd, block); ++ Native.setBlocking(common.getFD(), block); + } + + @Override +@@ -61,54 +61,26 @@ public class NativeSocketChannel extends AbstractSelectableChannel + return validOps; + } + public final int getFD() { +- return fd; ++ return common.getFD(); + } + + public int read(ByteBuffer dst) throws IOException { +- int n = Native.read(fd, dst); +- switch (n) { +- case 0: +- return -1; +- +- case -1: +- switch (Native.getLastError()) { +- case EAGAIN: +- case EWOULDBLOCK: +- return 0; +- +- default: +- throw new IOException(Native.getLastErrorString()); +- } +- +- default: +- return n; +- } ++ return common.read(dst); + } + + public int write(ByteBuffer src) throws IOException { +- int n = Native.write(fd, src); +- if (n < 0) { +- switch (Native.getLastError()) { +- case EAGAIN: +- case EWOULDBLOCK: +- return 0; +- default: +- throw new IOException(Native.getLastErrorString()); +- } +- } +- +- return n; ++ return common.write(src); + } + + public void shutdownInput() throws IOException { +- int n = Native.shutdown(fd, SHUT_RD); ++ int n = Native.shutdown(common.getFD(), SHUT_RD); + if (n < 0) { + throw new IOException(Native.getLastErrorString()); + } + } + + public void shutdownOutput() throws IOException { +- int n = Native.shutdown(fd, SHUT_WR); ++ int n = Native.shutdown(common.getFD(), SHUT_WR); + if (n < 0) { + throw new IOException(Native.getLastErrorString()); + } +-- +2.19.1 + diff --git a/jnr-enxio-0.19.tar.gz b/jnr-enxio-0.19.tar.gz new file mode 100644 index 0000000..e8069e4 Binary files /dev/null and b/jnr-enxio-0.19.tar.gz differ diff --git a/jnr-enxio.spec b/jnr-enxio.spec new file mode 100644 index 0000000..686d0b0 --- /dev/null +++ b/jnr-enxio.spec @@ -0,0 +1,43 @@ +Name: jnr-enxio +Version: 0.19 +Release: 1 +Summary: Unix sockets for Java +License: ASL 2.0 and LGPLv3 +URL: https://github.com/jnr/%{name}/ +Source0: https://github.com/jnr/%{name}/archive/%{name}-%{version}.tar.gz +Patch0: 0001-Add-enxio-classes-from-jnr-unixsocket.patch +BuildArch: noarch +BuildRequires: maven-local mvn(com.github.jnr:jnr-constants) mvn(com.github.jnr:jnr-ffi) +BuildRequires: mvn(junit:junit) mvn(org.apache.felix:maven-bundle-plugin) +BuildRequires: mvn(org.apache.maven.plugins:maven-source-plugin) +BuildRequires: mvn(org.sonatype.oss:oss-parent:pom:) +%description +Unix sockets for Java. + +%package javadoc +Summary: Javadocs for %{name} +%description javadoc +This package contains the API documentation for %{name}. + +%prep +%setup -q -n %{name}-%{name}-%{version} +%patch0 -p1 +find ./ -name '*.jar' -delete +find ./ -name '*.class' -delete +%pom_remove_plugin ":maven-javadoc-plugin" + +%build +%mvn_build + +%install +%mvn_install + +%files -f .mfiles +%license LICENSE + +%files javadoc -f .mfiles-javadoc +%license LICENSE + +%changelog +* Thu Jul 30 2020 Jeffery.Gao - 0.19-1 +- Package init diff --git a/jnr-enxio.yaml b/jnr-enxio.yaml new file mode 100644 index 0000000..111a7f6 --- /dev/null +++ b/jnr-enxio.yaml @@ -0,0 +1,5 @@ +git_url: https://github.com/jnr/jnr-enxio +version_control: github +src_repo: jnr/jnr-enxio +tag_prefix: "jnr-enxio-" +seperator: "."