Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasmJS target to the Cache module #605

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -57,3 +58,6 @@ tasks {
targetCompatibility = JavaVersion.VERSION_11.name
}
}

// Workaround for https://youtrack.jetbrains.com/issue/KT-62040
tasks.getByName("wrapper")
28 changes: 28 additions & 0 deletions cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,6 +29,10 @@ kotlin {
browser()
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}
cocoapods {
summary = "Cache5"
homepage = "https://github.com/MobileNativeFoundation/Store"
Expand All @@ -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

Expand Down Expand Up @@ -108,3 +127,12 @@ koverMerged {
onCheck.set(true)
}
}

// See https://youtrack.jetbrains.com/issue/KT-63014
rootProject.the<NodeJsRootExtension>().apply {
nodeVersion = "21.0.0-v8-canary20231024d0ddc81258"
nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary"
}
tasks.withType<KotlinNpmInstallTask>().configureEach {
args.add("--ignore-engines")
}
2 changes: 1 addition & 1 deletion cache/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.mobilenativefoundation.store.cache5" />
<manifest />
Original file line number Diff line number Diff line change
@@ -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<String, String> = CacheBuilder<String, String>().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<String, String>().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<String, String>().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<String, String>().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<String, String>().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"))
}
}
11 changes: 10 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -25,6 +26,10 @@ kotlin {
browser()
nodejs()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
nodejs()
}

sourceSets {
val commonMain by getting {
Expand All @@ -33,9 +38,13 @@ kotlin {
}
}
}

jvmToolchain(11)
}

android {
namespace = "org.mobilenativefoundation.store.core5"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
compileSdk = 33

Expand Down
2 changes: 1 addition & 1 deletion core/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.mobilenativefoundation.store.core5"/>
<manifest />
11 changes: 6 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
41 changes: 28 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

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

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

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

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

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

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

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

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

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

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

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

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