Skip to content

Commit

Permalink
1.0.4 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 authored Apr 15, 2024
2 parents ad8b174 + e7915dd commit 208dc65
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 79 deletions.
49 changes: 14 additions & 35 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import nl.littlerobots.vcu.plugin.versionCatalogUpdate
import nl.littlerobots.vcu.plugin.versionSelector
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.gradleDoctor)
alias(libs.plugins.versions)
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.dokka)
alias(libs.plugins.dependencyAnalysis)
alias(libs.plugins.atomicfu)
// plugins already on a classpath (conventions)
// alias(libs.plugins.androidApplication) apply false
// alias(libs.plugins.androidLibrary) apply false
Expand Down Expand Up @@ -61,34 +60,30 @@ doctor {
}
}

dependencyAnalysis {
structure {
ignoreKtx(true)
}
}

dependencies {
detektPlugins(rootProject.libs.detekt.formatting)
detektPlugins(rootProject.libs.detekt.compose)
detektPlugins(rootProject.libs.detekt.libraries)
}

versionCatalogUpdate {
sortByKey.set(true)
sortByKey = true

versionSelector { stabilityLevel(it.candidate.version) >= Config.minStabilityLevel }

keep {
keepUnusedVersions.set(true)
keepUnusedLibraries.set(true)
keepUnusedPlugins.set(true)
keepUnusedVersions = true
keepUnusedLibraries = true
keepUnusedPlugins = true
}
}

// atomicfu {
// dependenciesVersion = libs.versions.kotlinx.atomicfu.get()
// transformJvm = false
// jvmVariant = "VH"
// transformJs = false
// }
atomicfu {
dependenciesVersion = libs.versions.kotlinx.atomicfu.get()
transformJvm = false
jvmVariant = "VH"
transformJs = false
}

tasks {
withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
Expand Down Expand Up @@ -118,22 +113,6 @@ tasks {
description = "Run detekt on whole project"
autoCorrect = false
}

withType<DependencyUpdatesTask>().configureEach {
outputFormatter = "json"

fun stabilityLevel(version: String): Int {
Config.stabilityLevels.forEachIndexed { index, postfix ->
val regex = """.*[.\-]$postfix[.\-\d]*""".toRegex(RegexOption.IGNORE_CASE)
if (version.matches(regex)) return index
}
return Config.stabilityLevels.size
}

rejectVersionIf {
stabilityLevel(currentVersion) > stabilityLevel(candidate.version)
}
}
}

