diff --git a/build.gradle.kts b/build.gradle.kts index 6c7def3af..13a6ceacc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,6 +20,7 @@ buildscript { classpath(libs.maven.publish.plugin) classpath(libs.kover.plugin) classpath(libs.atomic.fu.gradle.plugin) + classpath(libs.kmmBridge.gradle.plugin) } } @@ -57,3 +58,6 @@ tasks { targetCompatibility = JavaVersion.VERSION_11.name } } + +// Workaround for https://youtrack.jetbrains.com/issue/KT-62040 +tasks.getByName("wrapper") diff --git a/cache/build.gradle.kts b/cache/build.gradle.kts index b13569c13..7ebfb5b9f 100644 --- a/cache/build.gradle.kts +++ b/cache/build.gradle.kts @@ -2,6 +2,9 @@ import com.vanniktech.maven.publish.SonatypeHost.S01 import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension +import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask plugins { kotlin("multiplatform") @@ -26,6 +29,10 @@ kotlin { browser() nodejs() } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs() + } cocoapods { summary = "Cache5" homepage = "https://github.com/MobileNativeFoundation/Store" @@ -48,15 +55,27 @@ kotlin { implementation(libs.kotlinx.coroutines.core) } } + val commonTest by getting { + dependencies { + implementation(kotlin("test")) + implementation(libs.junit) + implementation(libs.kotlinx.coroutines.test) + } + } + val jvmMain by getting val androidMain by getting val nativeMain by creating { dependsOn(commonMain) } } + + jvmToolchain(11) } android { + namespace = "org.mobilenativefoundation.store.cache5" + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") compileSdk = 33 @@ -108,3 +127,12 @@ koverMerged { onCheck.set(true) } } + +// See https://youtrack.jetbrains.com/issue/KT-63014 +rootProject.the().apply { + nodeVersion = "21.0.0-v8-canary20231024d0ddc81258" + nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" +} +tasks.withType().configureEach { + args.add("--ignore-engines") +} diff --git a/cache/src/androidMain/AndroidManifest.xml b/cache/src/androidMain/AndroidManifest.xml index 55c8f9cb7..8072ee00d 100644 --- a/cache/src/androidMain/AndroidManifest.xml +++ b/cache/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/cache/src/commonTest/kotlin/org/mobilenativefoundation/store/cache5/CacheTests.kt b/cache/src/commonTest/kotlin/org/mobilenativefoundation/store/cache5/CacheTests.kt new file mode 100644 index 000000000..2488c4eda --- /dev/null +++ b/cache/src/commonTest/kotlin/org/mobilenativefoundation/store/cache5/CacheTests.kt @@ -0,0 +1,106 @@ +package org.mobilenativefoundation.store.cache5 + +import kotlinx.coroutines.test.runTest +import kotlin.test.Ignore +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.time.Duration.Companion.milliseconds + +class CacheTests { + private val cache: Cache = CacheBuilder().build() + + @Test + fun getIfPresent() { + cache.put("key", "value") + assertEquals("value", cache.getIfPresent("key")) + } + + @Test + fun getOrPut() { + assertEquals("value", cache.getOrPut("key") { "value" }) + } + + @Ignore // Not implemented yet + @Test + fun getAllPresent() { + cache.put("key1", "value1") + cache.put("key2", "value2") + assertEquals(mapOf("key1" to "value1", "key2" to "value2"), cache.getAllPresent(listOf("key1", "key2"))) + } + + @Ignore // Not implemented yet + @Test + fun putAll() { + cache.putAll(mapOf("key1" to "value1", "key2" to "value2")) + assertEquals(mapOf("key1" to "value1", "key2" to "value2"), cache.getAllPresent(listOf("key1", "key2"))) + } + + @Test + fun invalidate() { + cache.put("key", "value") + cache.invalidate("key") + assertEquals(null, cache.getIfPresent("key")) + } + + @Ignore // Not implemented yet + @Test + fun invalidateAll() { + cache.put("key1", "value1") + cache.put("key2", "value2") + cache.invalidateAll(listOf("key1", "key2")) + assertEquals(null, cache.getIfPresent("key1")) + assertEquals(null, cache.getIfPresent("key2")) + } + + @Ignore // Not implemented yet + @Test + fun size() { + cache.put("key1", "value1") + cache.put("key2", "value2") + assertEquals(2, cache.size()) + } + + @Test + fun maximumSize() { + val cache = CacheBuilder().maximumSize(1).build() + cache.put("key1", "value1") + cache.put("key2", "value2") + assertEquals(null, cache.getIfPresent("key1")) + assertEquals("value2", cache.getIfPresent("key2")) + } + + @Test + fun maximumWeight() { + val cache = CacheBuilder().weigher(399) { _, _ -> 100 }.build() + cache.put("key1", "value1") + cache.put("key2", "value2") + assertEquals(null, cache.getIfPresent("key1")) + assertEquals("value2", cache.getIfPresent("key2")) + } + + @Test + fun expireAfterAccess() = runTest { + var timeNs = 0L + val cache = CacheBuilder().expireAfterAccess(100.milliseconds).ticker { timeNs }.build() + cache.put("key", "value") + + timeNs += 50.milliseconds.inWholeNanoseconds + assertEquals("value", cache.getIfPresent("key")) + + timeNs += 100.milliseconds.inWholeNanoseconds + assertEquals(null, cache.getIfPresent("key")) + } + + @Test + fun expireAfterWrite() = runTest { + var timeNs = 0L + val cache = CacheBuilder().expireAfterWrite(100.milliseconds).ticker { timeNs }.build() + cache.put("key", "value") + + timeNs += 50.milliseconds.inWholeNanoseconds + assertEquals("value", cache.getIfPresent("key")) + + timeNs += 50.milliseconds.inWholeNanoseconds + assertEquals(null, cache.getIfPresent("key")) + } +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 57dfd13f6..a44ebacf1 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,5 +1,6 @@ import com.vanniktech.maven.publish.SonatypeHost import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { kotlin("multiplatform") @@ -8,7 +9,7 @@ plugins { id("com.vanniktech.maven.publish") id("org.jetbrains.dokka") id("org.jetbrains.kotlinx.kover") - id("co.touchlab.faktory.kmmbridge") version("0.3.2") + id("co.touchlab.faktory.kmmbridge") `maven-publish` kotlin("native.cocoapods") id("kotlinx-atomicfu") @@ -25,6 +26,10 @@ kotlin { browser() nodejs() } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + nodejs() + } sourceSets { val commonMain by getting { @@ -33,9 +38,13 @@ kotlin { } } } + + jvmToolchain(11) } android { + namespace = "org.mobilenativefoundation.store.core5" + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") compileSdk = 33 diff --git a/core/src/androidMain/AndroidManifest.xml b/core/src/androidMain/AndroidManifest.xml index 463e3657a..8072ee00d 100644 --- a/core/src/androidMain/AndroidManifest.xml +++ b/core/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6de9532a9..7516546c6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,11 @@ [versions] androidMinSdk = "24" androidCompileSdk = "33" -androidGradlePlugin = "7.4.2" +androidGradlePlugin = "8.2.2" androidTargetSdk = "33" -atomicFu = "0.20.2" -baseKotlin = "1.9.10" -dokkaGradlePlugin = "1.6.0" +atomicFu = "0.23.2" +baseKotlin = "1.9.22" +dokkaGradlePlugin = "1.9.10" ktlintGradle = "10.2.1" jacocoGradlePlugin = "0.8.7" mavenPublishPlugin = "0.22.0" @@ -14,7 +14,7 @@ pagingCompose = "3.3.0-alpha02" pagingRuntime = "3.2.1" spotlessPluginGradle = "6.4.1" junit = "4.13.2" -kotlinxCoroutines = "1.7.1" +kotlinxCoroutines = "1.8.0" kotlinxSerialization = "1.5.1" kermit = "1.2.2" testCore = "1.5.0" @@ -36,6 +36,7 @@ jacoco-gradle-plugin = { group = "org.jacoco", name = "org.jacoco.core", version maven-publish-plugin = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "mavenPublishPlugin" } kover-plugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kover" } atomic-fu-gradle-plugin = { group = "org.jetbrains.kotlinx", name = "atomicfu-gradle-plugin", version.ref = "atomicFu" } +kmmBridge-gradle-plugin = { group = "co.touchlab.faktory.kmmbridge", name = "co.touchlab.faktory.kmmbridge.gradle.plugin", version.ref = "kmmBridge" } kotlinx-atomic-fu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicFu" } kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "baseKotlin" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a4..d64cd4917 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3e9de8f10..a80b22ce5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Sat Jun 17 09:25:41 EDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c78733..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32c..25da30dbd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/multicast/build.gradle.kts b/multicast/build.gradle.kts index 28db9f25e..2b602120f 100644 --- a/multicast/build.gradle.kts +++ b/multicast/build.gradle.kts @@ -53,9 +53,13 @@ kotlin { dependsOn(commonMain) } } + + jvmToolchain(11) } android { + namespace = "org.mobilenativefoundation.store.multicast5" + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") compileSdk = 33 diff --git a/multicast/src/androidMain/AndroidManifest.xml b/multicast/src/androidMain/AndroidManifest.xml index 4bc2e9a98..8072ee00d 100644 --- a/multicast/src/androidMain/AndroidManifest.xml +++ b/multicast/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/paging/build.gradle.kts b/paging/build.gradle.kts index f313ed179..f93e1b172 100644 --- a/paging/build.gradle.kts +++ b/paging/build.gradle.kts @@ -8,7 +8,7 @@ plugins { id("com.vanniktech.maven.publish") id("org.jetbrains.dokka") id("org.jetbrains.kotlinx.kover") - id("co.touchlab.faktory.kmmbridge") version("0.3.2") + id("co.touchlab.faktory.kmmbridge") `maven-publish` kotlin("native.cocoapods") id("kotlinx-atomicfu") @@ -52,9 +52,13 @@ kotlin { } } } + + jvmToolchain(11) } android { + namespace = "org.mobilenativefoundation.store.paging5" + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") compileSdk = 33 diff --git a/paging/src/androidMain/AndroidManifest.xml b/paging/src/androidMain/AndroidManifest.xml index b617bd2bf..8072ee00d 100644 --- a/paging/src/androidMain/AndroidManifest.xml +++ b/paging/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/rx2/build.gradle.kts b/rx2/build.gradle.kts index b41c0ab56..d7ca6cb77 100644 --- a/rx2/build.gradle.kts +++ b/rx2/build.gradle.kts @@ -28,6 +28,8 @@ dependencies { } android { + namespace = "org.mobilenativefoundation.store.rx2" + compileSdk = 33 defaultConfig { @@ -48,6 +50,10 @@ android { } } +kotlin { + jvmToolchain(11) +} + tasks.withType().configureEach { dokkaSourceSets.configureEach { reportUndocumented.set(false) diff --git a/rx2/src/main/AndroidManifest.xml b/rx2/src/main/AndroidManifest.xml index 20ac12a6b..8072ee00d 100644 --- a/rx2/src/main/AndroidManifest.xml +++ b/rx2/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + diff --git a/settings.gradle b/settings.gradle index 8c532892f..b8969413e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,10 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + include ':store' include ':cache' include ':multicast' include ':rx2' include ':paging' -include ':core' \ No newline at end of file +include ':core' diff --git a/store/build.gradle.kts b/store/build.gradle.kts index a495ae20e..11a3bd4ae 100644 --- a/store/build.gradle.kts +++ b/store/build.gradle.kts @@ -10,7 +10,7 @@ plugins { id("com.vanniktech.maven.publish") id("org.jetbrains.dokka") id("org.jetbrains.kotlinx.kover") - id("co.touchlab.faktory.kmmbridge") version("0.3.2") + id("co.touchlab.faktory.kmmbridge") `maven-publish` kotlin("native.cocoapods") id("kotlinx-atomicfu") @@ -61,7 +61,6 @@ kotlin { } val commonTest by getting { - dependsOn(commonMain) dependencies { implementation(kotlin("test")) implementation(libs.junit) @@ -75,9 +74,13 @@ kotlin { dependsOn(commonMain) } } + + jvmToolchain(11) } android { + namespace = "org.mobilenativefoundation.store.store5" + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") compileSdk = 33 diff --git a/store/src/androidMain/AndroidManifest.xml b/store/src/androidMain/AndroidManifest.xml index 5d87d3b12..8072ee00d 100644 --- a/store/src/androidMain/AndroidManifest.xml +++ b/store/src/androidMain/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file +