Skip to content

Commit

Permalink
Kotlin 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
romainbsl committed Apr 30, 2024
1 parent 7bf22a7 commit 7034626
Show file tree
Hide file tree
Showing 29 changed files with 312 additions and 298 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ on:
- '!./github/workflow/snapshot.yml'

jobs:
build-upload:
unit-tests:
uses: kosi-libs/kodein-internal-github-actions/.github/workflows/unit-tests.yml@main
instrumentation-tests:
uses: kosi-libs/kodein-internal-github-actions/.github/workflows/check-with-android.yml@main

upload-snapshot:
needs:
- unit-tests
- instrumentation-tests
runs-on: macOS-latest
env:
SONATYPE_USERNAME: ${{ secrets.sonatype_username }}
SONATYPE_PASSWORD: ${{ secrets.sonatype_password }}
steps:
- name: Setup
uses: kosi-libs/kodein-internal-github-actions/setup@main
- name: Check with Android
uses: kosi-libs/kodein-internal-github-actions/checkWithAndroid@main
- name: Upload
run: ./gradlew publishAllPublicationsToOssrhStagingRepository -PgitRef=${{ github.ref }} -Psnapshot=true
shell: bash
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ package-lock.json
*.a
*.o
*.so

# Kotlin
.kotlin
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kodein.library.android
alias(libs.plugins.compose.compiler)
alias(libs.plugins.compose)
}

Expand Down
15 changes: 13 additions & 2 deletions framework/compose/kodein-di-framework-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import com.android.build.gradle.internal.lint.LintModelWriterTask
import com.android.build.gradle.internal.tasks.LintModelMetadataTask

plugins {
kodein.library.mppWithAndroid
alias(libs.plugins.compose.compiler)
alias(libs.plugins.compose)
}