extensions.findByType<YarnRootExtension>()?.run {
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Config {

const val majorRelease = 1
const val minorRelease = 0
const val patch = 3
const val patch = 4
const val postfix = ""
const val versionName = "$majorRelease.$minorRelease.$patch$postfix"
const val url = "https://github.com/respawn-app/ApiResult"
Expand Down Expand Up @@ -68,6 +68,8 @@ feature-rich.
const val consumerProguardFile = "consumer-rules.pro"

val stabilityLevels = listOf("preview", "eap", "alpha", "beta", "m", "cr", "rc")
val minStabilityLevel = stabilityLevels.indexOf("beta")

object Detekt {

const val configFile = "detekt.yml"
Expand Down
13 changes: 12 additions & 1 deletion buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

@OptIn(ExperimentalWasmDsl::class)
@Suppress("LongParameterList", "CyclomaticComplexMethod")
fun Project.configureMultiplatform(
ext: KotlinMultiplatformExtension,
jvm: Boolean = true,
Expand All @@ -14,7 +17,8 @@ fun Project.configureMultiplatform(
js: Boolean = true,
tvOs: Boolean = true,
macOs: Boolean = true,
watchOs: Boolean = true
watchOs: Boolean = true,
wasm: Boolean = true,
) = ext.apply {
val libs by versionCatalog
explicitApi()
Expand All @@ -27,6 +31,13 @@ fun Project.configureMultiplatform(
mingwX64()
}

if (wasm) wasmJs {
moduleName = this@configureMultiplatform.name
nodejs()
browser()
binaries.library()
}

if (js) {
js(IR) {
browser()
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ val Project.localProperties
load(FileInputStream(File(rootProject.rootDir, "local.properties")))
}
}

fun stabilityLevel(version: String): Int {
Config.stabilityLevels.forEachIndexed { index, postfix ->
val regex = """.*[.\-]$postfix[.\-\d]*""".toRegex(RegexOption.IGNORE_CASE)
if (version.matches(regex)) return index
}
return Config.stabilityLevels.size
}
13 changes: 13 additions & 0 deletions core/src/commonMain/kotlin/pro/respawn/apiresult/ApiResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,16 @@ public inline val <T> T.asResult: ApiResult<T> get() = ApiResult(this)
* Alias for [map] that takes [this] as a parameter
*/
public inline infix fun <T, R> ApiResult<T>.apply(block: T.() -> R): ApiResult<R> = map(block)

/**
* @return if [this] result value is [R], then returns it. If not, returns an [ApiResult.Error]
*/
public inline fun <reified R, T> ApiResult<T>.requireIs(
exception: (T) -> Exception = { value ->
"Result value is of type ${value?.let { it::class.simpleName }} but expected ${R::class}"
.let(::ConditionNotSatisfiedException)
},
): ApiResult<R> = tryMap { value ->
if (value !is R) throw exception(value)
value
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,37 @@ public inline fun <T> Iterable<ApiResult<T>>.firstSuccessOrThrow(): T = firstSuc
* @see firstSuccessOrThrow
*/
public inline fun <T> Iterable<ApiResult<T>>.firstSuccessOrNull(): T? = firstSuccess().orNull()

/**
* Maps each value in the collection, wrapping each map operation in an [ApiResult]
*/
public inline fun <T, R> Sequence<T>.mapResulting(
crossinline map: (T) -> R
): Sequence<ApiResult<R>> = map { ApiResult { map(it) } }

/**
* Accumulates all errors from this collection and splits them into two lists:
* - First is the [ApiResult.Success] results
* - Seconds is [ApiResult.Error] or errors produced by [ApiResult.Loading] (see [ApiResult.errorOnLoading]
*/
public fun <T> Sequence<ApiResult<T>>.accumulate(): Pair<List<T>, List<Exception>> {
val (success, other) = partition { it.isSuccess }
return Pair(
success.map { (it as Success).result },
other.mapNotNull { it.errorOnLoading().exceptionOrNull() }
)
}

/**
* Maps each value in the collection, wrapping each map operation in an [ApiResult]
*/
public inline fun <T, R> Iterable<T>.mapResulting(
crossinline map: (T) -> R
): List<ApiResult<R>> = map { ApiResult { map(it) } }

/**
* Accumulates all errors from this collection and splits them into two lists:
* - First is the [ApiResult.Success] results
* - Seconds is [ApiResult.Error] or errors produced by [ApiResult.Loading] (see [ApiResult.errorOnLoading]
*/
public fun <T> Iterable<ApiResult<T>>.accumulate(): Pair<List<T>, List<Exception>> = asSequence().accumulate()
10 changes: 10 additions & 0 deletions core/src/commonMain/kotlin/pro/respawn/apiresult/SuspendResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,13 @@ public inline fun <T> Flow<ApiResult<T>>.onEachResult(
public inline fun <T> Flow<ApiResult<T>>.onEachSuccess(
crossinline block: suspend (T) -> Unit
): Flow<ApiResult<T>> = onEachResult(block)

/**
* Maps this flow to an [ApiResult.Success] value, otherwise throws the resulting error
*/
public fun <T> Flow<ApiResult<T>>.orThrow(): Flow<T> = map { it.orThrow() }

/**
* Maps this flow to an [ApiResult.Success] value, otherwise the value is `null`
*/
public fun <T> Flow<ApiResult<T>>.orNull(): Flow<T?> = map { it.orNull() }
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ android.disableResourceValidation=true
android.nonFinalResIds=true
kotlinx.atomicfu.enableJvmIrTransformation=true
org.gradle.configuration-cache.problems=warn
nl.littlerobots.vcu.resolver=false
nl.littlerobots.vcu.resolver=true
40 changes: 18 additions & 22 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
[versions]
compose = "1.5.4"
compose-activity = "1.8.2"
compose-compiler = "1.5.7"
compose-material3 = "1.2.0-beta01"
compose = "1.6.5"
compose-activity = "1.9.0-rc01"
compose-compiler = "1.5.11"
compose-material3 = "1.2.1"
composeDetektPlugin = "1.3.0"
core-ktx = "1.12.0"
coroutines = "1.7.3"
dependencyAnalysisPlugin = "1.28.0"
detekt = "1.23.4"
detektFormattingPlugin = "1.23.4"
dokka = "1.9.10"
gradleAndroid = "8.3.0-alpha18"
gradleDoctorPlugin = "0.9.1"
kotest = "5.8.0"
kotest-plugin = "5.8.0"
core-ktx = "1.13.0-rc01"
coroutines = "1.8.1-Beta"
dependencyAnalysisPlugin = "1.31.0"
detekt = "1.23.6"
detektFormattingPlugin = "1.23.6"
dokka = "1.9.20"
gradleAndroid = "8.4.0-rc02"
gradleDoctorPlugin = "0.9.2"
kotest = "5.8.1"
kotest-plugin = "5.8.1"
# @pin
kotlin = "1.9.22"
kotlin = "1.9.23"
kotlinx-atomicfu = "0.23.1"
lifecycle = "2.6.2"
lifecycle-runtime-ktx = "2.6.2"
lifecycle = "2.7.0"
lifecycle-runtime-ktx = "2.7.0"
turbine = "1.0.0"
versionCatalogUpdatePlugin = "0.8.2"
versionsPlugin = "0.50.0"
versionCatalogUpdatePlugin = "0.8.4"

[libraries]
android-gradle = { module = "com.android.tools.build:gradle", version.ref = "gradleAndroid" }
Expand All @@ -39,7 +38,6 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting",
detekt-gradle = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
detekt-libraries = { module = "io.gitlab.arturbosch.detekt:detekt-rules-libraries", version.ref = "detekt" }
dokka-android = { module = "org.jetbrains.dokka:android-documentation-plugin", version.ref = "dokka" }
gradle-versions = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsPlugin" }
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-framework = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
kotest-junit = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
Expand All @@ -51,7 +49,6 @@ kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-common", version.ref = "kotlin" }
lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle-runtime-ktx" }
version-gradle = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsPlugin" }

[bundles]
unittest = [
Expand All @@ -71,4 +68,3 @@ dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
gradleDoctor = { id = "com.osacky.doctor", version.ref = "gradleDoctorPlugin" }
kotest = { id = "io.kotest.multiplatform", version.ref = "kotest-plugin" }
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "versionCatalogUpdatePlugin" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# 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 @@ -144,15 +145,15 @@ 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=SC3045
# 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=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# 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, 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.
# 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" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
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

Expand All @@ -57,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

Expand Down

0 comments on commit 208dc65

Please sign in to comment.