From 4d0e6b383202fcde55b0942804f84ced6b6136d2 Mon Sep 17 00:00:00 2001 From: Andrey Antonowycz Date: Sun, 31 Jul 2022 11:43:02 +0200 Subject: [PATCH] Repackage library for Maven Central release --- .github/workflows/maven-publish.yml | 29 +++- CHANGELOG.md | 7 +- README.md | 10 +- pom.xml | 136 +++++++++++++++--- .../java/{ => websocket}/ServerSocket.java | 16 ++- src/main/java/{ => websocket}/Socket.java | 5 + .../preprocessors}/WSInputStream.java | 4 + .../preprocessors}/WSOutputStream.java | 4 + src/test/java/ServerTest.java | 2 +- src/test/java/TestServer.java | 3 + 10 files changed, 177 insertions(+), 39 deletions(-) rename src/main/java/{ => websocket}/ServerSocket.java (50%) rename src/main/java/{ => websocket}/Socket.java (95%) rename src/main/java/{ => websocket/preprocessors}/WSInputStream.java (98%) rename src/main/java/{ => websocket/preprocessors}/WSOutputStream.java (98%) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index e3e00b8..4c6b38b 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,5 +1,7 @@ # This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# Additionally it will publish the package to the Maven Central Repository through OSSRH # For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path +# https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven name: Maven Package @@ -12,19 +14,16 @@ jobs: build_release: runs-on: ubuntu-latest -# permissions: -# contents: read -# packages: write steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK for publishing to GitHub Packages uses: actions/setup-java@v3 with: java-version: '11' distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file + server-id: github + settings-path: ${{ github.workspace }} - name: Build with Maven run: mvn -B package --file pom.xml @@ -45,3 +44,21 @@ jobs: run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml env: GITHUB_TOKEN: ${{ github.token }} + + - name: Set up JDK for publishing to Maven Central Repository + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Publish to Maven Central Repository + run: mvn -P release --batch-mode deploy + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 673a32d..eb44d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,14 @@ # Changelog -## [1.0-2] - 2022-07-29 +## [1.0-3] - 2022-07-31 Revision to initial release. ### Changes -- Fixed buffer underflow issue that occurred when sending messages longer than 125 bits +- Attach JavaDoc and sources to release JAR +- Publish to Apache Maven Central Repository ### Features -- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular java.net Socket clients and web browsers +- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular `java.net` `Socket` clients and web browsers - Automatic HTTP Upgrade handling to WebSocket protocol upon web browser handshake - Automatic encoding and decoding of traffic between server and web browser client after WebSocket handshaking with the help of background processes \ No newline at end of file diff --git a/README.md b/README.md index ad0941c..7acebd7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Minimal Java library for communication between server and web browser, designed as a drop-in replacement for the `java.net` `ServerSocket` and `Socket` classes ## Features -- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular java.net Socket clients and web browsers +- Drop-in replacement for `java.net` `ServerSocket` and `Socket` classes, able to interact with regular `java.net` `Socket` clients and web browsers - Automatic HTTP Upgrade handling to WebSocket protocol upon web browser handshake - Automatic encoding and decoding of traffic between server and web browser client after WebSocket handshaking with the help of background processes @@ -17,8 +17,8 @@ Minimal Java library for communication between server and web browser, designed Using the library to communicate with web browsers is designed to be as straight-forward as interacting normal `java.net` `Socket` clients. Below is a simple example server allowing only once consecutive client to connect at a time, to handle more than one client at a time implement a client handler class with a thread for every client. ```java -import com.antonowycz.ServerSocket; // Extension of java.net.ServerSocket -import com.antonowycz.Socket; // Extension of java.net.Socket +import com.antonowycz.websocket.ServerSocket; // Extension of java.net.ServerSocket +import com.antonowycz.websocket.Socket; // Extension of java.net.Socket ... public class TestServer implements Runnable { ... @@ -56,8 +56,8 @@ public class TestServer implements Runnable { ### Client The code above works both when the client on the receiving end is a regular `java.net.Socket` class, or a web browser with the [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455) protocol implemented, e.g. Chrome 16+, Firefox 11+, IE 10+. -#### Java Socket -The following unit test from `src/test/java/ServerTest.class` ensures backwards compatibility between the extended `Socket` class and the `java.net.Socket` class: +#### Java websocket.Socket +The following unit test from `src/test/java/ServerTest.class` ensures backwards compatibility between the extended `websocket.Socket` class and the `java.net.Socket` class: ```java @Test diff --git a/pom.xml b/pom.xml index bdaf8d3..f9039b2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,26 @@ com.antonowycz minimal-jwebsocket - 1.0-2 + 1.0-3 + jar + minimal-jwebsocket + Minimal Java library for communication between server and web browser, designed as a drop-in replacement for the java.net websocket.ServerSocket and websocket.Socket classes + https://github.com/ethergeus/minimal-jwebsocket + + + + The Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + ethergeus + Andrey Antonowycz + andrey@antonowycz.com + + 11 @@ -55,29 +74,105 @@ + + + release + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.4.0 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + --pinentry-mode + loopback + + + + + sign-artifacts + verify + + sign + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + true + @{project.version} + false + true + false + -DskipTests=true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.13 + true + + https://s01.oss.sonatype.org/ + ossrh + true + 60 + + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots/ + + + oss.sonatype + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + - org.apache.maven.plugins maven-surefire-plugin 3.0.0-M7 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.4.0 - - - generate-javadoc - package - - javadoc - - - - @@ -88,4 +183,11 @@ https://maven.pkg.github.com/ethergeus/minimal-jwebsocket + + + scm:git:git@github.com:ethergeus/minimal-jwebsocket.git + scm:git:git@github.com:ethergeus/minimal-jwebsocket.git + https://github.com/ethergeus/minimal-jwebsocket + HEAD + \ No newline at end of file diff --git a/src/main/java/ServerSocket.java b/src/main/java/websocket/ServerSocket.java similarity index 50% rename from src/main/java/ServerSocket.java rename to src/main/java/websocket/ServerSocket.java index df4526b..9559c87 100644 --- a/src/main/java/ServerSocket.java +++ b/src/main/java/websocket/ServerSocket.java @@ -1,33 +1,35 @@ +package websocket; + import java.io.IOException; import java.net.SocketException; import java.net.SocketImpl; public class ServerSocket extends java.net.ServerSocket { /* - * The ServerSocket class of the minimal-jwebsocket packages provides a method to interact with browser clients - * whilst being backwards compatible with the java.net ServerSocket implementation. + * The websocket.ServerSocket class of the minimal-jwebsocket packages provides a method to interact with browser clients + * whilst being backwards compatible with the java.net websocket.ServerSocket implementation. */ public ServerSocket(int port) throws IOException { super(port); } /* - * Accept a new connection to the current ServerSocket object. - * Adapted from java.net.ServerSocket to use the local Socket class instead of java.net.Socket + * Accept a new connection to the current websocket.ServerSocket object. + * Adapted from java.net.websocket.ServerSocket to use the local websocket.Socket class instead of java.net.websocket.Socket */ @Override public Socket accept() throws IOException { if (isClosed()) - throw new SocketException("Socket is closed"); + throw new SocketException("websocket.Socket is closed"); if (!isBound()) - throw new SocketException("Socket is not bound yet"); + throw new SocketException("websocket.Socket is not bound yet"); Socket s = new Socket((SocketImpl) null); implAccept(s); return s; } /* - * Call the java.net.Socket.implAccept() method to create input and output stream, then create pre-processors for + * Call the java.net.websocket.Socket.implAccept() method to create input and output stream, then create pre-processors for * both streams which will handle the encoding and decoding for when the connection is upgraded to type websocket. */ protected final void implAccept(Socket s) throws IOException { diff --git a/src/main/java/Socket.java b/src/main/java/websocket/Socket.java similarity index 95% rename from src/main/java/Socket.java rename to src/main/java/websocket/Socket.java index 6a0c229..09c2fd2 100644 --- a/src/main/java/Socket.java +++ b/src/main/java/websocket/Socket.java @@ -1,3 +1,8 @@ +package websocket; + +import websocket.preprocessors.WSInputStream; +import websocket.preprocessors.WSOutputStream; + import java.io.IOException; import java.io.OutputStream; import java.net.SocketImpl; diff --git a/src/main/java/WSInputStream.java b/src/main/java/websocket/preprocessors/WSInputStream.java similarity index 98% rename from src/main/java/WSInputStream.java rename to src/main/java/websocket/preprocessors/WSInputStream.java index 1378868..41619c2 100644 --- a/src/main/java/WSInputStream.java +++ b/src/main/java/websocket/preprocessors/WSInputStream.java @@ -1,3 +1,7 @@ +package websocket.preprocessors; + +import websocket.Socket; + import java.io.*; import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException; diff --git a/src/main/java/WSOutputStream.java b/src/main/java/websocket/preprocessors/WSOutputStream.java similarity index 98% rename from src/main/java/WSOutputStream.java rename to src/main/java/websocket/preprocessors/WSOutputStream.java index c276fae..c021eb1 100644 --- a/src/main/java/WSOutputStream.java +++ b/src/main/java/websocket/preprocessors/WSOutputStream.java @@ -1,3 +1,7 @@ +package websocket.preprocessors; + +import websocket.Socket; + import java.io.*; import java.nio.ByteBuffer; import java.util.NoSuchElementException; diff --git a/src/test/java/ServerTest.java b/src/test/java/ServerTest.java index 18f42ff..f50b222 100644 --- a/src/test/java/ServerTest.java +++ b/src/test/java/ServerTest.java @@ -19,7 +19,7 @@ public class ServerTest { private static final int SERVER_PORT = 8080; private TestServer server; - private static final String WS_HTML_CLIENT = Paths.get("src", "test", "web", "src/test/web/TestWSClient.html").toUri().toString(); + private static final String WS_HTML_CLIENT = Paths.get("src", "test", "web", "TestWSClient.html").toUri().toString(); @BeforeEach public void init() { diff --git a/src/test/java/TestServer.java b/src/test/java/TestServer.java index b6b2790..51151f2 100644 --- a/src/test/java/TestServer.java +++ b/src/test/java/TestServer.java @@ -1,3 +1,6 @@ +import websocket.ServerSocket; +import websocket.Socket; + import java.io.*; import java.util.NoSuchElementException; import java.util.Scanner;