Skip to content

Commit

Permalink
chore: include missing connector libs
Browse files Browse the repository at this point in the history
  • Loading branch information
blackspherefollower committed Aug 8, 2023
1 parent 850e0ce commit 42c257b
Show file tree
Hide file tree
Showing 8 changed files with 725 additions and 0 deletions.
108 changes: 108 additions & 0 deletions buttplug4j.connectors.javax.websocket.client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
plugins {
id 'java-library'
id 'jacoco'
id 'maven-publish'
id 'checkstyle'
id 'signing'
}

repositories {
mavenCentral()
}

dependencies {
api project(':buttplug4j.connectors.javax.websocket.common')
api 'org.eclipse.jetty.websocket:websocket-javax-client:10.0.15'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
withJavadocJar()
withSourcesJar()
}
checkstyle {
configFile = file("${rootDir}/checkstyle.xml")
showViolations = false
ignoreFailures = true
}
test {
finalizedBy jacocoTestReport
finalizedBy check
}
jacocoTestReport {
dependsOn test
}
tasks.named('test') {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
csv.required = true
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${System.env.GITHUB_REPOSITORY}")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
maven {
name = "ossrh"
url = version.contains("-SNAPSHOT") ?
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") :
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")
}
}
}
publications {
mavenJava(MavenPublication) {
from(components.java)
pom {
name = 'Buttplug for Java'
description = 'A pure Java Buttplug Client implementation'
url = 'https://github.com/blackspherefollower/buttplug4j'
inceptionYear = '2017'

licenses {
license {
name = 'BSDv3 License'
url = 'https://github.com/blackspherefollower/buttplug4j/'
}
}
developers {
developer {
id = 'blackspherefollower'
name = 'BlackSphereFollower'
email = 'blackspherefollower@iostindex.com'
}
}
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'
}
}
}
}
}

signing {
def gpgKey = project.findProperty("gpg.key") ?: System.getenv("OSSRH_GPG") ?: ""
def gpgPass = project.findProperty("gpg.pass") ?: System.getenv("OSSRH_GPG_PASS") ?: ""
useInMemoryPgpKeys(gpgKey.replaceAll("\\\\n", "\n"), gpgPass)
sign publishing.publications.mavenJava
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.blackspherefollower.buttplug4j.connectors.javax.client;

import io.github.blackspherefollower.buttplug4j.client.ButtplugClient;
import io.github.blackspherefollower.buttplug4j.connectors.javax.common.ButtplugClientWSEndpoint;
import org.eclipse.jetty.util.component.LifeCycle;

import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@ClientEndpoint
public final class ButtplugClientWSClient extends ButtplugClientWSEndpoint {

private WebSocketContainer client;

public ButtplugClientWSClient(final String clientName) {
super(clientName);
}

public void connect(final URI url) throws IllegalStateException, DeploymentException, IOException,
ExecutionException, InterruptedException {

if (client != null && getSession() != null && getSession().isOpen()) {
throw new IllegalStateException("WS is already open");
}
setConnectionState(ButtplugClient.ConnectionState.CONNECTING);

CompletableFuture<Boolean> promise = new CompletableFuture<>();
setOnConnected(client -> promise.complete(true));

client = ContainerProvider.getWebSocketContainer();
client.connectToServer(this, url);
promise.get();
}

protected void cleanup() {

if (getSession() != null) {
try {
getSession().close();
} catch (IOException e) {
// noop - something when wrong closing the socket, but we're
// about to dispose of it anyway.
}
}

LifeCycle.stop(client);
client = null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.github.blackspherefollower.buttplug4j.connectors.javax.client;

import io.github.blackspherefollower.buttplug4j.client.ButtplugClientDevice;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.net.URI;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class ButtplugWSClientMockTest {

@Disabled
@Test
public void TestConnect() throws Exception {
ButtplugClientWSClient client = new ButtplugClientWSClient("Java Test");
client.connect(new URI("ws://localhost:12345/buttplug"));
client.startScanning();

Thread.sleep(5000);
client.requestDeviceList();
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
}
}

Thread.sleep(1000);
assertTrue(client.stopAllDevices());

Thread.sleep(60000);
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
}
}

Thread.sleep(1000);
assertTrue(client.stopAllDevices());

Thread.sleep(60000);
for (ButtplugClientDevice dev : client.getDevices()) {
if (dev.getScalarVibrateCount() > 0) {
dev.sendScalarVibrateCmd(0.5).get();
}
}

Thread.sleep(1000);
assertTrue(client.stopAllDevices());

client.disconnect();
}
}
107 changes: 107 additions & 0 deletions buttplug4j.connectors.javax.websocket.common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
plugins {
id 'java-library'
id 'jacoco'
id 'maven-publish'
id 'checkstyle'
id 'signing'
}

repositories {
mavenCentral()
}

dependencies {
api project(':buttplug4j')
api 'javax.websocket:javax.websocket-api:1.1'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
withJavadocJar()
withSourcesJar()
}
checkstyle {
configFile = file("${rootDir}/checkstyle.xml")
showViolations = false
ignoreFailures = true
}
test {
finalizedBy jacocoTestReport
finalizedBy check
}
jacocoTestReport {
dependsOn test
}
tasks.named('test') {
useJUnitPlatform()
}

jacocoTestReport {
reports {
xml.required = true
csv.required = true
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${System.env.GITHUB_REPOSITORY}")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
maven {
name = "ossrh"
url = version.contains("-SNAPSHOT") ?
uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") :
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")
}
}
}
publications {
mavenJava(MavenPublication) {
from(components.java)
pom {
name = 'Buttplug for Java'
description = 'A pure Java Buttplug Client implementation'
url = 'https://github.com/blackspherefollower/buttplug4j'
inceptionYear = '2017'

licenses {
license {
name = 'BSDv3 License'
url = 'https://github.com/blackspherefollower/buttplug4j/'
}
}
developers {
developer {
id = 'blackspherefollower'
name = 'BlackSphereFollower'
email = 'blackspherefollower@iostindex.com'
}
}
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'
}
}
}
}
}

signing {
def gpgKey = project.findProperty("gpg.key") ?: System.getenv("OSSRH_GPG") ?: ""
def gpgPass = project.findProperty("gpg.pass") ?: System.getenv("OSSRH_GPG_PASS") ?: ""
useInMemoryPgpKeys(gpgKey.replaceAll("\\\\n", "\n"), gpgPass)
sign publishing.publications.mavenJava
}
Loading

0 comments on commit 42c257b

Please sign in to comment.