Kotlin 1.5. Further context plugins readOnlyZation

This commit is contained in:
Alexander Nozik 2021-04-07 11:39:24 +03:00
parent 23f1d4f7fd
commit 187094d942
14 changed files with 40 additions and 16 deletions

View File

@ -11,6 +11,7 @@
- Package changed to `space.kscience`
- Scheme made observable
- Global context is a variable (the singleton is hidden and will be deprecated in future)
- Kotlin 1.5
### Deprecated
- Direct use of PluginManager

View File

@ -4,7 +4,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.4.0-dev-5"
version = "0.4.0-dev-6"
}
subprojects {

View File

@ -64,6 +64,7 @@ public final class space/kscience/dataforge/context/ContextBuilder {
public final fun getName ()Lspace/kscience/dataforge/names/Name;
public final fun name (Ljava/lang/String;)V
public final fun plugin (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun plugin (Lspace/kscience/dataforge/context/Plugin;)V
public final fun plugin (Lspace/kscience/dataforge/context/PluginFactory;Lkotlin/jvm/functions/Function1;)V
public final fun plugin (Lspace/kscience/dataforge/context/PluginFactory;Lspace/kscience/dataforge/meta/Meta;)V
public final fun plugin (Lspace/kscience/dataforge/context/PluginTag;Lkotlin/jvm/functions/Function1;)V
@ -202,7 +203,6 @@ public final class space/kscience/dataforge/context/PluginManager : java/lang/It
public fun getContext ()Lspace/kscience/dataforge/context/Context;
public fun iterator ()Ljava/util/Iterator;
public final fun list (Z)Ljava/util/Collection;
public final fun load (Lspace/kscience/dataforge/context/Plugin;)Lspace/kscience/dataforge/context/Plugin;
public final fun remove (Lspace/kscience/dataforge/context/Plugin;)V
}

View File

@ -29,7 +29,7 @@ public class ContextBuilder internal constructor(
meta.action()
}
public fun name(string: String){
public fun name(string: String) {
this.name = string.toName()
}
@ -43,7 +43,7 @@ public class ContextBuilder internal constructor(
factories[factory] = Meta(metaBuilder)
}
public fun plugin(factory: PluginFactory<*>, meta: Meta){
public fun plugin(factory: PluginFactory<*>, meta: Meta) {
factories[factory] = meta
}
@ -55,6 +55,13 @@ public class ContextBuilder internal constructor(
plugin(PluginTag(name, group, version), action)
}
/**
* Add de-facto existing plugin as a dependency
*/
public fun plugin(plugin: Plugin) {
plugin(DeFactoPluginFactory(plugin))
}
public fun build(): Context {
val contextName = name ?: "@auto[${hashCode().toUInt().toString(16)}]".toName()
return Context(contextName, parent, meta.seal()).apply {

View File

@ -1,5 +1,6 @@
package space.kscience.dataforge.context
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.misc.Type
import kotlin.reflect.KClass
@ -12,3 +13,12 @@ public interface PluginFactory<T : Plugin> : Factory<T> {
public const val TYPE: String = "pluginFactory"
}
}
/**
* Plugin factory created for the specific actual plugin
*/
internal class DeFactoPluginFactory<T : Plugin>(val plugin: T) : PluginFactory<T> {
override fun invoke(meta: Meta, context: Context): T = plugin
override val tag: PluginTag get() = plugin.tag
override val type: KClass<out T> get() = plugin::class
}

View File

@ -84,7 +84,7 @@ public class PluginManager(override val context: Context) : ContextAware, Iterab
* @return
*/
@Deprecated("Use immutable contexts instead")
public fun <T : Plugin> load(plugin: T): T {
private fun <T : Plugin> load(plugin: T): T {
if (get(plugin::class, plugin.tag, recursive = false) != null) {
error("Plugin with tag ${plugin.tag} already exists in ${context.name}")
} else {
@ -102,6 +102,7 @@ public class PluginManager(override val context: Context) : ContextAware, Iterab
/**
* Load a plugin using its factory
*/
@Deprecated("Use immutable contexts instead")
internal fun <T : Plugin> load(factory: PluginFactory<T>, meta: Meta = Meta.EMPTY): T =
load(factory(meta, context))

View File

@ -1,6 +1,5 @@
package space.kscience.dataforge.properties
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@ -23,12 +22,12 @@ public fun <T> Property<T>.toFlow(): StateFlow<T> = MutableStateFlow(value).also
}
/**
* Reflect all changes in the [source] property onto this property
* Reflect all changes in the [source] property onto this property. Does not reflect changes back.
*
* @return a mirroring job
*/
@DFExperimental
public fun <T> Property<T>.mirror(source: Property<T>, scope: CoroutineScope) {
public fun <T> Property<T>.mirror(source: Property<T>) {
source.onChange(this) {
this.value = it
}

View File

@ -17,12 +17,14 @@ package space.kscience.dataforge.provider
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.toName
import kotlin.jvm.JvmInline
/**
* Path interface.
*
*/
public inline class Path(public val tokens: List<PathToken>) : Iterable<PathToken> {
@JvmInline
public value class Path(public val tokens: List<PathToken>) : Iterable<PathToken> {
override fun iterator(): Iterator<PathToken> = tokens.iterator()

View File

@ -24,9 +24,8 @@ class ContextTest {
fun testPluginManager() {
val context = Global.buildContext{
name("test")
plugin(DummyPlugin())
}
context.plugins.load(DummyPlugin())
//Global.plugins.load(DummyPlugin())
val members = context.gather<Name>("test")
assertEquals(3, members.count())
members.forEach {

View File

@ -3,6 +3,7 @@ package space.kscience.dataforge.properties
import space.kscience.dataforge.meta.Scheme
import space.kscience.dataforge.meta.SchemeSpec
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.misc.DFExperimental
import kotlin.test.Test
import kotlin.test.assertEquals
@ -12,6 +13,7 @@ internal class TestScheme : Scheme() {
companion object : SchemeSpec<TestScheme>(::TestScheme)
}
@DFExperimental
class ItemPropertiesTest {
@Test
fun testBinding() {

View File

@ -658,7 +658,6 @@ public final class space/kscience/dataforge/meta/transformations/MetaTransformat
public static fun equals-impl (Ljava/util/Collection;Ljava/lang/Object;)Z
public static final fun equals-impl0 (Ljava/util/Collection;Ljava/util/Collection;)Z
public static final fun generate-impl (Ljava/util/Collection;Lspace/kscience/dataforge/meta/Meta;)Lspace/kscience/dataforge/meta/Meta;
public final fun getTransformations ()Ljava/util/Collection;
public fun hashCode ()I
public static fun hashCode-impl (Ljava/util/Collection;)I
public fun toString ()Ljava/lang/String;

View File

@ -3,6 +3,7 @@ package space.kscience.dataforge.meta.transformations
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.names.Name
import kotlin.jvm.JvmInline
/**
* A transformation for meta item or a group of items
@ -85,7 +86,8 @@ public data class RegexItemTransformationRule(
/**
* A set of [TransformationRule] to either transform static meta or create dynamically updated [MutableMeta]
*/
public inline class MetaTransformation(public val transformations: Collection<TransformationRule>) {
@JvmInline
public value class MetaTransformation(private val transformations: Collection<TransformationRule>) {
/**
* Produce new meta using only those items that match transformation rules

View File

@ -2,9 +2,11 @@ package space.kscience.dataforge.tables
import kotlinx.coroutines.flow.toList
import space.kscience.dataforge.meta.Meta
import kotlin.jvm.JvmInline
import kotlin.reflect.KType
public inline class MapRow<C : Any>(private val values: Map<String, C?>) : Row<C> {
@JvmInline
public value class MapRow<C : Any>(private val values: Map<String, C?>) : Row<C> {
override fun get(column: String): C? = values[column]
}

View File

@ -7,8 +7,8 @@ pluginManagement {
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}
val toolsVersion = "0.9.3"
val kotlinVersion = "1.4.32"
val toolsVersion = "0.9.4"
val kotlinVersion = "1.5.0-M2"
plugins {
id("ru.mipt.npm.gradle.project") version toolsVersion