diff --git a/build.gradle.kts b/build.gradle.kts index 518b4eb7..d8c6a93a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,4 @@ -val dataforgeVersion by extra("0.1.2-dev-6") +val dataforgeVersion by extra("0.1.2-dev-7") allprojects { repositories { diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/AbstractPlugin.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/AbstractPlugin.kt index 8864fae1..4c1e86d1 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/AbstractPlugin.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/AbstractPlugin.kt @@ -1,16 +1,15 @@ package hep.dataforge.context -import hep.dataforge.meta.Config +import hep.dataforge.meta.EmptyMeta +import hep.dataforge.meta.Meta import hep.dataforge.names.Name -abstract class AbstractPlugin : Plugin { +abstract class AbstractPlugin(override val meta: Meta = EmptyMeta) : Plugin { private var _context: Context? = null override val context: Context get() = _context ?: error("Plugin $tag is not attached") - override val config = Config() - override fun attach(context: Context) { this._context = context } @@ -19,8 +18,6 @@ abstract class AbstractPlugin : Plugin { this._context = null } - //TODO make configuration activation-safe - override fun provideTop(target: String, name: Name): Any? = null override fun listTop(target: String): Sequence = emptySequence() diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/ContextBuilder.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/ContextBuilder.kt index 52079854..203edd2c 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/ContextBuilder.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/ContextBuilder.kt @@ -1,8 +1,7 @@ package hep.dataforge.context -import hep.dataforge.meta.Config import hep.dataforge.meta.MetaBuilder -import hep.dataforge.meta.configure +import hep.dataforge.meta.buildMeta /** * A convenience builder for context @@ -19,11 +18,11 @@ class ContextBuilder(var name: String = "@anonimous", val parent: Context = Glob plugins.add(plugin) } - fun plugin(tag: PluginTag, action: Config.() -> Unit) { - plugins.add(PluginRepository.fetch(tag).configure(action)) + fun plugin(tag: PluginTag, action: MetaBuilder.() -> Unit) { + plugins.add(PluginRepository.fetch(tag, buildMeta(action))) } - fun plugin(name: String, group: String = "", version: String = "", action: Config.() -> Unit) { + fun plugin(name: String, group: String = "", version: String = "", action: MetaBuilder.() -> Unit) { plugin(PluginTag(name, group, version), action) } diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Plugin.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Plugin.kt index 4560e29b..e06bf3f9 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Plugin.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/Plugin.kt @@ -1,6 +1,5 @@ package hep.dataforge.context -import hep.dataforge.meta.Configurable import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaRepr import hep.dataforge.meta.buildMeta @@ -22,7 +21,7 @@ import hep.dataforge.provider.Provider * * @author Alexander Nozik */ -interface Plugin : Named, ContextAware, Provider, MetaRepr, Configurable { +interface Plugin : Named, ContextAware, Provider, MetaRepr { /** * Get tag for this plugin @@ -31,13 +30,14 @@ interface Plugin : Named, ContextAware, Provider, MetaRepr, Configurable { */ val tag: PluginTag + val meta: Meta + /** * The name of this plugin ignoring version and group * * @return */ - override val name: String - get() = tag.name + override val name: String get() = tag.name /** * Plugin dependencies which are required to attach this plugin. Plugin @@ -67,7 +67,7 @@ interface Plugin : Named, ContextAware, Provider, MetaRepr, Configurable { "context" to context.name "type" to this::class.simpleName "tag" to tag - "meta" to config + "meta" to meta } companion object { diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginManager.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginManager.kt index c504394b..bcce8eb6 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginManager.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginManager.kt @@ -116,7 +116,7 @@ class PluginManager(override val context: Context) : ContextAware, Iterable load(PluginRepository.fetch(tag,meta)) - loaded.config == meta -> loaded // if meta is the same, return existing plugin + loaded.meta == meta -> loaded // if meta is the same, return existing plugin else -> throw RuntimeException("Can't load plugin with tag $tag. Plugin with this tag and different configuration already exists in context.") } } @@ -125,7 +125,7 @@ class PluginManager(override val context: Context) : ContextAware, Iterable load(factory(meta)) - loaded.config == meta -> loaded // if meta is the same, return existing plugin + loaded.meta == meta -> loaded // if meta is the same, return existing plugin else -> throw RuntimeException("Can't load plugin with tag ${factory.tag}. Plugin with this tag and different configuration already exists in context.") } } @@ -146,7 +146,7 @@ class PluginManager(override val context: Context) : ContextAware, Iterable loaded // if meta is the same, return existing plugin + loaded.meta == meta -> loaded // if meta is the same, return existing plugin else -> throw RuntimeException("Can't load plugin with type $type. Plugin with this type and different configuration already exists in context.") } } diff --git a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginRepository.kt b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginRepository.kt index 8a560fda..eb715f80 100644 --- a/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginRepository.kt +++ b/dataforge-context/src/commonMain/kotlin/hep/dataforge/context/PluginRepository.kt @@ -2,18 +2,14 @@ package hep.dataforge.context import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.Meta -import hep.dataforge.meta.configure import kotlin.reflect.KClass interface PluginFactory { val tag: PluginTag val type: KClass - operator fun invoke(): T + operator fun invoke(meta: Meta = EmptyMeta): T } -operator fun PluginFactory<*>.invoke(meta: Meta) = invoke().configure(meta) - - expect object PluginRepository { fun register(factory: PluginFactory<*>) @@ -29,26 +25,25 @@ expect object PluginRepository { * Fetch specific plugin and instantiate it with given meta */ fun PluginRepository.fetch(tag: PluginTag, meta: Meta = EmptyMeta): Plugin = - PluginRepository.list().find { it.tag.matches(tag) }?.invoke(meta) - ?: error("Plugin with tag $tag not found in the repository") + list().find { it.tag.matches(tag) }?.invoke(meta) ?: error("Plugin with tag $tag not found in the repository") fun PluginRepository.register( tag: PluginTag, type: KClass, - constructor: () -> T + constructor: (Meta) -> T ): PluginFactory { val factory = object : PluginFactory { override val tag: PluginTag = tag override val type: KClass = type - override fun invoke(): T = constructor() + override fun invoke(meta: Meta): T = constructor(meta) } - PluginRepository.register(factory) + register(factory) return factory } -inline fun PluginRepository.register(tag: PluginTag, noinline constructor: () -> T) = +inline fun PluginRepository.register(tag: PluginTag, noinline constructor: (Meta) -> T) = register(tag, T::class, constructor) fun PluginRepository.register(plugin: Plugin) = register(plugin.tag, plugin::class) { plugin } \ No newline at end of file diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt index 229598e4..9179f16e 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/names/Name.kt @@ -61,6 +61,7 @@ data class NameToken(val body: String, val index: String = "") { } fun String.toName(): Name { + if (isBlank()) return EmptyName val tokens = sequence { var bodyBuilder = StringBuilder() var queryBuilder = StringBuilder() diff --git a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt index 4e11e23e..47d9f59c 100644 --- a/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt +++ b/dataforge-output/src/commonMain/kotlin/hep/dataforge/output/OutputManager.kt @@ -67,7 +67,7 @@ class ConsoleOutputManager : AbstractPlugin(), OutputManager { override val type = ConsoleOutputManager::class - override fun invoke() = ConsoleOutputManager() + override fun invoke(meta:Meta) = ConsoleOutputManager() } }