kotlin.kodein {
jsEnv()

allComposeExperimental()
allComposeUi()

common.mainDependencies {
implementation(kotlin.compose.runtime)
Expand All @@ -21,6 +24,14 @@ kotlin.kodein {
}
}

//
tasks.withType<LintModelWriterTask>{
dependsOn("generateResourceAccessorsForAndroidUnitTest")
}
tasks.withType<LintModelMetadataTask>{
dependsOn("generateResourceAccessorsForAndroidUnitTest")
}

android {
namespace = "org.kodein.di.compose"
}
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true

# Wasm
org.jetbrains.compose.experimental.wasm.enabled=true
kotlin.wasm.stability.nowarn=true

# Kosi
org.kodein.native.enableCrossCompilation=true
17 changes: 9 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[versions]
# Core
kaverit = "2.8.2"
kaverit = "2.9.0-kotlin-2-SNAPSHOT"
# Android
android-appcompat = "28.0.0"
androidx-appcompat = "1.6.1"
androidx-fragment = "1.6.2"
androidx-lifecycle = "2.6.2"
androidx-compose = "2.7.5"
androidx-lifecycle = "2.7.0"
androidx-compose = "2.7.7"
# Compose
jbCompose = "1.6.0-alpha01"
compose-compiler = "1.5.4"
compose-bom = "2023.10.01"
jbCompose = "1.6.10-beta03"
compose-compiler = "2.0.0-RC2"
compose-bom = "2024.04.01"
# KSP
kotlinpoet = "1.14.2"
ksp = "1.9.20-1.0.14"
# Ktor
ktor = "2.3.5"
ktor = "2.3.6"
# JxInject
javax-inject = "1"
# TornadoFX
Expand All @@ -25,7 +25,7 @@ tornadofx = "1.7.20"
testfx = "4.0.4-alpha"
# Test
junit = "4.13.2"
junit-jupiter = "5.6.3"
junit-jupiter = "5.10.1"

[libraries]
# Core
Expand Down Expand Up @@ -61,5 +61,6 @@ junit = { module = "junit:junit", version.ref = "junit" }

[plugins]
compose = { id = "org.jetbrains.compose", version.ref = "jbCompose" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "compose-compiler" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
openjfx = { id = "org.openjfx.javafxplugin", version.ref = "openjfx" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
12 changes: 8 additions & 4 deletions kodein-di/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
id("org.kodein.library.mpp")
}
Expand All @@ -19,10 +21,12 @@ kotlin.kodein {
}
}

kotlin.sourceSets {
val jsBasedMain by getting
getByName("wasmJsMain").dependsOn(jsBasedMain)
}
//kotlin {
// @OptIn(ExperimentalKotlinGradlePluginApi::class)
// compilerOptions {
// freeCompilerArgs.add("-Xexpect-actual-classes")
// }
//}

kodeinUpload {
name = "Kodein"
Expand Down
6 changes: 3 additions & 3 deletions kodein-di/src/commonMain/kotlin/org/kodein/di/Copy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Copy {
* A [Copy] spec that copies no bindings.
*/
public object None: Copy {
override fun keySet(tree: DITree): Set<DI.Key<*, *, *>> = emptySet<DI.Key<*, *, *>>()
override fun keySet(tree: DITree): Set<DI.Key<*, *, *>> = emptySet()
}

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ public interface Copy {
val ignored = ignoreSpecs.flatMap { specsToKeys(tree, it) }
return copySpecs
.flatMap { specsToKeys(tree, it) }
.minus(ignored)
.minus(ignored.toSet())
.toSet()
}
}
Expand All @@ -126,7 +126,7 @@ public interface Copy {
val kept = copySpecs.flatMap { specsToKeys(tree, it) }
val ignored = ignoreSpecs
.flatMap { specsToKeys(tree, it) }
.minus(kept)
.minus(kept.toSet())
return tree.bindings.keys.minus(ignored)
}
}
Expand Down
6 changes: 3 additions & 3 deletions kodein-di/src/commonMain/kotlin/org/kodein/di/DIAware.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package org.kodein.di

import org.kodein.di.internal.DirectDIImpl
import org.kodein.di.internal.createDirectDI
import org.kodein.type.TypeToken

/**
Expand Down Expand Up @@ -43,7 +43,7 @@ public interface DIContext<C : Any> {
internal inline val DIContext<*>.anyType get() = type as TypeToken<in Any>

private object Contexes {
val AnyDIContext = DIContext<Any>(TypeToken.Any, Any())
val AnyDIContext = DIContext(TypeToken.Any, Any())
}

/**
Expand Down Expand Up @@ -272,7 +272,7 @@ public fun <A, T : Any> DIAware.InstanceOrNull(
/**
* Return a direct [DirectDI] instance, with its receiver and context set to this DIAware receiver and context.
*/
public val DIAware.direct: DirectDI get() = DirectDIImpl(di.container, diContext)
public val DIAware.direct: DirectDI get() = createDirectDI(di.container, diContext)

private class DIWrapper(
private val _base: DI,
Expand Down
6 changes: 3 additions & 3 deletions kodein-di/src/commonMain/kotlin/org/kodein/di/DIContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface DIContainer {
* @throws DI.DependencyLoopException When calling the provider function, if the instance construction triggered a dependency loop.
*/
public fun <C : Any, T: Any> provider(key: DI.Key<C, Unit, T>, context: C, overrideLevel: Int = 0): () -> T =
factory(key, context).toProvider { Unit }
factory(key, context).toProvider { }

/**
* Retrieve a provider for the given key, or null if none is found.
Expand All @@ -87,7 +87,7 @@ public interface DIContainer {
* @throws DI.DependencyLoopException When calling the provider function, if the instance construction triggered a dependency loop.
*/
public fun <C : Any, T: Any> providerOrNull(key: DI.Key<C, Unit, T>, context: C, overrideLevel: Int = 0): (() -> T)? =
factoryOrNull(key, context)?.toProvider { Unit }
factoryOrNull(key, context)?.toProvider { }

/**
* Retrieve all providers that match the given key.
Expand All @@ -102,7 +102,7 @@ public interface DIContainer {
* @throws DI.DependencyLoopException When calling the factory function, if the instance construction triggered a dependency loop.
*/
public fun <C : Any, T: Any> allProviders(key: DI.Key<C, Unit, T>, context: C, overrideLevel: Int = 0): List<() -> T> =
allFactories(key, context).map { it.toProvider { Unit } }
allFactories(key, context).map { it.toProvider { } }

/**
* This is where you configure the bindings.
Expand Down
4 changes: 1 addition & 3 deletions kodein-di/src/commonMain/kotlin/org/kodein/di/DirectDI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface DirectDIAware {
/**
* @see [DirectDI]
*/
@Suppress("FunctionName", "ClassName")
@Suppress("FunctionName")
public interface DirectDIBase : DirectDIAware {

/**
Expand Down Expand Up @@ -176,8 +176,6 @@ public interface DirectDIBase : DirectDIAware {
*
* Note that `DirectDI` is engineered to also work with Java code.
*/
// https://youtrack.jetbrains.com/issue/KT-61573
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
public expect interface DirectDI : DirectDIBase

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ public inline fun <reified A : Any, reified T : Any> DirectDIAware.provider(
* @return A provider, or null if no provider was found.
* @throws DI.DependencyLoopException When calling the provider function, if the instance construction triggered a dependency loop.
*/
@Suppress("UNCHECKED_CAST")
public inline fun <reified T : Any> DirectDIAware.providerOrNull(tag: Any? = null): (() -> T)? =
directDI.ProviderOrNull<T>(generic(), tag)

Expand Down
2 changes: 0 additions & 2 deletions kodein-di/src/commonMain/kotlin/org/kodein/di/SetBindings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.kodein.type.generic
* @param T The created type.
* @return A set binding ready to be bound.
*/
@Suppress("RemoveExplicitTypeArguments")
public inline fun <reified T : Any> DI.Builder.bindSet(tag: Any? = null, overrides: Boolean? = null): Unit = Bind(
tag = tag,
overrides = overrides,
Expand Down Expand Up @@ -66,7 +65,6 @@ public inline fun <reified T : Any> DI.Builder.inBindSet(
* @param A The argument type.
* @param T The created type.
*/
@Suppress("RemoveExplicitTypeArguments")
public inline fun <reified A : Any, reified T : Any> DI.Builder.bindArgSet(
tag: Any? = null,
overrides: Boolean? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.kodein.type.generic
*/
public inline fun <C : Any, reified A : Any, reified T: Any> DI.BindBuilder<C>.factory(
noinline creator: BindingDI<C>.(A) -> T
): Factory<C, A, T> = Factory<C, A, T>(contextType, generic(), generic(), creator)
): Factory<C, A, T> = Factory(contextType, generic(), generic(), creator)

/**
* Binds a factory: each time an instance is needed, the function [creator] function will be called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public interface NoArgBindingDI<out C : Any> : DirectDI, WithContext<C> {
}

internal class NoArgBindingDIWrap<out C : Any>(private val _di: BindingDI<C>) : NoArgBindingDI<C>, DirectDI by _di, WithContext<C> by _di {
override fun overriddenProvider() = _di.overriddenFactory().toProvider { Unit }
override fun overriddenProviderOrNull() = _di.overriddenFactoryOrNull()?.toProvider { Unit }
override fun overriddenProvider() = _di.overriddenFactory().toProvider { }
override fun overriddenProviderOrNull() = _di.overriddenFactoryOrNull()?.toProvider { }
override fun overriddenInstance() = overriddenProvider().invoke()
override fun overriddenInstanceOrNull() = overriddenProviderOrNull()?.invoke()
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class Singleton<C : Any, T : Any>(
public val sync: Boolean = true,
public val creator: NoArgBindingDI<C>.() -> T
) : NoArgDIBinding<C, T> {
@Suppress("UNCHECKED_CAST")

private val _refMaker = refMaker ?: SingletonReference
private val _scopeKey = ScopeKey(Any(), Unit)

Expand Down Expand Up @@ -169,7 +169,6 @@ public class Singleton<C : Any, T : Any>(
override fun getFactory(key: DI.Key<C, Unit, T>, di: BindingDI<C>): (Unit) -> T {
var lateInitRegistry: ScopeRegistry? = null

@Suppress("UNCHECKED_CAST")
val bindingDi = if (explicitContext) di else di.onErasedContext()
return { _ ->
val registry = lateInitRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ internal class DIContainerImpl private constructor(
runCallbacks: Boolean
) : this(DITreeImpl(builder.bindingsMap, externalSources, builder.translators), null, fullDescriptionOnError, fullContainerTreeOnError) {
val init: () -> Unit = {
val direct = DirectDIImpl(this, AnyDIContext)
builder.callbacks.forEach { @Suppress("UNUSED_EXPRESSION") it(direct) }
val direct = createDirectDI(this, AnyDIContext)
builder.callbacks.forEach { it(direct) }
}

if (runCallbacks)
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class DIContainerImpl private constructor(
*
* @throws DI.DependencyLoopException if the key exists in the dependency tree.
*/
internal fun check(searchedKey: DI.Key<*, *, *>, searchedOverrideLevel: Int) {
fun check(searchedKey: DI.Key<*, *, *>, searchedOverrideLevel: Int) {
if (!recursiveCheck(this, searchedKey, searchedOverrideLevel)) {
val list = recursiveLoop(this, searchedKey, searchedOverrideLevel, emptyList()) + displayString(searchedKey, overrideLevel)
val sb = StringBuilder()
Expand Down Expand Up @@ -136,7 +136,7 @@ internal class DIContainerImpl private constructor(

private fun <C : Any, A, T: Any> bindingDI(key: DI.Key<C, A, T>, context: DIContext<C>, tree: DITree, overrideLevel: Int) : BindingDI<C> {
val container = DIContainerImpl(tree, Node(key, overrideLevel, node, fullDescriptionOnError), fullDescriptionOnError, fullContainerTreeOnError)
return BindingDIImpl(DirectDIImpl(container, context), key, overrideLevel)
return BindingDIImpl(createDirectDI(container, context), key, overrideLevel)
}

@Suppress("UNCHECKED_CAST")
Expand All @@ -146,7 +146,7 @@ internal class DIContainerImpl private constructor(
val (_, definition, translator) = it[0]
node?.check(key, 0)
val originalContext = DIContext(key.contextType, context) as DIContext<Any>
val kContext = translator?.toKContext(DirectDIImpl(this, originalContext), context) ?: originalContext
val kContext = translator?.toKContext(createDirectDI(this, originalContext), context) ?: originalContext
key as DI.Key<Any, A, T>
val bindingDI = bindingDI(key, kContext, definition.tree, overrideLevel)
return definition.binding.getFactory(key, bindingDI)
Expand All @@ -173,7 +173,7 @@ internal class DIContainerImpl private constructor(
val (_, definition, translator) = result[0]
node?.check(key, overrideLevel)
val originalContext = DIContext(key.contextType, context) as DIContext<Any>
val kContext = translator?.toKContext(DirectDIImpl(this, originalContext), context) ?: originalContext
val kContext = translator?.toKContext(createDirectDI(this, originalContext), context) ?: originalContext
key as DI.Key<Any, A, T>
val bindingDI = bindingDI(key, kContext, definition.tree, overrideLevel)
return definition.binding.getFactory(key, bindingDI)
Expand Down Expand Up @@ -223,7 +223,7 @@ internal class DIContainerImpl private constructor(
return result.map { (_, definition, translator) ->
node?.check(key, overrideLevel)
val originalContext = DIContext(key.contextType, context) as DIContext<Any>
val kContext = translator?.toKContext(DirectDIImpl(this, originalContext), context) ?: originalContext
val kContext = translator?.toKContext(createDirectDI(this, originalContext), context) ?: originalContext
key as DI.Key<Any, A, T>
val bindingDI = bindingDI(key, kContext, definition.tree, overrideLevel)
definition.binding.getFactory(key, bindingDI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal open class BindingDIImpl<out C : Any, out A, out T: Any> internal const
override fun overriddenFactory(): (Any?) -> Any = container.factory(key, context, overrideLevel + 1) as (Any?) -> Any
override fun overriddenFactoryOrNull(): ((Any?) -> Any)? = container.factoryOrNull(key, context, overrideLevel + 1) as ((Any?) -> Any)?
override val context: C get() = directDI.di.diContext.value as C
override fun onErasedContext(): BindingDI<C> = BindingDIImpl<C, A, T>(
override fun onErasedContext(): BindingDI<C> = BindingDIImpl(
directDI.On(ErasedContext),
key,
overrideLevel
Expand Down

This file was deleted.

Loading

0 comments on commit 7034626

Please sign in to comment.