Skip to content

Commit

Permalink
Actualize sample with latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed May 21, 2024
1 parent cd25b85 commit 9cac34d
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 192 deletions.
21 changes: 7 additions & 14 deletions samples/chat/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,8 +14,6 @@
* limitations under the License.
*/

import org.jetbrains.kotlin.konan.target.*

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
Expand All @@ -30,19 +28,14 @@ kotlin {
browser()
nodejs()
}
when {
HostManager.hostIsLinux -> linuxX64("native")
HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("native")
HostManager.hostIsMac -> macosX64("native")
else -> null
}
linuxX64()
macosX64()
macosArm64()

sourceSets {
commonMain {
dependencies {
api("io.rsocket.kotlin:rsocket-core:$rsocketVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion")
}
commonMain.dependencies {
api("io.rsocket.kotlin:rsocket-core:$rsocketVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,20 +14,18 @@
* limitations under the License.
*/

package io.rsocket.kotlin.samples.chat.client
import org.jetbrains.kotlin.gradle.targets.js.nodejs.*
import org.jetbrains.kotlin.gradle.targets.js.npm.*

import io.rsocket.kotlin.samples.chat.api.*
import kotlinx.coroutines.*
plugins {
kotlin("multiplatform") apply false
}

suspend fun main() {
coroutineScope {
//only WS is supported on browser JS
// native WS server is incompatible with js WS client
(Servers.WS - Servers.Native.WS).forEach {
val client = ApiClient(it, "Yuri")
launch {
client.use(it, "RSocket is awesome! (from browser)")
}
}
plugins.withType<NodeJsRootPlugin> {
// ignore package lock
extensions.configure<NpmExtension> {
lockFileDirectory.set(layout.buildDirectory.dir("kotlin-js-store"))
packageLockMismatchReport.set(LockFileMismatchReport.NONE)
packageLockAutoReplace.set(true)
}
}
69 changes: 25 additions & 44 deletions samples/chat/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*

plugins {
kotlin("multiplatform")
Expand All @@ -33,56 +33,37 @@ kotlin {
jvm {
withJava()
}
js("browser") {
browser {
binaries.executable()
}
}
js("nodejs") {
nodejs {
binaries.executable()
}
js {
browser()
nodejs()
binaries.executable()
}
when {
HostManager.hostIsLinux -> linuxX64("native")
HostManager.hostIsMingw -> null //no native support for TCP in ktor mingwX64("clientNative")
HostManager.hostIsMac -> macosX64("native")
else -> null
}?.binaries {
executable {
entryPoint = "io.rsocket.kotlin.samples.chat.client.main"
linuxX64()
macosX64()
macosArm64()
targets.withType<KotlinNativeTarget>().configureEach {
binaries {
executable {
entryPoint = "io.rsocket.kotlin.samples.chat.client.main"
}
}
}

sourceSets {
commonMain {
dependencies {
implementation(project(":api"))
implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion")
}
commonMain.dependencies {
implementation(project(":api"))
implementation("io.rsocket.kotlin:rsocket-transport-ktor-websocket-client:$rsocketVersion")
}
val jvmMain by getting {
dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
jvmMain.dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
findByName("nativeMain")?.apply {
dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
nativeMain.dependencies {
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:$rsocketVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
val browserMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
}
}
val nodejsMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("io.rsocket.kotlin:rsocket-transport-nodejs-tcp:$rsocketVersion")
}
jsMain.dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,12 @@ package io.rsocket.kotlin.samples.chat.client
import io.rsocket.kotlin.samples.chat.api.*
import kotlinx.coroutines.*

suspend fun main() {
coroutineScope {
// native WS server is incompatible with js WS client
(Servers.ALL - Servers.Native.WS).forEach {
val client = ApiClient(it, "Kolya")
launch {
client.use(it, "RSocket is awesome! (from nodeJS)")
}
suspend fun main(): Unit = coroutineScope {
// only WS is supported on browser JS
Servers.WS.forEach {
val client = ApiClient(it, "Kolya")
launch {
client.use(it, "RSocket is awesome! (from js)")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2022 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright 2015-2022 the original author or authors.
~ Copyright 2015-2024 the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
32 changes: 0 additions & 32 deletions samples/chat/client/src/nodejsMain/kotlin/clientTransport.kt

This file was deleted.

22 changes: 11 additions & 11 deletions samples/chat/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2022 the original author or authors.
# Copyright 2015-2024 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,16 +15,16 @@
#
group=io.rsocket.kotlin.sample.chat
version=1.0.0
kotlinVersion=1.6.20
ktorVersion=2.0.0
kotlinxSerializationVersion=1.3.2
rsocketVersion=0.15.4
kotlin.js.compiler=ir
kotlin.mpp.stability.nowarn=true
kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled
kotlinVersion=2.0.0
ktorVersion=2.3.11
kotlinxSerializationVersion=1.6.3
rsocketVersion=0.16.0

#Kotlin
kotlin.js.yarn=false
#Gradle
org.gradle.jvmargs=-Xmx2g
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2g
org.gradle.vfs.watch=true
Binary file modified samples/chat/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion samples/chat/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions samples/chat/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,18 +198,28 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
Loading

0 comments on commit 9cac34d

Please sign in to comment.