diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 12ec64d..6824549 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ -github: blackspherefollower +github: blackspherefollower patreon: blackspherefollower ko_fi: blackspherefollower diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a17c104..fa43263 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -39,38 +39,38 @@ jobs: # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/SECURITY.md b/SECURITY.md index 1357b4a..9a82033 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,10 +4,10 @@ Only the latest release is considered supported. -| Version | Supported | -| ------- | ------------------ | -| 3.0.x | ✅ | -| 0.0.x | ❎ | +| Version | Supported | +|---------|-----------| +| 3.0.x | ✅ | +| 0.0.x | ❎ | ## Reporting a Vulnerability diff --git a/build.gradle b/build.gradle index 9e76ef1..0910baa 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,3 @@ - subprojects { project -> group = 'io.github.blackspherefollower' version = "3.1." + ("${System.env.GITHUB_RUN_NUMBER ?: 1}") + ("${System.env.GITHUB_REF_TYPE}" == "tag" ? "" : "-SNAPSHOT") diff --git a/buttplug4j.connectors.javax.websocket.client/build.gradle b/buttplug4j.connectors.javax.websocket.client/build.gradle index a87fce0..19d9abc 100644 --- a/buttplug4j.connectors.javax.websocket.client/build.gradle +++ b/buttplug4j.connectors.javax.websocket.client/build.gradle @@ -63,8 +63,8 @@ publishing { uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = project.findProperty("maven.user") ?:System.getenv("MAVEN_USER") - password = project.findProperty("maven.pass") ?:System.getenv("MAVEN_PASS") + username = project.findProperty("maven.user") ?: System.getenv("MAVEN_USER") + password = project.findProperty("maven.pass") ?: System.getenv("MAVEN_PASS") } } } @@ -91,9 +91,9 @@ publishing { } } scm { - connection='scm:git:git:github.com/blackspherefollower/buttplug4j.git' - developerConnection='scm:git:https://github.com/blackspherefollower/buttplug4j.git' - url='https://github.com/blackspherefollower/buttplug4j' + connection = 'scm:git:git:github.com/blackspherefollower/buttplug4j.git' + developerConnection = 'scm:git:https://github.com/blackspherefollower/buttplug4j.git' + url = 'https://github.com/blackspherefollower/buttplug4j' } } } diff --git a/buttplug4j.connectors.javax.websocket.common/build.gradle b/buttplug4j.connectors.javax.websocket.common/build.gradle index 57801cd..6317e08 100644 --- a/buttplug4j.connectors.javax.websocket.common/build.gradle +++ b/buttplug4j.connectors.javax.websocket.common/build.gradle @@ -62,8 +62,8 @@ publishing { uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = project.findProperty("maven.user") ?:System.getenv("MAVEN_USER") - password = project.findProperty("maven.pass") ?:System.getenv("MAVEN_PASS") + username = project.findProperty("maven.user") ?: System.getenv("MAVEN_USER") + password = project.findProperty("maven.pass") ?: System.getenv("MAVEN_PASS") } } } @@ -90,9 +90,9 @@ publishing { } } scm { - connection='scm:git:git:github.com/blackspherefollower/buttplug4j.git' - developerConnection='scm:git:https://github.com/blackspherefollower/buttplug4j.git' - url='https://github.com/blackspherefollower/buttplug4j' + connection = 'scm:git:git:github.com/blackspherefollower/buttplug4j.git' + developerConnection = 'scm:git:https://github.com/blackspherefollower/buttplug4j.git' + url = 'https://github.com/blackspherefollower/buttplug4j' } } } diff --git a/buttplug4j.connectors.javax.websocket.common/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/common/ButtplugClientWSEndpoint.java b/buttplug4j.connectors.javax.websocket.common/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/common/ButtplugClientWSEndpoint.java index a822024..3c3b63e 100644 --- a/buttplug4j.connectors.javax.websocket.common/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/common/ButtplugClientWSEndpoint.java +++ b/buttplug4j.connectors.javax.websocket.common/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/common/ButtplugClientWSEndpoint.java @@ -6,13 +6,7 @@ import io.github.blackspherefollower.buttplug4j.protocol.ButtplugProtocolException; import io.github.blackspherefollower.buttplug4j.protocol.messages.Error; -import javax.websocket.ClientEndpoint; -import javax.websocket.CloseReason; -import javax.websocket.OnClose; -import javax.websocket.OnError; -import javax.websocket.OnMessage; -import javax.websocket.OnOpen; -import javax.websocket.Session; +import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; import java.nio.ByteBuffer; @@ -24,10 +18,10 @@ @ClientEndpoint @ServerEndpoint("/") public abstract class ButtplugClientWSEndpoint extends ButtplugClient { + private static final int TENSEC = 10000; private Session session; private Timer wsPingTimer; - public ButtplugClientWSEndpoint(final String aClientName) { super(aClientName); } @@ -36,8 +30,6 @@ public final Session getSession() { return session; } - private static final int TENSEC = 10000; - @OnMessage public final void onMessage(final Session sess, final String message) { try { diff --git a/buttplug4j.connectors.javax.websocket.server/build.gradle b/buttplug4j.connectors.javax.websocket.server/build.gradle index 9bd8a43..a208145 100644 --- a/buttplug4j.connectors.javax.websocket.server/build.gradle +++ b/buttplug4j.connectors.javax.websocket.server/build.gradle @@ -63,8 +63,8 @@ publishing { uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = project.findProperty("maven.user") ?:System.getenv("MAVEN_USER") - password = project.findProperty("maven.pass") ?:System.getenv("MAVEN_PASS") + username = project.findProperty("maven.user") ?: System.getenv("MAVEN_USER") + password = project.findProperty("maven.pass") ?: System.getenv("MAVEN_PASS") } } } @@ -91,9 +91,9 @@ publishing { } } scm { - connection='scm:git:git:github.com/blackspherefollower/buttplug4j.git' - developerConnection='scm:git:https://github.com/blackspherefollower/buttplug4j.git' - url='https://github.com/blackspherefollower/buttplug4j' + connection = 'scm:git:git:github.com/blackspherefollower/buttplug4j.git' + developerConnection = 'scm:git:https://github.com/blackspherefollower/buttplug4j.git' + url = 'https://github.com/blackspherefollower/buttplug4j' } } } diff --git a/buttplug4j.connectors.javax.websocket.server/src/test/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/server/ButtplugClientWSServerMockTest.java b/buttplug4j.connectors.javax.websocket.server/src/test/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/server/ButtplugClientWSServerMockTest.java index ef8345b..c572413 100644 --- a/buttplug4j.connectors.javax.websocket.server/src/test/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/server/ButtplugClientWSServerMockTest.java +++ b/buttplug4j.connectors.javax.websocket.server/src/test/java/io/github/blackspherefollower/buttplug4j/connectors/javax/websocket/server/ButtplugClientWSServerMockTest.java @@ -55,60 +55,60 @@ public ButtplugClientWSServerExample(int port) throws Exception { wsContainer.addEndpoint(ServerEndpointConfig.Builder.create(ButtplugClientWSEndpoint.class, "/{user}").configurator(new ServerEndpointConfig.Configurator() { @Override public T getEndpointInstance(Class endpointClass) { - if(endpointClass == ButtplugClientWSEndpoint.class) { + if (endpointClass == ButtplugClientWSEndpoint.class) { ButtplugClientWSServer client = new ButtplugClientWSServer("Java WS Server Buttplug Client"); client.setOnConnected(new IConnectedEvent() { @Override public void onConnected(ButtplugClient client) { new Thread(() -> { try { - if( client instanceof ButtplugClientWSServer ) { + if (client instanceof ButtplugClientWSServer) { Session s = ((ButtplugClientWSServer) client).getSession(); - s.getPathParameters().forEach((k,v) -> { + s.getPathParameters().forEach((k, v) -> { System.out.printf("param: %s -> %s\n", k, v); }); } client.startScanning(); - Thread.sleep(5000); - client.requestDeviceList(); - for ( - ButtplugClientDevice dev : client.getDevices()) { - if (dev.getScalarVibrateCount() > 0) { - dev.sendScalarVibrateCmd(0.5).get(); + Thread.sleep(5000); + client.requestDeviceList(); + for ( + ButtplugClientDevice dev : client.getDevices()) { + if (dev.getScalarVibrateCount() > 0) { + dev.sendScalarVibrateCmd(0.5).get(); + } } - } - Thread.sleep(1000); + Thread.sleep(1000); - assertTrue(client.stopAllDevices()); + assertTrue(client.stopAllDevices()); - Thread.sleep(60000); - for ( - ButtplugClientDevice dev : client.getDevices()) { - if (dev.getScalarVibrateCount() > 0) { - dev.sendScalarVibrateCmd(0.5).get(); + Thread.sleep(60000); + for ( + ButtplugClientDevice dev : client.getDevices()) { + if (dev.getScalarVibrateCount() > 0) { + dev.sendScalarVibrateCmd(0.5).get(); + } } - } - Thread.sleep(1000); + Thread.sleep(1000); - assertTrue(client.stopAllDevices()); + assertTrue(client.stopAllDevices()); - Thread.sleep(60000); - for ( - ButtplugClientDevice dev : client.getDevices()) { - if (dev.getScalarVibrateCount() > 0) { - dev.sendScalarVibrateCmd(0.5).get(); + Thread.sleep(60000); + for ( + ButtplugClientDevice dev : client.getDevices()) { + if (dev.getScalarVibrateCount() > 0) { + dev.sendScalarVibrateCmd(0.5).get(); + } } - } - Thread.sleep(1000); + Thread.sleep(1000); - assertTrue(client.stopAllDevices()); + assertTrue(client.stopAllDevices()); - client.disconnect(); + client.disconnect(); } catch (ExecutionException e) { throw new RuntimeException(e); } catch (InterruptedException e) { @@ -121,7 +121,7 @@ public void onConnected(ButtplugClient client) { }).start(); } }); - return (T)client; + return (T) client; } return null; } @@ -130,18 +130,15 @@ public void onConnected(ButtplugClient client) { server.start(); } - public URI getURI() - { + public URI getURI() { return server.getURI(); } - public void stop() throws Exception - { + public void stop() throws Exception { server.stop(); } - public void join() throws InterruptedException - { + public void join() throws InterruptedException { server.join(); } } diff --git a/buttplug4j.connectors.jetty.websocket.client/build.gradle b/buttplug4j.connectors.jetty.websocket.client/build.gradle index e9a21f8..0b32960 100644 --- a/buttplug4j.connectors.jetty.websocket.client/build.gradle +++ b/buttplug4j.connectors.jetty.websocket.client/build.gradle @@ -64,8 +64,8 @@ publishing { uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = project.findProperty("maven.user") ?:System.getenv("MAVEN_USER") - password = project.findProperty("maven.pass") ?:System.getenv("MAVEN_PASS") + username = project.findProperty("maven.user") ?: System.getenv("MAVEN_USER") + password = project.findProperty("maven.pass") ?: System.getenv("MAVEN_PASS") } } } @@ -92,9 +92,9 @@ publishing { } } scm { - connection='scm:git:git:github.com/blackspherefollower/buttplug4j.git' - developerConnection='scm:git:https://github.com/blackspherefollower/buttplug4j.git' - url='https://github.com/blackspherefollower/buttplug4j' + connection = 'scm:git:git:github.com/blackspherefollower/buttplug4j.git' + developerConnection = 'scm:git:https://github.com/blackspherefollower/buttplug4j.git' + url = 'https://github.com/blackspherefollower/buttplug4j' } } } diff --git a/buttplug4j.connectors.jetty.websocket.client/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/jetty/websocket/client/ButtplugClientWSClient.java b/buttplug4j.connectors.jetty.websocket.client/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/jetty/websocket/client/ButtplugClientWSClient.java index 02a24dd..cdffd29 100644 --- a/buttplug4j.connectors.jetty.websocket.client/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/jetty/websocket/client/ButtplugClientWSClient.java +++ b/buttplug4j.connectors.jetty.websocket.client/src/main/java/io/github/blackspherefollower/buttplug4j/connectors/jetty/websocket/client/ButtplugClientWSClient.java @@ -6,10 +6,10 @@ import io.github.blackspherefollower.buttplug4j.protocol.ButtplugProtocolException; import io.github.blackspherefollower.buttplug4j.protocol.messages.Error; import org.eclipse.jetty.util.component.LifeCycle; +import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.annotations.*; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.eclipse.jetty.websocket.api.Session; import java.io.IOException; import java.net.URI; @@ -18,14 +18,14 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; @WebSocket(maxTextMessageSize = 64 * 1024) public final class ButtplugClientWSClient extends ButtplugClient { + private static final int TENSEC = 10000; private WebSocketClient client; - private Session session; + private Timer wsPingTimer; public ButtplugClientWSClient(final String clientName) { super(clientName); @@ -88,13 +88,8 @@ public void run() { new Thread(() -> doHandshake()).start(); } - private Timer wsPingTimer; - - - private static final int TENSEC = 10000; - @OnWebSocketMessage - public final void onMessage(final Session sess, final String message) { + public void onMessage(final Session sess, final String message) { try { List msgs = getParser().parseJson(message); onMessage(msgs); diff --git a/buttplug4j/build.gradle b/buttplug4j/build.gradle index 8cdd872..84873d5 100644 --- a/buttplug4j/build.gradle +++ b/buttplug4j/build.gradle @@ -63,8 +63,8 @@ publishing { uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = project.findProperty("maven.user") ?:System.getenv("MAVEN_USER") - password = project.findProperty("maven.pass") ?:System.getenv("MAVEN_PASS") + username = project.findProperty("maven.user") ?: System.getenv("MAVEN_USER") + password = project.findProperty("maven.pass") ?: System.getenv("MAVEN_PASS") } } } @@ -91,9 +91,9 @@ publishing { } } scm { - connection='scm:git:git:github.com/blackspherefollower/buttplug4j.git' - developerConnection='scm:git:https://github.com/blackspherefollower/buttplug4j.git' - url='https://github.com/blackspherefollower/buttplug4j' + connection = 'scm:git:git:github.com/blackspherefollower/buttplug4j.git' + developerConnection = 'scm:git:https://github.com/blackspherefollower/buttplug4j.git' + url = 'https://github.com/blackspherefollower/buttplug4j' } } } diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/ButtplugException.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/ButtplugException.java index b38c4c3..e8a78fb 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/ButtplugException.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/ButtplugException.java @@ -4,12 +4,12 @@ public class ButtplugException extends Exception { private String errorMessage = ""; - protected final void setMessage(final String errorMessage) { - this.errorMessage = errorMessage; - } - @Override public final String getMessage() { return errorMessage; } + + protected final void setMessage(final String errorMessage) { + this.errorMessage = errorMessage; + } } diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClient.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClient.java index ffcf2c1..60087df 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClient.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClient.java @@ -4,21 +4,9 @@ import io.github.blackspherefollower.buttplug4j.protocol.ButtplugDeviceMessage; import io.github.blackspherefollower.buttplug4j.protocol.ButtplugJsonMessageParser; import io.github.blackspherefollower.buttplug4j.protocol.ButtplugMessage; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceAdded; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceList; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceRemoved; import io.github.blackspherefollower.buttplug4j.protocol.messages.Error; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Ok; +import io.github.blackspherefollower.buttplug4j.protocol.messages.*; import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.DeviceMessageInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Ping; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RequestDeviceList; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RequestServerInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ScanningFinished; -import io.github.blackspherefollower.buttplug4j.protocol.messages.SensorReading; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ServerInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StartScanning; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopAllDevices; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopScanning; import java.io.IOException; import java.util.ArrayList; diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDevice.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDevice.java index 9de0ad1..da64f22 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDevice.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/client/ButtplugClientDevice.java @@ -1,18 +1,9 @@ package io.github.blackspherefollower.buttplug4j.client; -import io.github.blackspherefollower.buttplug4j.util.Pair; import io.github.blackspherefollower.buttplug4j.protocol.ButtplugMessage; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceAdded; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceRemoved; -import io.github.blackspherefollower.buttplug4j.protocol.messages.LinearCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.DeviceMessage; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.DeviceMessageInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.GenericFeatureAttributes; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.GenericMessageAttributes; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.MessageAttributes; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RotateCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ScalarCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopDeviceCmd; +import io.github.blackspherefollower.buttplug4j.protocol.messages.*; +import io.github.blackspherefollower.buttplug4j.protocol.messages.Parts.*; +import io.github.blackspherefollower.buttplug4j.util.Pair; import java.util.ArrayList; import java.util.HashMap; diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/ButtplugMessage.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/ButtplugMessage.java index 5fe2810..445b9dd 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/ButtplugMessage.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/ButtplugMessage.java @@ -5,27 +5,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceAdded; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceList; -import io.github.blackspherefollower.buttplug4j.protocol.messages.DeviceRemoved; import io.github.blackspherefollower.buttplug4j.protocol.messages.Error; -import io.github.blackspherefollower.buttplug4j.protocol.messages.LinearCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Ok; -import io.github.blackspherefollower.buttplug4j.protocol.messages.Ping; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RequestDeviceList; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RequestServerInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.RotateCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ScalarCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ScanningFinished; -import io.github.blackspherefollower.buttplug4j.protocol.messages.SensorReadCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.SensorReading; -import io.github.blackspherefollower.buttplug4j.protocol.messages.SensorSubscribeCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.SensorUnsubscribeCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.ServerInfo; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StartScanning; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopAllDevices; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopDeviceCmd; -import io.github.blackspherefollower.buttplug4j.protocol.messages.StopScanning; +import io.github.blackspherefollower.buttplug4j.protocol.messages.*; @JsonTypeInfo(include = As.WRAPPER_OBJECT, use = Id.NAME) @JsonSubTypes({ diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessage.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessage.java index 40e0fec..8b80cbd 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessage.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessage.java @@ -1,6 +1,9 @@ package io.github.blackspherefollower.buttplug4j.protocol.messages.Parts; public final class DeviceMessage { + private String message; + private MessageAttributes attributes; + public String getMessage() { return message; } @@ -16,7 +19,4 @@ public MessageAttributes getAttributes() { public void setAttributes(final MessageAttributes attributes) { this.attributes = attributes; } - - private String message; - private MessageAttributes attributes; } diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessageInfo.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessageInfo.java index 7b00660..e06d47c 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessageInfo.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessageInfo.java @@ -22,6 +22,29 @@ public final class DeviceMessageInfo { @JsonProperty(value = "DeviceDisplayName") @JsonInclude(JsonInclude.Include.NON_EMPTY) private String deviceDisplayName; + @JsonProperty(value = "DeviceMessages", required = true) + @JsonDeserialize(using = DeviceMessagesDeserializer.class) + @JsonSerialize(using = DeviceMessagesSerializer.class) + private ArrayList deviceMessages; + + public DeviceMessageInfo(final long deviceIndex, final String deviceName, + final ArrayList deviceMessages, final int deviceMessageTimingGap, + final String deviceDisplayName) { + this.deviceName = deviceName; + this.deviceIndex = deviceIndex; + this.deviceMessages = deviceMessages; + this.deviceMessageTimingGap = deviceMessageTimingGap; + this.deviceDisplayName = deviceDisplayName; + } + + @SuppressWarnings("unused") + private DeviceMessageInfo() { + this.deviceName = ""; + this.deviceIndex = -1; + this.deviceMessages = new ArrayList<>(); + this.deviceMessageTimingGap = null; + this.deviceDisplayName = ""; + } public long getDeviceIndex() { return deviceIndex; @@ -62,28 +85,4 @@ public ArrayList getDeviceMessages() { public void setDeviceMessages(final ArrayList deviceMessages) { this.deviceMessages = deviceMessages; } - - @JsonProperty(value = "DeviceMessages", required = true) - @JsonDeserialize(using = DeviceMessagesDeserializer.class) - @JsonSerialize(using = DeviceMessagesSerializer.class) - private ArrayList deviceMessages; - - public DeviceMessageInfo(final long deviceIndex, final String deviceName, - final ArrayList deviceMessages, final int deviceMessageTimingGap, - final String deviceDisplayName) { - this.deviceName = deviceName; - this.deviceIndex = deviceIndex; - this.deviceMessages = deviceMessages; - this.deviceMessageTimingGap = deviceMessageTimingGap; - this.deviceDisplayName = deviceDisplayName; - } - - @SuppressWarnings("unused") - private DeviceMessageInfo() { - this.deviceName = ""; - this.deviceIndex = -1; - this.deviceMessages = new ArrayList<>(); - this.deviceMessageTimingGap = null; - this.deviceDisplayName = ""; - } } diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessagesDeserializer.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessagesDeserializer.java index f92009c..f7cb3eb 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessagesDeserializer.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/Parts/DeviceMessagesDeserializer.java @@ -20,7 +20,7 @@ public Object deserialize(final JsonParser p, final DeserializationContext ctxt) JsonNode node = oc.readTree(p); ArrayList ret = new ArrayList<>(); - for (Iterator> it = node.fields(); it.hasNext();) { + for (Iterator> it = node.fields(); it.hasNext(); ) { Map.Entry msg = it.next(); DeviceMessage dmsg = new DeviceMessage(); dmsg.setMessage(msg.getKey()); @@ -39,7 +39,7 @@ public Object deserialize(final JsonParser p, final DeserializationContext ctxt) case "SensorReadCmd": case "SensorSubscribeCmd": SensorMessageAttributes sattrs = new SensorMessageAttributes(); - for (Iterator it2 = msg.getValue().elements(); it2.hasNext();) { + for (Iterator it2 = msg.getValue().elements(); it2.hasNext(); ) { sattrs.getFeatures().add(new ObjectMapper().treeToValue(it2.next(), SensorFeatureAttributes.class)); } @@ -48,12 +48,12 @@ public Object deserialize(final JsonParser p, final DeserializationContext ctxt) case "ScalarCmd": case "LinearCmd": case "RotateCmd": - GenericMessageAttributes gattrs = new GenericMessageAttributes(); - for (Iterator it2 = msg.getValue().elements(); it2.hasNext();) { - gattrs.getFeatures().add(new ObjectMapper().treeToValue(it2.next(), - GenericFeatureAttributes.class)); - } - dmsg.setAttributes(gattrs); + GenericMessageAttributes gattrs = new GenericMessageAttributes(); + for (Iterator it2 = msg.getValue().elements(); it2.hasNext(); ) { + gattrs.getFeatures().add(new ObjectMapper().treeToValue(it2.next(), + GenericFeatureAttributes.class)); + } + dmsg.setAttributes(gattrs); break; default: throw new JsonParseException(p, "Unknown Buttplug Device Message type: " + dmsg.getMessage()); diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/ScalarCmd.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/ScalarCmd.java index 86d06e8..2ed3ee0 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/ScalarCmd.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/protocol/messages/ScalarCmd.java @@ -1,9 +1,9 @@ package io.github.blackspherefollower.buttplug4j.protocol.messages; import com.fasterxml.jackson.annotation.JsonProperty; -import io.github.blackspherefollower.buttplug4j.util.Pair; import io.github.blackspherefollower.buttplug4j.protocol.ButtplugConsts; import io.github.blackspherefollower.buttplug4j.protocol.ButtplugDeviceMessage; +import io.github.blackspherefollower.buttplug4j.util.Pair; import java.util.ArrayList; diff --git a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/util/Pair.java b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/util/Pair.java index 46bed1c..31355e8 100644 --- a/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/util/Pair.java +++ b/buttplug4j/src/main/java/io/github/blackspherefollower/buttplug4j/util/Pair.java @@ -9,6 +9,7 @@ public Pair(final A a, final B b) { this.a = a; this.b = b; } + public A getLeft() { return a; } diff --git a/checkstyle.xml b/checkstyle.xml index 454f6ff..2116b88 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -52,7 +52,7 @@ + default="checkstyle-suppressions.xml"/> @@ -102,19 +102,19 @@ - + - + - + - + - + @@ -174,7 +174,7 @@ - + @@ -202,7 +202,7 @@ + default="checkstyle-xpath-suppressions.xml"/>