From 6eaf3ed0da3ad949d1c728c13c7c29da989bacdb Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 15 Jul 2021 14:09:31 +0300 Subject: [PATCH 1/7] client only tests test JS WS Client transport update pipelines to run ktor JS tests --- .github/workflows/gradle-main.yml | 2 +- .github/workflows/gradle-pr.yml | 2 +- .github/workflows/run-tests.yml | 2 +- build.gradle.kts | 7 +- examples/multiplatform-chat/build.gradle.kts | 2 +- playground/build.gradle.kts | 7 +- .../rsocket-test-server/build.gradle.kts | 87 +++++++++++++++++++ .../io/rsocket/kotlin/test/server/App.kt | 75 ++++++++++++++++ rsocket-transport-ktor/build.gradle.kts | 2 + .../ktor/ClientWebSocketTransportTest.kt | 43 +++++++++ settings.gradle.kts | 2 + 11 files changed, 219 insertions(+), 12 deletions(-) create mode 100644 rsocket-test/rsocket-test-server/build.gradle.kts create mode 100644 rsocket-test/rsocket-test-server/src/jvmMain/kotlin/io/rsocket/kotlin/test/server/App.kt create mode 100644 rsocket-transport-ktor/src/jsTest/kotlin/io/rsocket/kotlin/transport/ktor/ClientWebSocketTransportTest.kt diff --git a/.github/workflows/gradle-main.yml b/.github/workflows/gradle-main.yml index 5a31413a3..a9664d656 100644 --- a/.github/workflows/gradle-main.yml +++ b/.github/workflows/gradle-main.yml @@ -78,7 +78,7 @@ jobs: dependencies-cache-enabled: false configuration-cache-enabled: false - name: Test rsocket-transport-ktor module - if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure()) + if: matrix.target != 'mingwX64' && (success() || failure()) timeout-minutes: 10 uses: gradle/gradle-build-action@v1 with: diff --git a/.github/workflows/gradle-pr.yml b/.github/workflows/gradle-pr.yml index 52c5995ab..34b370f16 100644 --- a/.github/workflows/gradle-pr.yml +++ b/.github/workflows/gradle-pr.yml @@ -73,7 +73,7 @@ jobs: dependencies-cache-enabled: false configuration-cache-enabled: false - name: Test rsocket-transport-ktor module - if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure()) + if: matrix.target != 'mingwX64' && (success() || failure()) timeout-minutes: 10 uses: gradle/gradle-build-action@v1 with: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index cbb9c0c74..9f9ddc1b4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -72,7 +72,7 @@ jobs: dependencies-cache-enabled: false configuration-cache-enabled: false - name: Test rsocket-transport-ktor module - if: matrix.target != 'mingwX64' && matrix.target != 'jsIrNode' && matrix.target != 'jsIrBrowser' && matrix.target != 'jsLegacyNode' && matrix.target != 'jsLegacyBrowser' && (success() || failure()) + if: matrix.target != 'mingwX64' && (success() || failure()) timeout-minutes: 10 uses: gradle/gradle-build-action@v1 with: diff --git a/build.gradle.kts b/build.gradle.kts index fb20ca1b7..6447c1dd0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,8 +63,9 @@ subprojects { //targets configuration extensions.configure { val isAutoConfigurable = project.name.startsWith("rsocket") //manual config of others - val jvmOnly = project.name == "rsocket-transport-ktor-server" //server is jvm only - + val jvmOnly = + project.name == "rsocket-transport-ktor-server" || //server is jvm only + project.name == "rsocket-test-server" //windows target isn't supported by ktor-network val supportMingw = project.name != "rsocket-transport-ktor" && project.name != "rsocket-transport-ktor-client" @@ -140,7 +141,7 @@ subprojects { //common configuration extensions.configure { - val isTestProject = project.name == "rsocket-test" + val isTestProject = project.name == "rsocket-test" || project.name == "rsocket-test-server" val isLibProject = project.name.startsWith("rsocket") val isPlaygroundProject = project.name == "playground" val isExampleProject = "examples" in project.path diff --git a/examples/multiplatform-chat/build.gradle.kts b/examples/multiplatform-chat/build.gradle.kts index 822cdbe29..e229c3c1e 100644 --- a/examples/multiplatform-chat/build.gradle.kts +++ b/examples/multiplatform-chat/build.gradle.kts @@ -80,7 +80,7 @@ kotlin { val clientJsMain by getting { dependsOn(clientMain) dependencies { - implementation("io.ktor:ktor-client-js:$ktorVersion") + implementation("io.ktor:ktor-client-core:$ktorVersion") } } diff --git a/playground/build.gradle.kts b/playground/build.gradle.kts index 63d299690..bd81ccd28 100644 --- a/playground/build.gradle.kts +++ b/playground/build.gradle.kts @@ -46,6 +46,8 @@ kotlin { implementation(project(":rsocket-core")) implementation(project(":rsocket-transport-local")) implementation(project(":rsocket-transport-ktor-client")) + + implementation("io.ktor:ktor-client-core:$ktorVersion") //for WS support } } val jvmMain by getting { @@ -56,10 +58,5 @@ kotlin { implementation("io.ktor:ktor-server-cio:$ktorVersion") } } - val jsMain by getting { - dependencies { - implementation("io.ktor:ktor-client-js:$ktorVersion") //for WS support - } - } } } diff --git a/rsocket-test/rsocket-test-server/build.gradle.kts b/rsocket-test/rsocket-test-server/build.gradle.kts new file mode 100644 index 000000000..5fd31fcba --- /dev/null +++ b/rsocket-test/rsocket-test-server/build.gradle.kts @@ -0,0 +1,87 @@ +/* + * Copyright 2015-2020 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. + * 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. + */ + +import org.jetbrains.kotlin.gradle.plugin.mpp.* +import java.io.* +import java.net.* + +plugins { + kotlin("multiplatform") +} + +val ktorVersion: String by rootProject + +kotlin { + sourceSets { + val jvmMain by getting { + dependencies { + implementation(project(":rsocket-test")) + implementation(project(":rsocket-transport-ktor-server")) + + implementation("io.ktor:ktor-server-cio:$ktorVersion") + } + } + } +} + +open class RSocketTestServer : DefaultTask() { + @Internal + var server: Closeable? = null + private set + + @Internal + lateinit var classpath: FileCollection + + @TaskAction + fun exec() { + try { + println("[TestServer] start") + val loader = URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader()) + server = loader.loadClass("io.rsocket.kotlin.test.server.AppKt").getMethod("start").invoke(null) as Closeable + println("[TestServer] started") + } catch (cause: Throwable) { + println("[TestServer] failed: ${cause.message}") + cause.printStackTrace() + } + } +} + +val startTestServer by tasks.registering(RSocketTestServer::class) { + dependsOn(tasks["jvmJar"]) + classpath = (kotlin.targets["jvm"].compilations["test"] as KotlinJvmCompilation).runtimeDependencyFiles +} + +val testTasks = setOf( + "jsLegacyNodeTest", + "jsIrNodeTest", + "jsLegacyBrowserTest", + "jsIrBrowserTest", +) + +rootProject.allprojects { + if (name == "rsocket-transport-ktor") { + tasks.matching { it.name in testTasks }.all { + dependsOn(startTestServer) + } + } +} + +gradle.buildFinished { + startTestServer.get().server?.run { + close() + println("[TestServer] stop") + } +} diff --git a/rsocket-test/rsocket-test-server/src/jvmMain/kotlin/io/rsocket/kotlin/test/server/App.kt b/rsocket-test/rsocket-test-server/src/jvmMain/kotlin/io/rsocket/kotlin/test/server/App.kt new file mode 100644 index 000000000..904b77c5d --- /dev/null +++ b/rsocket-test/rsocket-test-server/src/jvmMain/kotlin/io/rsocket/kotlin/test/server/App.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2015-2020 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. + * 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 io.rsocket.kotlin.test.server + +import io.ktor.application.* +import io.ktor.routing.* +import io.ktor.server.cio.* +import io.ktor.server.engine.* +import io.ktor.websocket.* +import io.rsocket.kotlin.core.* +import io.rsocket.kotlin.test.* +import io.rsocket.kotlin.transport.ktor.* +import io.rsocket.kotlin.transport.ktor.server.* +import kotlinx.coroutines.* +import java.io.* + +fun main() { + start().await() +} + +fun start(): TestServer { + val server = TestServer() + server.start() + return server +} + +class TestServer : Closeable { + private val job = Job() + private var wsServer: ApplicationEngine? = null + private val rSocketServer = RSocketServer { +// loggerFactory = PrintLogger.withLevel(LoggingLevel.DEBUG) + } + + fun start(): Unit = runCatching { + val scope = CoroutineScope(job) + + //start TCP server + rSocketServer.bindIn(scope, TcpServerTransport(port = 8000)) { TestRSocket() } + + //start WS server + wsServer = scope.embeddedServer(CIO, port = 9000) { + install(WebSockets) + install(RSocketSupport) { server = rSocketServer } + + routing { + rSocket { TestRSocket() } + } + }.start() + + Thread.sleep(1000) //await start + }.onFailure { close() }.getOrThrow() + + fun await() { + runBlocking { job.join() } + } + + override fun close() { + runBlocking { job.cancelAndJoin() } + wsServer?.stop(0, 1000) + } +} diff --git a/rsocket-transport-ktor/build.gradle.kts b/rsocket-transport-ktor/build.gradle.kts index 01e2e152a..8c289a3e6 100644 --- a/rsocket-transport-ktor/build.gradle.kts +++ b/rsocket-transport-ktor/build.gradle.kts @@ -58,3 +58,5 @@ kotlin { } description = "Ktor RSocket transport implementations (TCP, Websocket)" + +evaluationDependsOn(":rsocket-test-server") diff --git a/rsocket-transport-ktor/src/jsTest/kotlin/io/rsocket/kotlin/transport/ktor/ClientWebSocketTransportTest.kt b/rsocket-transport-ktor/src/jsTest/kotlin/io/rsocket/kotlin/transport/ktor/ClientWebSocketTransportTest.kt new file mode 100644 index 000000000..2285574a1 --- /dev/null +++ b/rsocket-transport-ktor/src/jsTest/kotlin/io/rsocket/kotlin/transport/ktor/ClientWebSocketTransportTest.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2015-2020 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. + * 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 io.rsocket.kotlin.transport.ktor + +import io.ktor.client.* +import io.ktor.client.engine.js.* +import io.ktor.client.features.websocket.* +import io.rsocket.kotlin.test.* +import io.rsocket.kotlin.transport.ktor.client.* +import kotlinx.coroutines.* + +class ClientWebSocketTransportTest : TransportTest() { + + private val httpClient = HttpClient(Js) { + install(WebSockets) + install(RSocketSupport) { connector = CONNECTOR } + } + + override suspend fun before() { + client = httpClient.rSocket(port = 9000) + } + + override suspend fun after() { + super.after() + httpClient.close() + httpClient.coroutineContext.job.cancelAndJoin() + } + +} diff --git a/settings.gradle.kts b/settings.gradle.kts index be056ed4b..207278e2d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -62,6 +62,8 @@ include("playground") include("rsocket-core") include("rsocket-test") +include("rsocket-test-server") +project(":rsocket-test-server").projectDir = file("rsocket-test/rsocket-test-server") include("rsocket-transport-local") From 9e1bae50621603ec64208f6d331db542355f9505 Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:18:58 +0300 Subject: [PATCH 2/7] gradle 7.2 --- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 257 ++++++++++++++--------- 2 files changed, 154 insertions(+), 105 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 05679dc3c..ffed3a254 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 744e882ed..1b6c78733 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# 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 +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +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"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + 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. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# 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. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" From 627cca4183cfd080fa2fcc62b9b087cc644020dc Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:19:59 +0300 Subject: [PATCH 3/7] remove playground and publish check --- playground/build.gradle.kts | 62 ---------- playground/src/commonMain/kotlin/Metadata.kt | 109 ------------------ playground/src/commonMain/kotlin/Stub.kt | 57 --------- playground/src/commonMain/kotlin/TCP.kt | 33 ------ playground/src/commonMain/kotlin/WS.kt | 30 ----- playground/src/commonMain/kotlin/streams.kt | 50 -------- playground/src/jsMain/kotlin/WSApp.kt | 19 --- playground/src/jsMain/resources/index.html | 27 ----- playground/src/jvmMain/kotlin/TcpClientApp.kt | 19 --- playground/src/jvmMain/kotlin/TcpServerApp.kt | 27 ----- playground/src/jvmMain/kotlin/WSClientApp.kt | 19 --- playground/src/jvmMain/kotlin/WSServerApp.kt | 30 ----- playground/src/nativeMain/kotlin/TcpApp.kt | 24 ---- publish-check/build.gradle.kts | 88 -------------- publish-check/src/commonMain/kotlin/Stub.kt | 22 ---- .../src/commonTest/kotlin/StubTest.kt | 26 ----- settings.gradle.kts | 4 - 17 files changed, 646 deletions(-) delete mode 100644 playground/build.gradle.kts delete mode 100644 playground/src/commonMain/kotlin/Metadata.kt delete mode 100644 playground/src/commonMain/kotlin/Stub.kt delete mode 100644 playground/src/commonMain/kotlin/TCP.kt delete mode 100644 playground/src/commonMain/kotlin/WS.kt delete mode 100644 playground/src/commonMain/kotlin/streams.kt delete mode 100644 playground/src/jsMain/kotlin/WSApp.kt delete mode 100644 playground/src/jsMain/resources/index.html delete mode 100644 playground/src/jvmMain/kotlin/TcpClientApp.kt delete mode 100644 playground/src/jvmMain/kotlin/TcpServerApp.kt delete mode 100644 playground/src/jvmMain/kotlin/WSClientApp.kt delete mode 100644 playground/src/jvmMain/kotlin/WSServerApp.kt delete mode 100644 playground/src/nativeMain/kotlin/TcpApp.kt delete mode 100644 publish-check/build.gradle.kts delete mode 100644 publish-check/src/commonMain/kotlin/Stub.kt delete mode 100644 publish-check/src/commonTest/kotlin/StubTest.kt diff --git a/playground/build.gradle.kts b/playground/build.gradle.kts deleted file mode 100644 index bd81ccd28..000000000 --- a/playground/build.gradle.kts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import org.jetbrains.kotlin.konan.target.* - -plugins { - kotlin("multiplatform") -} - -val ktorVersion: String by rootProject - -kotlin { - jvm() - js(IR) { - browser { - binaries.executable() - } - } - when { - HostManager.hostIsLinux -> linuxX64("native") -// HostManager.hostIsMingw -> mingwX64("native") //no native support for TCP - HostManager.hostIsMac -> macosX64("native") - else -> null - }?.binaries { - executable { - entryPoint = "main" - } - } - - sourceSets { - val commonMain by getting { - dependencies { - implementation(project(":rsocket-core")) - implementation(project(":rsocket-transport-local")) - implementation(project(":rsocket-transport-ktor-client")) - - implementation("io.ktor:ktor-client-core:$ktorVersion") //for WS support - } - } - val jvmMain by getting { - dependencies { - implementation(project(":rsocket-transport-ktor-server")) - - implementation("io.ktor:ktor-client-cio:$ktorVersion") - implementation("io.ktor:ktor-server-cio:$ktorVersion") - } - } - } -} diff --git a/playground/src/commonMain/kotlin/Metadata.kt b/playground/src/commonMain/kotlin/Metadata.kt deleted file mode 100644 index 1b39431a5..000000000 --- a/playground/src/commonMain/kotlin/Metadata.kt +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.utils.io.core.* -import io.rsocket.kotlin.* -import io.rsocket.kotlin.core.* -import io.rsocket.kotlin.metadata.* -import io.rsocket.kotlin.payload.* - -@OptIn(ExperimentalMetadataApi::class) -public fun metadata() { - - //writing - - val routing = RoutingMetadata("tag1", "route1", "something") - val tracing = ZipkinTracingMetadata( - kind = ZipkinTracingMetadata.Kind.Sample, - traceId = 123L, - spanId = 123L - ) - val cm1 = buildCompositeMetadata { - add(routing) - add(tracing) - } - // or - val cm2 = CompositeMetadata(routing, tracing) - - //all lambdas are inline, and don't create another objects for builders - //so no overhead comparing to using plain Payload(data, metadata) function - val payload = buildPayload { - data("Some data") - metadata(cm2) - // or - metadata(cm1) - // or - compositeMetadata { - add(routing) - add(tracing) - - add(WellKnownMimeType.ApplicationAvro, buildPacket { writeText("some custom metadata building") }) - //or - val raw = RawMetadata(WellKnownMimeType.ApplicationAvro, ByteReadPacket.Empty) - - add(raw) - } - } - - //reading - //property types are not needed, just for better online readability - val cm: CompositeMetadata = payload.metadata?.read(CompositeMetadata) ?: return - - val rmr = RawMetadata.reader(WellKnownMimeType.ApplicationAvro) - - - val rm: RoutingMetadata = cm.get(RoutingMetadata) - val tm: ZipkinTracingMetadata = cm.get(ZipkinTracingMetadata) - - //or - val rm1: RoutingMetadata = cm[RoutingMetadata] - val tm1: ZipkinTracingMetadata = cm[ZipkinTracingMetadata] - - //or - val rmNull: RoutingMetadata? = cm.getOrNull(RoutingMetadata) - val tmNull: ZipkinTracingMetadata? = cm.getOrNull(ZipkinTracingMetadata) - - //or - val rmList: List = cm.list(RoutingMetadata) //spec allow this - - //or - val c: Boolean = cm.contains(RoutingMetadata) - val c2: Boolean = RoutingMetadata in cm - - //or - - cm.entries.forEach { - if (it.hasMimeTypeOf(RoutingMetadata)) { - val rm2: RoutingMetadata = it.read(RoutingMetadata) - } - //or - val tm2: ZipkinTracingMetadata? = it.readOrNull(ZipkinTracingMetadata) - - - } - - //usage - - rm.tags.forEach { - println("tag: $it") - } - - tm.traceId - tm.traceIdHigh - - val span = "${tm.parentSpanId}-${tm.spanId}" - -} diff --git a/playground/src/commonMain/kotlin/Stub.kt b/playground/src/commonMain/kotlin/Stub.kt deleted file mode 100644 index a1c1c8ebe..000000000 --- a/playground/src/commonMain/kotlin/Stub.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.utils.io.core.* -import io.rsocket.kotlin.* -import io.rsocket.kotlin.payload.* -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* -import kotlin.random.* - -val rSocketAcceptor: ConnectionAcceptor = ConnectionAcceptor { - RSocketRequestHandler { - requestResponse { - delay(Random.nextLong(1000, 3000)) - throw RSocketError.Invalid(it.toString()) - } - requestStream { - flow { - coroutineScope { - while (isActive) { - emit(it) - } - } - } - } - } -} - -suspend fun RSocket.doSomething() { - // launch { rSocket.requestResponse(Payload(byteArrayOf(1, 1, 1), byteArrayOf(2, 2, 2))) } -// launch { rSocket.fireAndForget(Payload(byteArrayOf(1, 1, 1), byteArrayOf(2, 2, 2))) } -// launch { rSocket.metadataPush(byteArrayOf(1, 2, 3)) } - var i = 0 - requestStream( - buildPayload { - data(byteArrayOf(1, 1, 1)) - metadata(byteArrayOf(2, 2, 2)) - } - ).flowOn(PrefetchStrategy(10000, 0)).collect { - println(it.data.readBytes().contentToString()) - if (++i == 10000) error("") - } -// launch { rSocket.requestChannel(RequestingFlow { emit(Payload(byteArrayOf(3, 3, 3), byteArrayOf(4, 4, 4))) }).collect() } -} diff --git a/playground/src/commonMain/kotlin/TCP.kt b/playground/src/commonMain/kotlin/TCP.kt deleted file mode 100644 index 2b6db3344..000000000 --- a/playground/src/commonMain/kotlin/TCP.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.rsocket.kotlin.core.* -import io.rsocket.kotlin.payload.* -import io.rsocket.kotlin.transport.ktor.* - -suspend fun runTcpClient() { - val transport = TcpClientTransport("0.0.0.0", 4444) - RSocketConnector().connect(transport).doSomething() -} - -//to test nodejs tcp server -suspend fun testNodeJsServer() { - val transport = TcpClientTransport("127.0.0.1", 9000) - val client = RSocketConnector().connect(transport) - - val response = client.requestResponse(buildPayload { data("Hello from JVM") }) - println(response.data.readText()) -} diff --git a/playground/src/commonMain/kotlin/WS.kt b/playground/src/commonMain/kotlin/WS.kt deleted file mode 100644 index 6bf06201a..000000000 --- a/playground/src/commonMain/kotlin/WS.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.client.* -import io.ktor.client.engine.* -import io.ktor.client.features.websocket.* -import io.rsocket.kotlin.transport.ktor.client.* - -suspend fun runWSClient(engine: HttpClientEngineFactory<*>) { - val client = HttpClient(engine) { - install(WebSockets) - install(RSocketSupport) - } - - val rSocket = client.rSocket() - rSocket.doSomething() -} diff --git a/playground/src/commonMain/kotlin/streams.kt b/playground/src/commonMain/kotlin/streams.kt deleted file mode 100644 index 8e0a93a99..000000000 --- a/playground/src/commonMain/kotlin/streams.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.rsocket.kotlin.* -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.* -import kotlinx.coroutines.flow.* - -@ExperimentalStreamsApi -private suspend fun s() { - val flow = flow { - val strategy = currentCoroutineContext()[RequestStrategy]!!.provide() - var i = strategy.firstRequest() - println("INIT: $i") - var r = 0 - while (i > 0) { - emit(r++) - val n = strategy.nextRequest() - println("") - if (n > 0) i += n - i-- - } - } - - flow.flowOn(PrefetchStrategy(64, 16)).onEach { println(it) }.launchIn(GlobalScope) - - val ch = Channel() - - flow.flowOn(ChannelStrategy(ch)).onEach { println(it) }.launchIn(GlobalScope) - - delay(100) - ch.send(5) - delay(100) - ch.send(5) - delay(100) - ch.send(5) -} diff --git a/playground/src/jsMain/kotlin/WSApp.kt b/playground/src/jsMain/kotlin/WSApp.kt deleted file mode 100644 index 893b4820b..000000000 --- a/playground/src/jsMain/kotlin/WSApp.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.client.engine.js.* - -suspend fun main(): Unit = runWSClient(Js) diff --git a/playground/src/jsMain/resources/index.html b/playground/src/jsMain/resources/index.html deleted file mode 100644 index aaa9768d0..000000000 --- a/playground/src/jsMain/resources/index.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - Title - - - - - - diff --git a/playground/src/jvmMain/kotlin/TcpClientApp.kt b/playground/src/jvmMain/kotlin/TcpClientApp.kt deleted file mode 100644 index f1189def1..000000000 --- a/playground/src/jvmMain/kotlin/TcpClientApp.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -suspend fun main(): Unit = runTcpClient() - -//suspend fun main(): Unit = testNodeJsServer() diff --git a/playground/src/jvmMain/kotlin/TcpServerApp.kt b/playground/src/jvmMain/kotlin/TcpServerApp.kt deleted file mode 100644 index ec7ad96a0..000000000 --- a/playground/src/jvmMain/kotlin/TcpServerApp.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.rsocket.kotlin.core.* -import io.rsocket.kotlin.transport.ktor.* -import kotlinx.coroutines.* -import kotlin.coroutines.* - -suspend fun runTcpServer(dispatcher: CoroutineContext) { - val transport = TcpServerTransport("0.0.0.0", 4444) - RSocketServer().bindIn(CoroutineScope(dispatcher), transport, rSocketAcceptor).handlerJob.join() -} - -suspend fun main(): Unit = runTcpServer(Dispatchers.IO) diff --git a/playground/src/jvmMain/kotlin/WSClientApp.kt b/playground/src/jvmMain/kotlin/WSClientApp.kt deleted file mode 100644 index 5737b29b1..000000000 --- a/playground/src/jvmMain/kotlin/WSClientApp.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.client.engine.cio.* - -suspend fun main(): Unit = runWSClient(CIO) diff --git a/playground/src/jvmMain/kotlin/WSServerApp.kt b/playground/src/jvmMain/kotlin/WSServerApp.kt deleted file mode 100644 index 94de39cc4..000000000 --- a/playground/src/jvmMain/kotlin/WSServerApp.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.ktor.application.* -import io.ktor.routing.* -import io.ktor.server.cio.* -import io.ktor.server.engine.* -import io.rsocket.kotlin.transport.ktor.server.* - -fun main() { - embeddedServer(CIO) { - install(RSocketSupport) - routing { - rSocket(acceptor = rSocketAcceptor) - } - }.start(true) -} diff --git a/playground/src/nativeMain/kotlin/TcpApp.kt b/playground/src/nativeMain/kotlin/TcpApp.kt deleted file mode 100644 index 184844af7..000000000 --- a/playground/src/nativeMain/kotlin/TcpApp.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import kotlinx.coroutines.* - -fun main() { - runBlocking { - runTcpClient() - } -} - diff --git a/publish-check/build.gradle.kts b/publish-check/build.gradle.kts deleted file mode 100644 index 15889bcd8..000000000 --- a/publish-check/build.gradle.kts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -plugins { - kotlin("multiplatform") -} - -val publishCheckVersion: String by project - -kotlin { - //all targets depends on core and local transport - - jvm() //depends on ktor client and server - js(IR) { //depends on ktor client - browser() - nodejs() - } - - mingwX64() //depends only on common - val hostTargets = listOf(linuxX64(), macosX64()) - val iosTargets = listOf(iosArm32(), iosArm64(), iosX64()) - val tvosTargets = listOf(tvosArm64(), tvosX64()) - val watchosTargets = listOf(watchosArm32(), watchosArm64(), watchosX86()) - val nativeTargets = hostTargets + iosTargets + tvosTargets + watchosTargets //depends on ktor client - - sourceSets { - val commonMain by getting { - dependencies { - implementation("io.rsocket.kotlin:rsocket-core:$publishCheckVersion") - implementation("io.rsocket.kotlin:rsocket-transport-local:$publishCheckVersion") - - api(kotlin("test-common")) - api(kotlin("test-annotations-common")) - } - } - - val nonWinCommonMain by creating { - dependsOn(commonMain) - dependencies { - implementation("io.rsocket.kotlin:rsocket-transport-ktor:$publishCheckVersion") - } - } - - val clientMain by creating { - dependsOn(nonWinCommonMain) - dependencies { - implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:$publishCheckVersion") - } - } - - val jsMain by getting { - dependsOn(clientMain) - dependencies { - api(kotlin("test-js")) - } - } - - val jvmMain by getting { - dependsOn(clientMain) - dependencies { - implementation("io.rsocket.kotlin:rsocket-transport-ktor-server:$publishCheckVersion") - - api(kotlin("test-junit")) - } - } - - val nativeMain by creating { - dependsOn(clientMain) - } - - nativeTargets.forEach { - sourceSets["${it.name}Main"].dependsOn(nativeMain) - } - } -} diff --git a/publish-check/src/commonMain/kotlin/Stub.kt b/publish-check/src/commonMain/kotlin/Stub.kt deleted file mode 100644 index 89647d161..000000000 --- a/publish-check/src/commonMain/kotlin/Stub.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.rsocket.kotlin.* -import io.rsocket.kotlin.payload.* - -val rSocket = RSocketRequestHandler { - requestResponse { payload: Payload -> payload } -} diff --git a/publish-check/src/commonTest/kotlin/StubTest.kt b/publish-check/src/commonTest/kotlin/StubTest.kt deleted file mode 100644 index 5d109ea3e..000000000 --- a/publish-check/src/commonTest/kotlin/StubTest.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2015-2020 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. - * 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. - */ - -import io.rsocket.kotlin.payload.* -import io.rsocket.kotlin.* -import kotlin.test.* - -class StubTest { - @Test - fun test() { - assertTrue(rSocket.isActive) - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 207278e2d..329208834 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -58,7 +58,6 @@ gradleEnterprise { rootProject.name = "rsocket-kotlin" include("benchmarks") -include("playground") include("rsocket-core") include("rsocket-test") @@ -81,6 +80,3 @@ fun includeExample(name: String) { //includeExample("nodejs-tcp-transport") includeExample("interactions") includeExample("multiplatform-chat") - -val publishCheckVersion: String? by settings -if (publishCheckVersion != null) include("publish-check") From e3b98b873de70c923dfa60f1536f51156dba9e77 Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:26:47 +0300 Subject: [PATCH 4/7] enable version catalogs minor update of versions create convention plugins in buildSrc: * rsocket-build - basic configuration of any module * rsocket-build-js - configuration of JS target * rsocket-build-jvm - configuration of JVM target * rsocket-build-native - configuration of native targets * rsocket-build-multiplatform - configuration of all targets * rsocket-build-publish - configuration of maven-central/artifactory publication and singing * rsocket-build-library - base configuration for library module (publishing + explicitApi mode) --- buildSrc/build.gradle.kts | 12 + buildSrc/settings.gradle.kts | 20 ++ .../main/kotlin/rsocket-build-js.gradle.kts | 21 ++ .../main/kotlin/rsocket-build-jvm.gradle.kts | 11 + .../kotlin/rsocket-build-library.gradle.kts | 12 + .../rsocket-build-multiplatform.gradle.kts | 5 + .../kotlin/rsocket-build-native.gradle.kts | 47 ++++ .../kotlin/rsocket-build-publish.gradle.kts | 232 ++++++++++++++++++ .../src/main/kotlin/rsocket-build.gradle.kts | 34 +++ buildSrc/src/main/kotlin/util.kt | 35 +++ gradle/libs.versions.toml | 51 ++++ settings.gradle.kts | 3 + 12 files changed, 483 insertions(+) create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-js.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-jvm.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-library.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-multiplatform.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-native.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build-publish.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket-build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/util.kt create mode 100644 gradle/libs.versions.toml diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 000000000..f062efce5 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + `kotlin-dsl` +} +repositories { + mavenCentral() +} + +dependencies { + implementation(blibs.plugin.kotlin) + implementation(blibs.plugin.kotlinx.atomicfu) + implementation(blibs.plugin.jfrog.artifactory) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..521aa9337 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,20 @@ +enableFeaturePreview("VERSION_CATALOGS") +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + } + versionCatalogs { + create("blibs") { //not libs because of idea + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-js.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-js.gradle.kts new file mode 100644 index 000000000..d7c2c2670 --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-js.gradle.kts @@ -0,0 +1,21 @@ +kotlin { + js { + useCommonJs() + //configure running tests for JS + nodejs { + testTask { + useMocha { + timeout = "600s" + } + } + } + browser { + testTask { + useKarma { + useConfigDirectory(rootDir.resolve("js").resolve("karma.config.d")) + useChromeHeadless() + } + } + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-jvm.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-jvm.gradle.kts new file mode 100644 index 000000000..3b0ba7e3b --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-jvm.gradle.kts @@ -0,0 +1,11 @@ +kotlin { + jvm { + testRuns.all { + executionTask.configure { + // ActiveProcessorCount is used here, to make sure local setup is similar as on CI + // Github Actions linux runners have 2 cores + jvmArgs("-Xmx4g", "-XX:+UseParallelGC", "-XX:ActiveProcessorCount=2") + } + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-library.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-library.gradle.kts new file mode 100644 index 000000000..ba44f15a2 --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-library.gradle.kts @@ -0,0 +1,12 @@ +plugins { + id("rsocket-build") + id("rsocket-build-publish") +} + +kotlin { + explicitApi() + //TODO all warnings as errors + sourceSets["commonTest"].dependencies { + implementation(project(":rsocket-test")) + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-multiplatform.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-multiplatform.gradle.kts new file mode 100644 index 000000000..852a130a4 --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-multiplatform.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("rsocket-build-js") + id("rsocket-build-jvm") + id("rsocket-build-native") +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-native.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-native.gradle.kts new file mode 100644 index 000000000..02825a41e --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-native.gradle.kts @@ -0,0 +1,47 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.* + +kotlin { + linuxX64() + macosX64() + //ktor-network doesn't support windows + if (!project.name.startsWith("rsocket-transport-ktor")) mingwX64() //TODO + + iosArm32() + iosArm64() + iosX64() + + tvosArm64() + tvosX64() + + watchosArm32() + watchosArm64() + watchosX86() + + + val nativeMain by sourceSets.creating { + dependsOn(sourceSets["commonMain"]) + } + val nativeTest by sourceSets.creating { + dependsOn(sourceSets["commonTest"]) + } + targets.all { + if (this is KotlinNativeTarget) { + sourceSets["${name}Main"].dependsOn(nativeMain) + sourceSets["${name}Test"].dependsOn(nativeTest) + + if (this is KotlinNativeTargetWithTests<*>) { + + //run tests on release + mimalloc to reduce tests execution time + //compilation is slower in that mode, but work with buffers is much faster + //TODO do another check? + if (System.getenv("CI") == "true") { + binaries.test(listOf(RELEASE)) + testRuns.all { setExecutionSourceFrom(binaries.getTest(RELEASE)) } + compilations.all { + kotlinOptions.freeCompilerArgs += "-Xallocator=mimalloc" + } + } + } + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build-publish.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build-publish.gradle.kts new file mode 100644 index 000000000..a9be2a8a0 --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build-publish.gradle.kts @@ -0,0 +1,232 @@ +import groovy.util.* +import org.gradle.api.publish.maven.internal.artifact.* +import org.jetbrains.kotlin.konan.target.* +import org.jfrog.gradle.plugin.artifactory.dsl.* + +//TODO cleanup publication + +plugins { + signing + `maven-publish` + com.jfrog.artifactory +} + +val Project.publicationNames: Array + get() { + val publishing: PublishingExtension by extensions + val all = publishing.publications.names + //publish js, jvm, metadata, linuxX64 and kotlinMultiplatform only once + return when { + HostManager.hostIsLinux -> all + else -> all - "js" - "jvm" - "metadata" - "kotlinMultiplatform" - "linuxX64" + }.toTypedArray() + } + +fun publishPlatformArtifactsInRootModule( + platformPublication: MavenPublication, + kotlinMultiplatformPublication: MavenPublication +) { + lateinit var platformXml: XmlProvider + + platformPublication.pom.withXml { platformXml = this } + + kotlinMultiplatformPublication.apply { + pom.withXml { + val root = asNode() + // Remove the original content and add the content from the platform POM: + root.children().toList().forEach { root.remove(it as Node) } + platformXml.asNode().children() + .forEach { root.append(it as Node) } + + // Adjust the self artifact ID, as it should match the root module's coordinates: + ((root.get("artifactId") as NodeList)[0] as Node).setValue(artifactId) + + // Set packaging to POM to indicate that there's no artifact: + root.appendNode("packaging", "pom") + + // Remove the original platform dependencies and add a single dependency on the platform module: + val dependencies = (root.get("dependencies") as NodeList)[0] as Node + dependencies.children().toList() + .forEach { dependencies.remove(it as Node) } + val singleDependency = dependencies.appendNode("dependency") + singleDependency.appendNode( + "groupId", + platformPublication.groupId + ) + singleDependency.appendNode( + "artifactId", + platformPublication.artifactId + ) + singleDependency.appendNode( + "version", + platformPublication.version + ) + singleDependency.appendNode("scope", "compile") + } + } + + tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" } + .configureEach { + dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) + } + +} + +//publication +afterEvaluate { + + val versionSuffix: String? by project + if (versionSuffix != null) { + project.version = project.version.toString() + versionSuffix + } + + task("javadocJar") { + archiveClassifier.set("javadoc") + } + + tasks.withType { + dependsOn("javadocJar") + } + + kotlin { + targets.all { + mavenPublication { + pom { + name.set(project.name) + description.set(project.description) + url.set("http://rsocket.io") + + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + developers { + developer { + id.set("whyoleg") + name.set("Oleg Yukhnevich") + email.set("whyoleg@gmail.com") + } + developer { + id.set("OlegDokuka") + name.set("Oleh Dokuka") + email.set("oleh.dokuka@icloud.com") + } + } + scm { + connection.set("https://github.com/rsocket/rsocket-kotlin.git") + developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git") + url.set("https://github.com/rsocket/rsocket-kotlin") + } + } + } + } + } + + tasks.withType { + dependsOn(tasks.withType()) + } + + tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach { + dependsOn(tasks["generatePomFileForJvmPublication"]) + } +} + +val bintrayUser: String? by project +val bintrayKey: String? by project +if (bintrayUser != null && bintrayKey != null) { + //configure artifactory + artifactory { + setContextUrl("https://oss.jfrog.org") + + publish(delegateClosureOf { + repository(delegateClosureOf { + setProperty("repoKey", "oss-snapshot-local") + setProperty("username", bintrayUser) + setProperty("password", bintrayKey) + setProperty("maven", true) + }) + println("Artifactory: ${publicationNames.contentToString()}") + defaults(delegateClosureOf { + invokeMethod("publications", publicationNames) + }) + }) + + val buildNumber: String? by project + + if (buildNumber != null) { + clientConfig.info.buildNumber = buildNumber + } + } +} + +//configure maven central +val sonatypeUsername: String? by project +val sonatypePassword: String? by project +if (sonatypeUsername != null && sonatypePassword != null) { + afterEvaluate { + publishing { + repositories { + maven { + name = "sonatype" + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") + credentials { + username = sonatypeUsername + password = sonatypePassword + } + } + } + + publications.filterIsInstance().forEach { + // add empty javadocs + if (name != "kotlinMultiplatform") { + it.artifact(tasks["javadocJar"]) + } + + when (val type = it.name) { + "kotlinMultiplatform" -> { + // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with + // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too + it.artifactId = project.name + publishPlatformArtifactsInRootModule( + publications["jvm"] as MavenPublication, + it + ) + } + else -> it.artifactId = "${project.name}-$type" + } + } + } + signing { + //requiring signature if there is a publish task that is not to MavenLocal + isRequired = gradle.taskGraph.allTasks.any { + it.name.toLowerCase().contains("publish") && !it.name.contains("MavenLocal") + } + + val signingKey: String? by project + val signingPassword: String? by project + + useInMemoryPgpKeys(signingKey, signingPassword) + val names = publicationNames + val publishing: PublishingExtension by project.extensions + beforeEvaluate { + publishing.publications + .filterIsInstance() + .filter { it.name in names } + .forEach { publication -> + val moduleFile = buildDir.resolve("publications/${publication.name}/module.json") + if (moduleFile.exists()) { + publication.artifact(object : FileBasedMavenArtifact(moduleFile) { + override fun getDefaultExtension() = "module" + }) + } + } + } + afterEvaluate { + sign(*publishing.publications.toTypedArray()) + } + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket-build.gradle.kts b/buildSrc/src/main/kotlin/rsocket-build.gradle.kts new file mode 100644 index 000000000..4f8ae2d0d --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket-build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + `kotlin-multiplatform` +} + +kotlin { + sourceSets.all { + languageSettings.apply { + progressiveMode = true + languageVersion = "1.5" + apiVersion = "1.5" + + useExperimentalAnnotation("kotlin.RequiresOptIn") + + if (name.contains("test", ignoreCase = true)) testOptIn() + } + } +} + +tasks.whenTaskAdded { + if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") } +} + +//workaround for https://youtrack.jetbrains.com/issue/KT-44884 +configurations.matching { !it.name.startsWith("kotlinCompilerPluginClasspath") }.all { + resolutionStrategy.eachDependency { + val version = requested.version + if (requested.group == "org.jetbrains.kotlinx" && + requested.name.startsWith("kotlinx-coroutines") && + version != null && !version.contains("native-mt") + ) { + useVersion("$version-native-mt") + } + } +} diff --git a/buildSrc/src/main/kotlin/util.kt b/buildSrc/src/main/kotlin/util.kt new file mode 100644 index 000000000..0b1b1856a --- /dev/null +++ b/buildSrc/src/main/kotlin/util.kt @@ -0,0 +1,35 @@ +import org.gradle.api.* +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.* +import org.jetbrains.kotlin.gradle.plugin.* + +fun KotlinMultiplatformExtension.testOptIn() { + sourceSets.all { + languageSettings.testOptIn() + } +} + +fun LanguageSettingsBuilder.testOptIn() { + useExperimentalAnnotation("kotlin.time.ExperimentalTime") + useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") + + useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.ObsoleteCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.FlowPreview") + useExperimentalAnnotation("kotlinx.coroutines.DelicateCoroutinesApi") + + useExperimentalAnnotation("io.ktor.util.InternalAPI") + useExperimentalAnnotation("io.ktor.utils.io.core.internal.DangerousInternalIoApi") + + useExperimentalAnnotation("io.rsocket.kotlin.TransportApi") + useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalMetadataApi") + useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalStreamsApi") + useExperimentalAnnotation("io.rsocket.kotlin.RSocketLoggingApi") +} + +fun Project.kotlin(action: KotlinMultiplatformExtension.() -> Unit) { + plugins.withId("org.jetbrains.kotlin.multiplatform") { + extensions.configure(action) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..27b7a16aa --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,51 @@ +[versions] +kotlin = "1.5.21" +ktor = "1.6.2" +kotlinx-coroutines = "1.5.1-native-mt" +kotlinx-atomicfu = "0.16.2" +kotlinx-serialization = "1.2.2" +kotlinx-benchmark = "0.3.1" +jfrog-artifactory = "4.24.12" +turbine = "0.6.0" +updates = "0.39.0" +rsocket-java = "1.1.1" + +[libraries] + +plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +plugin-kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "kotlinx-atomicfu" } +plugin-jfrog-artifactory = { module = "org.jfrog.buildinfo:build-info-extractor-gradle", version.ref = "jfrog-artifactory" } + +ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor" } +ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor" } +ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" } +ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor" } +ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" } +ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" } +ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" } +ktor-server = { module = "io.ktor:ktor-server", version.ref = "ktor" } +ktor-server-websockets = { module = "io.ktor:ktor-websockets", version.ref = "ktor" } +ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor" } +ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor" } +ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor" } + +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-reactor = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-reactor", version.ref = "kotlinx-coroutines" } + +kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" } +kotlinx-serialization-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "kotlinx-serialization" } + +kotlinx-benchmark = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" } + +kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinx-atomicfu" } + +rsocket-java-core = { module = 'io.rsocket:rsocket-core', version.ref = "rsocket-java" } +rsocket-java-transport-local = { module = 'io.rsocket:rsocket-transport-local', version.ref = "rsocket-java" } + +turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } + +[plugins] +updates = { id = "com.github.ben-manes.versions", version.ref = "updates" } +kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark" } +kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 329208834..d64208aa8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,6 +14,9 @@ * limitations under the License. */ +enableFeaturePreview("VERSION_CATALOGS") +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + pluginManagement { repositories { gradlePluginPortal() From 9c79f40f816ee91c2b2df2af884a211aa845c5c3 Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:32:32 +0300 Subject: [PATCH 5/7] migrate modules to use version catalogs, typesafe project accessors and build convention plugins --- benchmarks/build.gradle.kts | 22 +- build.gradle.kts | 413 +----------------- examples/interactions/build.gradle.kts | 9 +- examples/multiplatform-chat/build.gradle.kts | 25 +- gradle.properties | 14 - rsocket-core/build.gradle.kts | 22 +- rsocket-test/build.gradle.kts | 25 +- .../rsocket-test-server/build.gradle.kts | 15 +- rsocket-transport-ktor/build.gradle.kts | 42 +- .../build.gradle.kts | 19 +- .../build.gradle.kts | 17 +- rsocket-transport-local/build.gradle.kts | 13 +- settings.gradle.kts | 19 +- 13 files changed, 86 insertions(+), 569 deletions(-) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 51c55826a..ee9d1c1c1 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -17,25 +17,21 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.* plugins { - kotlin("multiplatform") - id("org.jetbrains.kotlinx.benchmark") - kotlin("plugin.allopen") + `kotlin-multiplatform` + alias(libs.plugins.kotlin.allopen) + alias(libs.plugins.kotlinx.benchmark) } -val rsocketJavaVersion: String by rootProject -val kotlinxCoroutinesVersion: String by rootProject -val kotlinxBenchmarkVersion: String by rootProject - kotlin { val jvm = jvm() //common jvm source set val kotlinJvm = jvm("kotlin") //kotlin benchmark val javaJvm = jvm("java") sourceSets { - val commonMain by getting { + commonMain { dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:$kotlinxBenchmarkVersion") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") + implementation(libs.kotlinx.benchmark) + implementation(libs.kotlinx.coroutines.core) } } @@ -52,9 +48,9 @@ kotlin { val javaMain by getting { dependsOn(jvmMain) dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion") - implementation("io.rsocket:rsocket-core:$rsocketJavaVersion") - implementation("io.rsocket:rsocket-transport-local:$rsocketJavaVersion") + implementation(libs.kotlinx.coroutines.reactor) + implementation(libs.rsocket.java.core) + implementation(libs.rsocket.java.transport.local) } } } diff --git a/build.gradle.kts b/build.gradle.kts index 6447c1dd0..3f51cf3d6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,422 +14,17 @@ * limitations under the License. */ -import groovy.util.* -import org.gradle.api.publish.maven.internal.artifact.* -import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.plugin.mpp.* -import org.jetbrains.kotlin.konan.target.* -import org.jfrog.gradle.plugin.artifactory.dsl.* - +//needed for atomicfu buildscript { repositories { mavenCentral() } - val kotlinVersion: String by rootProject - val kotlinxAtomicfuVersion: String by rootProject - dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$kotlinxAtomicfuVersion") + classpath(libs.plugin.kotlin) + classpath(libs.plugin.kotlinx.atomicfu) } } -val kotlinxAtomicfuVersion: String by rootProject - plugins { - id("com.github.ben-manes.versions") - - //needed to add classpath to script - id("com.jfrog.artifactory") apply false -} - -val Project.publicationNames: Array - get() { - val publishing: PublishingExtension by extensions - val all = publishing.publications.names - //publish js, jvm, metadata, linuxX64 and kotlinMultiplatform only once - return when { - HostManager.hostIsLinux -> all - else -> all - "js" - "jvm" - "metadata" - "kotlinMultiplatform" - "linuxX64" - }.toTypedArray() - } - -subprojects { - tasks.whenTaskAdded { - if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") } - } - - plugins.withId("org.jetbrains.kotlin.multiplatform") { - //targets configuration - extensions.configure { - val isAutoConfigurable = project.name.startsWith("rsocket") //manual config of others - val jvmOnly = - project.name == "rsocket-transport-ktor-server" || //server is jvm only - project.name == "rsocket-test-server" - //windows target isn't supported by ktor-network - val supportMingw = project.name != "rsocket-transport-ktor" && project.name != "rsocket-transport-ktor-client" - - - if (!isAutoConfigurable) return@configure - - jvm { - testRuns.all { - executionTask.configure { - // ActiveProcessorCount is used here, to make sure local setup is similar as on CI - // Github Actions linux runners have 2 cores - jvmArgs("-Xmx4g", "-XX:+UseParallelGC", "-XX:ActiveProcessorCount=2") - } - } - } - - if (jvmOnly) return@configure - - js { - useCommonJs() - //configure running tests for JS - nodejs { - testTask { - useMocha { - timeout = "600s" - } - } - } - browser { - testTask { - useKarma { - useConfigDirectory(rootDir.resolve("js").resolve("karma.config.d")) - useChromeHeadless() - } - } - } - } - - //native targets configuration - val hostTargets = listOfNotNull(linuxX64(), macosX64(), if (supportMingw) mingwX64() else null) - - val iosTargets = listOf(iosArm32(), iosArm64(), iosX64()) - val tvosTargets = listOf(tvosArm64(), tvosX64()) - val watchosTargets = listOf(watchosArm32(), watchosArm64(), watchosX86()) - val nativeTargets = hostTargets + iosTargets + tvosTargets + watchosTargets - - val nativeMain by sourceSets.creating { - dependsOn(sourceSets["commonMain"]) - } - val nativeTest by sourceSets.creating { - dependsOn(sourceSets["commonTest"]) - } - - nativeTargets.forEach { - sourceSets["${it.name}Main"].dependsOn(nativeMain) - sourceSets["${it.name}Test"].dependsOn(nativeTest) - } - - //run tests on release + mimalloc to reduce tests execution time - //compilation is slower in that mode, but work with buffers is much faster - if (System.getenv("CI") == "true") { - targets.all { - if (this is KotlinNativeTargetWithTests<*>) { - binaries.test(listOf(RELEASE)) - testRuns.all { setExecutionSourceFrom(binaries.getTest(RELEASE)) } - compilations.all { - kotlinOptions.freeCompilerArgs += "-Xallocator=mimalloc" - } - } - } - } - } - - //common configuration - extensions.configure { - val isTestProject = project.name == "rsocket-test" || project.name == "rsocket-test-server" - val isLibProject = project.name.startsWith("rsocket") - val isPlaygroundProject = project.name == "playground" - val isExampleProject = "examples" in project.path - - sourceSets.all { - languageSettings.apply { - progressiveMode = true - languageVersion = "1.5" - apiVersion = "1.5" - - useExperimentalAnnotation("kotlin.RequiresOptIn") - - if (name.contains("test", ignoreCase = true) || isTestProject || isPlaygroundProject) { - useExperimentalAnnotation("kotlin.time.ExperimentalTime") - useExperimentalAnnotation("kotlin.ExperimentalStdlibApi") - - useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") - useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi") - useExperimentalAnnotation("kotlinx.coroutines.ObsoleteCoroutinesApi") - useExperimentalAnnotation("kotlinx.coroutines.FlowPreview") - useExperimentalAnnotation("kotlinx.coroutines.DelicateCoroutinesApi") - - useExperimentalAnnotation("io.ktor.util.InternalAPI") - useExperimentalAnnotation("io.ktor.utils.io.core.internal.DangerousInternalIoApi") - - useExperimentalAnnotation("io.rsocket.kotlin.TransportApi") - useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalMetadataApi") - useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalStreamsApi") - useExperimentalAnnotation("io.rsocket.kotlin.RSocketLoggingApi") - } - } - } - - if (isLibProject && !isTestProject) { - explicitApi() - sourceSets["commonTest"].dependencies { - implementation(project(":rsocket-test")) - } - } - - //fix atomicfu for examples and playground - if (isExampleProject || isPlaygroundProject) { - sourceSets["commonMain"].dependencies { - implementation("org.jetbrains.kotlinx:atomicfu:$kotlinxAtomicfuVersion") - } - } - } - } - - //workaround for https://youtrack.jetbrains.com/issue/KT-44884 - configurations.matching { !it.name.startsWith("kotlinCompilerPluginClasspath") }.all { - resolutionStrategy.eachDependency { - val version = requested.version - if (requested.group == "org.jetbrains.kotlinx" && - requested.name.startsWith("kotlinx-coroutines") && - version != null && !version.contains("native-mt") - ) { - useVersion("$version-native-mt") - } - } - } -} - -fun publishPlatformArtifactsInRootModule( - platformPublication: MavenPublication, - kotlinMultiplatformPublication: MavenPublication -) { - lateinit var platformXml: XmlProvider - - platformPublication.pom.withXml { platformXml = this } - - kotlinMultiplatformPublication.apply { - pom.withXml { - val root = asNode() - // Remove the original content and add the content from the platform POM: - root.children().toList().forEach { root.remove(it as Node) } - platformXml.asNode().children() - .forEach { root.append(it as Node) } - - // Adjust the self artifact ID, as it should match the root module's coordinates: - ((root.get("artifactId") as NodeList)[0] as Node).setValue(artifactId) - - // Set packaging to POM to indicate that there's no artifact: - root.appendNode("packaging", "pom") - - // Remove the original platform dependencies and add a single dependency on the platform module: - val dependencies = (root.get("dependencies") as NodeList)[0] as Node - dependencies.children().toList() - .forEach { dependencies.remove(it as Node) } - val singleDependency = dependencies.appendNode("dependency") - singleDependency.appendNode( - "groupId", - platformPublication.groupId - ) - singleDependency.appendNode( - "artifactId", - platformPublication.artifactId - ) - singleDependency.appendNode( - "version", - platformPublication.version - ) - singleDependency.appendNode("scope", "compile") - } - } - - tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" } - .configureEach { - dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) - } - -} - -//publication -subprojects { - afterEvaluate { - - val versionSuffix: String? by project - if (versionSuffix != null) { - project.version = project.version.toString() + versionSuffix - } - - task("javadocJar") { - archiveClassifier.set("javadoc") - } - - tasks.withType { - dependsOn("javadocJar") - } - - plugins.withId("org.jetbrains.kotlin.multiplatform") { - extensions.configure { - targets.all { - mavenPublication { - pom { - name.set(project.name) - description.set(project.description) - url.set("http://rsocket.io") - - licenses { - license { - name.set("The Apache Software License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - distribution.set("repo") - } - } - developers { - developer { - id.set("whyoleg") - name.set("Oleg Yukhnevich") - email.set("whyoleg@gmail.com") - } - developer { - id.set("OlegDokuka") - name.set("Oleh Dokuka") - email.set("oleh.dokuka@icloud.com") - } - } - scm { - connection.set("https://github.com/rsocket/rsocket-kotlin.git") - developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git") - url.set("https://github.com/rsocket/rsocket-kotlin") - } - } - } - } - } - } - - tasks.withType { - dependsOn(tasks.withType()) - } - - tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach { - dependsOn(tasks["generatePomFileForJvmPublication"]) - } - } -} - -val bintrayUser: String? by project -val bintrayKey: String? by project -if (bintrayUser != null && bintrayKey != null) { - - //configure artifactory - subprojects { - plugins.withId("com.jfrog.artifactory") { - configure { - setContextUrl("https://oss.jfrog.org") - - publish(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "oss-snapshot-local") - setProperty("username", bintrayUser) - setProperty("password", bintrayKey) - setProperty("maven", true) - }) - println("Artifactory: ${publicationNames.contentToString()}") - defaults(delegateClosureOf { - invokeMethod("publications", publicationNames) - }) - }) - - val buildNumber: String? by project - - if (buildNumber != null) { - clientConfig.info.buildNumber = buildNumber - } - } - } - } -} - -//configure bintray / maven central -val sonatypeUsername: String? by project -val sonatypePassword: String? by project -if (sonatypeUsername != null && sonatypePassword != null) { - subprojects { - afterEvaluate { - plugins.withId("maven-publish") { - plugins.withId("signing") { - extensions.configure { - //requiring signature if there is a publish task that is not to MavenLocal - isRequired = gradle.taskGraph.allTasks.any { - it.name.toLowerCase() - .contains("publish") && !it.name.contains("MavenLocal") - } - - val signingKey: String? by project - val signingPassword: String? by project - - useInMemoryPgpKeys(signingKey, signingPassword) - val names = publicationNames - val publishing: PublishingExtension by project.extensions - beforeEvaluate { - publishing.publications - .filterIsInstance() - .filter { it.name in names } - .forEach { publication -> - val moduleFile = - buildDir.resolve("publications/${publication.name}/module.json") - if (moduleFile.exists()) { - publication.artifact(object : - FileBasedMavenArtifact(moduleFile) { - override fun getDefaultExtension() = "module" - }) - } - } - } - afterEvaluate { - sign(*publishing.publications.toTypedArray()) - } - } - - extensions.configure { - repositories { - maven { - name = "sonatype" - url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") - credentials { - username = sonatypeUsername - password = sonatypePassword - } - } - } - - publications.filterIsInstance().forEach { - // add empty javadocs - if (name != "kotlinMultiplatform") { - it.artifact(tasks["javadocJar"]) - } - - val type = it.name - when (type) { - "kotlinMultiplatform" -> { - // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with - // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too - it.artifactId = project.name - publishPlatformArtifactsInRootModule( - publications["jvm"] as MavenPublication, - it - ) - } - else -> it.artifactId = "${project.name}-$type" - } - } - } - } - } - } - } + alias(libs.plugins.updates) } diff --git a/examples/interactions/build.gradle.kts b/examples/interactions/build.gradle.kts index ba87d6db7..7ce7cbc92 100644 --- a/examples/interactions/build.gradle.kts +++ b/examples/interactions/build.gradle.kts @@ -15,17 +15,18 @@ */ plugins { - kotlin("multiplatform") + `kotlin-multiplatform` + `kotlinx-atomicfu` } kotlin { jvm() sourceSets { - val commonMain by getting { + commonMain { dependencies { - implementation(project(":rsocket-core")) - implementation(project(":rsocket-transport-local")) + implementation(projects.rsocketCore) + implementation(projects.rsocketTransportLocal) } } } diff --git a/examples/multiplatform-chat/build.gradle.kts b/examples/multiplatform-chat/build.gradle.kts index e229c3c1e..caf10760b 100644 --- a/examples/multiplatform-chat/build.gradle.kts +++ b/examples/multiplatform-chat/build.gradle.kts @@ -17,14 +17,11 @@ import org.jetbrains.kotlin.konan.target.* plugins { - kotlin("multiplatform") - kotlin("plugin.serialization") - id("kotlinx-atomicfu") + `kotlin-multiplatform` + `kotlinx-atomicfu` + alias(libs.plugins.kotlin.serialization) } -val ktorVersion: String by rootProject -val kotlinxSerializationVersion: String by rootProject - kotlin { jvm("serverJvm") jvm("clientJvm") @@ -50,38 +47,34 @@ kotlin { sourceSets { val commonMain by getting { dependencies { - implementation(project(":rsocket-core")) - - implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinxSerializationVersion") + implementation(projects.rsocketCore) + implementation(libs.kotlinx.serialization.protobuf) } } val clientMain by creating { dependsOn(commonMain) dependencies { - implementation(project(":rsocket-transport-ktor-client")) + implementation(projects.rsocketTransportKtorClient) } } val serverJvmMain by getting { dependencies { - implementation(project(":rsocket-transport-ktor-server")) - implementation("io.ktor:ktor-server-cio:$ktorVersion") + implementation(projects.rsocketTransportKtorServer) + implementation(libs.ktor.server.cio) } } val clientJvmMain by getting { dependsOn(clientMain) dependencies { - implementation("io.ktor:ktor-client-cio:$ktorVersion") + implementation(libs.ktor.client.cio) } } val clientJsMain by getting { dependsOn(clientMain) - dependencies { - implementation("io.ktor:ktor-client-core:$ktorVersion") - } } if (!HostManager.hostIsMingw) { diff --git a/gradle.properties b/gradle.properties index e01243605..1ec376f72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,20 +18,6 @@ group=io.rsocket.kotlin version=0.13.1 -#Versions -kotlinVersion=1.5.21 -ktorVersion=1.6.1 -kotlinxCoroutinesVersion=1.5.1-native-mt -kotlinxAtomicfuVersion=0.16.2 -kotlinxSerializationVersion=1.2.2 -kotlinxBenchmarkVersion=0.3.1 -kotlinxNodejsVersion=0.0.7 -rsocketJavaVersion=1.1.1 -turbineVersion=0.5.2 -artifactoryVersion=4.24.12 -versionUpdatesVersion=0.39.0 -gradleEnterpriseVersion=3.4.1 - #Kotlin #kotlin.code.style=official kotlin.caching.enabled=true diff --git a/rsocket-core/build.gradle.kts b/rsocket-core/build.gradle.kts index 0cf50c201..9bec3beeb 100644 --- a/rsocket-core/build.gradle.kts +++ b/rsocket-core/build.gradle.kts @@ -15,28 +15,22 @@ */ plugins { - kotlin("multiplatform") - id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + `rsocket-build-library` + `rsocket-build-multiplatform` + `kotlinx-atomicfu` } -val ktorVersion: String by rootProject -val kotlinxCoroutinesVersion: String by rootProject - kotlin { sourceSets { - val commonMain by getting { + commonMain { dependencies { - api("io.ktor:ktor-io:$ktorVersion") - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") + api(libs.ktor.io) + api(libs.kotlinx.coroutines.core) } } - val commonTest by getting { + commonTest { dependencies { - implementation(project(":rsocket-transport-local")) + implementation(projects.rsocketTransportLocal) } } } diff --git a/rsocket-test/build.gradle.kts b/rsocket-test/build.gradle.kts index 19b2a9587..90bcc813f 100644 --- a/rsocket-test/build.gradle.kts +++ b/rsocket-test/build.gradle.kts @@ -15,32 +15,29 @@ */ plugins { - kotlin("multiplatform") - id("kotlinx-atomicfu") + `rsocket-build` + `rsocket-build-multiplatform` + `kotlinx-atomicfu` } -val ktorVersion: String by rootProject -val kotlinxCoroutinesVersion: String by rootProject -val turbineVersion: String by rootProject - kotlin { + testOptIn() sourceSets { - val commonMain by getting { + commonMain { dependencies { api(kotlin("test")) - api(project(":rsocket-core")) - - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") - api("io.ktor:ktor-utils:$ktorVersion") - api("app.cash.turbine:turbine:$turbineVersion") + api(projects.rsocketCore) + api(libs.kotlinx.coroutines.core) + api(libs.ktor.utils) + api(libs.turbine) } } - val jvmMain by getting { + jvmMain { dependencies { api(kotlin("test-junit")) } } - val jsMain by getting { + jsMain { dependencies { api(kotlin("test-js")) } diff --git a/rsocket-test/rsocket-test-server/build.gradle.kts b/rsocket-test/rsocket-test-server/build.gradle.kts index 5fd31fcba..e6a9c039e 100644 --- a/rsocket-test/rsocket-test-server/build.gradle.kts +++ b/rsocket-test/rsocket-test-server/build.gradle.kts @@ -19,19 +19,18 @@ import java.io.* import java.net.* plugins { - kotlin("multiplatform") + `rsocket-build` + `rsocket-build-jvm` } -val ktorVersion: String by rootProject - kotlin { + testOptIn() sourceSets { - val jvmMain by getting { + jvmMain { dependencies { - implementation(project(":rsocket-test")) - implementation(project(":rsocket-transport-ktor-server")) - - implementation("io.ktor:ktor-server-cio:$ktorVersion") + implementation(projects.rsocketTest) + implementation(projects.rsocketTransportKtorServer) + implementation(libs.ktor.server.cio) } } } diff --git a/rsocket-transport-ktor/build.gradle.kts b/rsocket-transport-ktor/build.gradle.kts index 8c289a3e6..429d79ef0 100644 --- a/rsocket-transport-ktor/build.gradle.kts +++ b/rsocket-transport-ktor/build.gradle.kts @@ -15,43 +15,33 @@ */ plugins { - kotlin("multiplatform") - - signing - `maven-publish` - id("com.jfrog.artifactory") + `rsocket-build-library` + `rsocket-build-multiplatform` } -val ktorVersion: String by rootProject -val kotlinxAtomicfuVersion: String by rootProject - kotlin { sourceSets { - val commonMain by getting { + commonMain { dependencies { - api(project(":rsocket-core")) - - api("io.ktor:ktor-network:$ktorVersion") - api("io.ktor:ktor-http-cio:$ktorVersion") + api(projects.rsocketCore) + api(libs.ktor.network) + api(libs.ktor.http.cio) } } - val commonTest by getting { + commonTest { dependencies { - implementation(project(":rsocket-transport-ktor-client")) - - implementation("org.jetbrains.kotlinx:atomicfu:$kotlinxAtomicfuVersion") + implementation(projects.rsocketTransportKtorClient) + implementation(libs.kotlinx.atomicfu) } } - val jvmTest by getting { + jvmTest { dependencies { - implementation(project(":rsocket-transport-ktor-server")) - - implementation("io.ktor:ktor-client-cio:$ktorVersion") - implementation("io.ktor:ktor-client-okhttp:$ktorVersion") - - implementation("io.ktor:ktor-server-cio:$ktorVersion") - implementation("io.ktor:ktor-server-netty:$ktorVersion") - implementation("io.ktor:ktor-server-jetty:$ktorVersion") + implementation(projects.rsocketTransportKtorServer) + implementation(libs.ktor.client.cio) + implementation(libs.ktor.client.okhttp) + implementation(libs.ktor.server.cio) + implementation(libs.ktor.server.netty) + implementation(libs.ktor.server.jetty) } } } diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts b/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts index f51b48ba7..fb5e0a2bb 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts +++ b/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts @@ -15,26 +15,19 @@ */ plugins { - kotlin("multiplatform") - - signing - `maven-publish` - id("com.jfrog.artifactory") + `rsocket-build-library` + `rsocket-build-multiplatform` } -val ktorVersion: String by rootProject - kotlin { sourceSets { - val commonMain by getting { + commonMain { dependencies { - api(project(":rsocket-core")) - api(project(":rsocket-transport-ktor")) - - api("io.ktor:ktor-client-core:$ktorVersion") + api(projects.rsocketTransportKtor) + api(libs.ktor.client.core) } } } } -description = "Ktor installments for RSocket client transport" \ No newline at end of file +description = "Ktor installments for RSocket client transport" diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts b/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts index 9f92b24f7..14d39b425 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts +++ b/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts @@ -15,24 +15,17 @@ */ plugins { - kotlin("multiplatform") - - signing - `maven-publish` - id("com.jfrog.artifactory") + `rsocket-build-library` + `rsocket-build-jvm` } -val ktorVersion: String by rootProject - kotlin { sourceSets { val commonMain by getting { dependencies { - api(project(":rsocket-core")) - api(project(":rsocket-transport-ktor")) - - api("io.ktor:ktor-server:$ktorVersion") - api("io.ktor:ktor-websockets:$ktorVersion") + api(projects.rsocketTransportKtor) + api(libs.ktor.server) + api(libs.ktor.server.websockets) } } } diff --git a/rsocket-transport-local/build.gradle.kts b/rsocket-transport-local/build.gradle.kts index 161799e99..62a1e7cee 100644 --- a/rsocket-transport-local/build.gradle.kts +++ b/rsocket-transport-local/build.gradle.kts @@ -15,21 +15,18 @@ */ plugins { - kotlin("multiplatform") - - signing - `maven-publish` - id("com.jfrog.artifactory") + `rsocket-build-library` + `rsocket-build-multiplatform` } kotlin { sourceSets { - val commonMain by getting { + commonMain { dependencies { - api(project(":rsocket-core")) + api(projects.rsocketCore) } } } } -description = "Local RSocket transport implementation" \ No newline at end of file +description = "Local RSocket transport implementation" diff --git a/settings.gradle.kts b/settings.gradle.kts index d64208aa8..e19966e6d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -22,23 +22,6 @@ pluginManagement { gradlePluginPortal() mavenCentral() } - - val kotlinVersion: String by settings - val artifactoryVersion: String by settings - val versionUpdatesVersion: String by settings - val gradleEnterpriseVersion: String by settings - val kotlinxBenchmarkVersion: String by settings - - plugins { - kotlin("plugin.allopen") version kotlinVersion - kotlin("plugin.serialization") version kotlinVersion - - id("org.jetbrains.kotlinx.benchmark") version kotlinxBenchmarkVersion - - id("com.jfrog.artifactory") version artifactoryVersion - id("com.github.ben-manes.versions") version versionUpdatesVersion - id("com.gradle.enterprise") version gradleEnterpriseVersion - } } dependencyResolutionManagement { @@ -48,7 +31,7 @@ dependencyResolutionManagement { } plugins { - id("com.gradle.enterprise") + id("com.gradle.enterprise") version "3.4.1" } gradleEnterprise { From 273fbc4499e0569c7ea3755c0075012de6b95bbd Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:33:17 +0300 Subject: [PATCH 6/7] improve RSocketTestServer configuration --- buildSrc/src/main/kotlin/RSocketTestServer.kt | 61 +++++++++++++++++++ .../rsocket-test-server/build.gradle.kts | 53 +--------------- rsocket-transport-ktor/build.gradle.kts | 2 +- 3 files changed, 63 insertions(+), 53 deletions(-) create mode 100644 buildSrc/src/main/kotlin/RSocketTestServer.kt diff --git a/buildSrc/src/main/kotlin/RSocketTestServer.kt b/buildSrc/src/main/kotlin/RSocketTestServer.kt new file mode 100644 index 000000000..15f8928a2 --- /dev/null +++ b/buildSrc/src/main/kotlin/RSocketTestServer.kt @@ -0,0 +1,61 @@ +import org.gradle.api.* +import org.gradle.api.file.* +import org.gradle.api.tasks.* +import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.* +import org.jetbrains.kotlin.gradle.plugin.mpp.* +import java.io.* +import java.net.* + +open class RSocketTestServer : DefaultTask() { + @Internal + var server: Closeable? = null + private set + + @Internal + lateinit var classpath: FileCollection + + @TaskAction + fun exec() { + try { + println("[TestServer] start") + val loader = URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader()) + server = loader.loadClass("io.rsocket.kotlin.test.server.AppKt").getMethod("start").invoke(null) as Closeable + println("[TestServer] started") + } catch (cause: Throwable) { + println("[TestServer] failed: ${cause.message}") + cause.printStackTrace() + } + } +} + +fun Project.registerTestServer() { + val startTestServer by tasks.registering(RSocketTestServer::class) { + dependsOn(tasks["jvmJar"]) + val target = this@registerTestServer.extensions.getByType().targets["jvm"] + classpath = (target.compilations["test"] as KotlinJvmCompilation).runtimeDependencyFiles + } + + gradle.buildFinished { + startTestServer.get().server?.run { + close() + println("[TestServer] stop") + } + } +} + +private val testTasks = setOf( + "jsLegacyNodeTest", + "jsIrNodeTest", + "jsLegacyBrowserTest", + "jsIrBrowserTest", +) + +fun Project.dependsOnTestServer() { + val testServer = evaluationDependsOn(":rsocket-test-server") + val startTestServer by testServer.tasks.getting + + tasks.matching { it.name in testTasks }.all { + dependsOn(startTestServer) + } +} diff --git a/rsocket-test/rsocket-test-server/build.gradle.kts b/rsocket-test/rsocket-test-server/build.gradle.kts index e6a9c039e..747c18a1f 100644 --- a/rsocket-test/rsocket-test-server/build.gradle.kts +++ b/rsocket-test/rsocket-test-server/build.gradle.kts @@ -14,10 +14,6 @@ * limitations under the License. */ -import org.jetbrains.kotlin.gradle.plugin.mpp.* -import java.io.* -import java.net.* - plugins { `rsocket-build` `rsocket-build-jvm` @@ -36,51 +32,4 @@ kotlin { } } -open class RSocketTestServer : DefaultTask() { - @Internal - var server: Closeable? = null - private set - - @Internal - lateinit var classpath: FileCollection - - @TaskAction - fun exec() { - try { - println("[TestServer] start") - val loader = URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), ClassLoader.getSystemClassLoader()) - server = loader.loadClass("io.rsocket.kotlin.test.server.AppKt").getMethod("start").invoke(null) as Closeable - println("[TestServer] started") - } catch (cause: Throwable) { - println("[TestServer] failed: ${cause.message}") - cause.printStackTrace() - } - } -} - -val startTestServer by tasks.registering(RSocketTestServer::class) { - dependsOn(tasks["jvmJar"]) - classpath = (kotlin.targets["jvm"].compilations["test"] as KotlinJvmCompilation).runtimeDependencyFiles -} - -val testTasks = setOf( - "jsLegacyNodeTest", - "jsIrNodeTest", - "jsLegacyBrowserTest", - "jsIrBrowserTest", -) - -rootProject.allprojects { - if (name == "rsocket-transport-ktor") { - tasks.matching { it.name in testTasks }.all { - dependsOn(startTestServer) - } - } -} - -gradle.buildFinished { - startTestServer.get().server?.run { - close() - println("[TestServer] stop") - } -} +registerTestServer() diff --git a/rsocket-transport-ktor/build.gradle.kts b/rsocket-transport-ktor/build.gradle.kts index 429d79ef0..0e8163ed9 100644 --- a/rsocket-transport-ktor/build.gradle.kts +++ b/rsocket-transport-ktor/build.gradle.kts @@ -49,4 +49,4 @@ kotlin { description = "Ktor RSocket transport implementations (TCP, Websocket)" -evaluationDependsOn(":rsocket-test-server") +dependsOnTestServer() From 70d95fedf567f57fb600908ca05f438a1be24983 Mon Sep 17 00:00:00 2001 From: olme04 Date: Thu, 19 Aug 2021 11:33:47 +0300 Subject: [PATCH 7/7] fix warnings after turbine update --- .../io/rsocket/kotlin/core/RSocketTest.kt | 24 +++++++++---------- .../kotlin/core/ReconnectableRSocketTest.kt | 4 ++-- .../kotlin/internal/RSocketRequesterTest.kt | 2 +- .../rsocket/kotlin/keepalive/KeepAliveTest.kt | 4 ++-- .../io/rsocket/kotlin/test/TestConnection.kt | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt index 616681ce5..6d8a64bea 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/RSocketTest.kt @@ -96,9 +96,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { val requester = start() requester.requestStream(payload("HELLO")).test { repeat(10) { - expectItem().release() + awaitItem().release() } - expectComplete() + awaitComplete() } } @@ -122,9 +122,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { }) requester.requestStream(payload("HELLO")).flowOn(PrefetchStrategy(1, 0)).test { repeat(3) { - expectItem().release() + awaitItem().release() } - val error = expectError() + val error = awaitError() assertTrue(error is RSocketError.ApplicationError) assertEquals("FAIL", error.message) } @@ -148,9 +148,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { .map { it.value } .test { repeat(23) { - expectItem().release() + awaitItem().release() } - val error = expectError() + val error = awaitError() assertTrue(error is IllegalStateException) assertEquals("oops", error.message) } @@ -170,9 +170,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { .take(3) //canceled after 3 element .test { repeat(3) { - expectItem().release() + awaitItem().release() } - expectComplete() + awaitComplete() } } @@ -203,9 +203,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { val request = (1..10).asFlow().map { payload(it.toString()) }.onCompletion { awaiter.complete() } requester.requestChannel(payload(""), request).test { repeat(10) { - expectItem().release() + awaitItem().release() } - expectComplete() + awaitComplete() } awaiter.join() delay(500) @@ -241,9 +241,9 @@ class RSocketTest : SuspendTest, TestWithLeakCheck { val request = (1..3).asFlow().map { payload(it.toString()) } requester.requestChannel(payload("0"), request).flowOn(PrefetchStrategy(3, 0)).test { repeat(3) { - expectItem().release() + awaitItem().release() } - expectComplete() + awaitComplete() } } diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/ReconnectableRSocketTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/ReconnectableRSocketTest.kt index c5d6c8097..6d2db3a87 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/ReconnectableRSocketTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/core/ReconnectableRSocketTest.kt @@ -204,9 +204,9 @@ class ReconnectableRSocketTest : SuspendTest, TestWithLeakCheck { rSocket.requestStream(Payload.Empty).test { repeat(5) { - assertEquals(Payload.Empty, expectItem()) + assertEquals(Payload.Empty, awaitItem()) } - expectComplete() + awaitComplete() } assertTrue(rSocket.isActive) diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/RSocketRequesterTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/RSocketRequesterTest.kt index 7a24b7b06..19a6c0f5c 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/RSocketRequesterTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/internal/RSocketRequesterTest.kt @@ -386,7 +386,7 @@ class RSocketRequesterTest : TestWithConnection(), TestWithLeakCheck { connection.test { expectFrame { assertTrue(it is RequestFrame) } connection.cancel() - expectComplete() + awaitComplete() } } assertFailsWith(CancellationException::class) { request() } diff --git a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/keepalive/KeepAliveTest.kt b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/keepalive/KeepAliveTest.kt index f918627c3..67a79d942 100644 --- a/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/keepalive/KeepAliveTest.kt +++ b/rsocket-core/src/commonTest/kotlin/io/rsocket/kotlin/keepalive/KeepAliveTest.kt @@ -65,7 +65,7 @@ class KeepAliveTest : TestWithConnection(), TestWithLeakCheck { assertTrue(rSocket.isActive) connection.test { repeat(50) { - expectItem() + awaitItem() } } } @@ -102,7 +102,7 @@ class KeepAliveTest : TestWithConnection(), TestWithLeakCheck { fun rSocketCanceledOnMissingKeepAliveTicks() = test { val rSocket = requester() connection.test { - while (rSocket.isActive) kotlin.runCatching { expectItem() } + while (rSocket.isActive) kotlin.runCatching { awaitItem() } } assertTrue(rSocket.coroutineContext.job.getCancellationException().cause is RSocketError.ConnectionError) } diff --git a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConnection.kt b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConnection.kt index 7e92b12b4..fc1a66a65 100644 --- a/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConnection.kt +++ b/rsocket-test/src/commonMain/kotlin/io/rsocket/kotlin/test/TestConnection.kt @@ -77,5 +77,5 @@ suspend fun FlowTurbine<*>.expectNoEventsIn(timeMillis: Long) { } suspend inline fun FlowTurbine.expectFrame(block: (frame: Frame) -> Unit) { - block(expectItem()) + block(awaitItem()) }