Fix bug in plugin isAttached
This commit is contained in:
parent
f83b759e75
commit
58c5355e25
@ -9,7 +9,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "space.kscience"
|
group = "space.kscience"
|
||||||
version = "0.6.1-dev-2"
|
version = "0.6.1-dev-3"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
@ -11,7 +11,7 @@ public abstract class AbstractPlugin(override val meta: Meta = Meta.EMPTY) : Plu
|
|||||||
private var _context: Context? = null
|
private var _context: Context? = null
|
||||||
private val dependencies = HashMap<PluginFactory<*>, Meta>()
|
private val dependencies = HashMap<PluginFactory<*>, Meta>()
|
||||||
|
|
||||||
override val isAttached: Boolean = _context != null
|
override val isAttached: Boolean get() = _context != null
|
||||||
|
|
||||||
override val context: Context
|
override val context: Context
|
||||||
get() = _context ?: error("Plugin $tag is not attached")
|
get() = _context ?: error("Plugin $tag is not attached")
|
||||||
|
@ -15,7 +15,7 @@ kscience {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api(projects.dataforgeIo)
|
api(projects.dataforgeIo)
|
||||||
}
|
}
|
||||||
useSerialization("1.4.1"){
|
useSerialization{
|
||||||
yamlKt()
|
yamlKt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ public fun YamlMap.toMeta(): Meta = YamlMeta(this)
|
|||||||
public class YamlMetaFormat(private val meta: Meta) : MetaFormat {
|
public class YamlMetaFormat(private val meta: Meta) : MetaFormat {
|
||||||
|
|
||||||
override fun writeMeta(output: Output, meta: Meta, descriptor: MetaDescriptor?) {
|
override fun writeMeta(output: Output, meta: Meta, descriptor: MetaDescriptor?) {
|
||||||
val yaml = meta.toYaml()
|
val yaml: YamlMap = meta.toYaml()
|
||||||
val string = Yaml.encodeToString(yaml)
|
val string = Yaml.encodeToString(YamlMap.serializer(), yaml)
|
||||||
output.writeUtf8String(string)
|
output.writeUtf8String(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package space.kscience.dataforge.io
|
package space.kscience.dataforge.io
|
||||||
|
|
||||||
import io.ktor.utils.io.core.Input
|
import io.ktor.utils.io.core.*
|
||||||
import io.ktor.utils.io.core.Output
|
|
||||||
import io.ktor.utils.io.core.readDouble
|
|
||||||
import io.ktor.utils.io.core.writeDouble
|
|
||||||
import space.kscience.dataforge.context.Context
|
import space.kscience.dataforge.context.Context
|
||||||
import space.kscience.dataforge.context.Factory
|
import space.kscience.dataforge.context.Factory
|
||||||
import space.kscience.dataforge.io.IOFormatFactory.Companion.IO_FORMAT_TYPE
|
import space.kscience.dataforge.io.IOFormatFactory.Companion.IO_FORMAT_TYPE
|
||||||
@ -27,6 +24,19 @@ public interface IOReader<out T> {
|
|||||||
public fun readObject(input: Input): T
|
public fun readObject(input: Input): T
|
||||||
|
|
||||||
public fun readObject(binary: Binary): T = binary.read { readObject(this) }
|
public fun readObject(binary: Binary): T = binary.read { readObject(this) }
|
||||||
|
|
||||||
|
public companion object {
|
||||||
|
/**
|
||||||
|
* no-op reader for binaries.
|
||||||
|
*/
|
||||||
|
public val binary: IOReader<Binary> = object : IOReader<Binary> {
|
||||||
|
override val type: KType = typeOf<Binary>()
|
||||||
|
|
||||||
|
override fun readObject(input: Input): Binary = input.readBytes().asBinary()
|
||||||
|
|
||||||
|
override fun readObject(binary: Binary): Binary = binary
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public inline fun <reified T> IOReader(crossinline read: Input.() -> T): IOReader<T> = object : IOReader<T> {
|
public inline fun <reified T> IOReader(crossinline read: Input.() -> T): IOReader<T> = object : IOReader<T> {
|
||||||
|
@ -36,11 +36,14 @@ import kotlin.reflect.typeOf
|
|||||||
|
|
||||||
public typealias FileFormatResolver<T> = (path: Path, meta: Meta) -> IOReader<T>
|
public typealias FileFormatResolver<T> = (path: Path, meta: Meta) -> IOReader<T>
|
||||||
|
|
||||||
public class FileData<T> internal constructor(private val data: Data<T>) : Data<T> by data {
|
/**
|
||||||
|
* A data based on a filesystem [Path]
|
||||||
public val path: String? get() = meta[META_FILE_PATH_KEY].string
|
*/
|
||||||
public val extension: String? get() = meta[META_FILE_EXTENSION_KEY].string
|
public class FileData<T> internal constructor(private val data: Data<T>, public val path: Path) : Data<T> by data {
|
||||||
|
|
||||||
|
// public val path: String? get() = meta[META_FILE_PATH_KEY].string
|
||||||
|
// public val extension: String? get() = meta[META_FILE_EXTENSION_KEY].string
|
||||||
|
//
|
||||||
public val createdTime: Instant? get() = meta[META_FILE_CREATE_TIME_KEY].string?.let { Instant.parse(it) }
|
public val createdTime: Instant? get() = meta[META_FILE_CREATE_TIME_KEY].string?.let { Instant.parse(it) }
|
||||||
public val updatedTime: Instant? get() = meta[META_FILE_UPDATE_TIME_KEY].string?.let { Instant.parse(it) }
|
public val updatedTime: Instant? get() = meta[META_FILE_UPDATE_TIME_KEY].string?.let { Instant.parse(it) }
|
||||||
|
|
||||||
@ -74,9 +77,12 @@ public fun <T : Any> IOPlugin.readDataFile(
|
|||||||
FileData.META_FILE_UPDATE_TIME_KEY put attributes.lastModifiedTime().toInstant().toString()
|
FileData.META_FILE_UPDATE_TIME_KEY put attributes.lastModifiedTime().toInstant().toString()
|
||||||
FileData.META_FILE_CREATE_TIME_KEY put attributes.creationTime().toInstant().toString()
|
FileData.META_FILE_CREATE_TIME_KEY put attributes.creationTime().toInstant().toString()
|
||||||
}
|
}
|
||||||
return FileData(Data(format.type, updatedMeta) {
|
return FileData(
|
||||||
envelope.data?.readWith(format) ?: error("Can't convert envelope without content to Data")
|
Data(format.type, updatedMeta) {
|
||||||
})
|
envelope.data?.readWith(format) ?: error("Can't convert envelope without content to Data")
|
||||||
|
},
|
||||||
|
path
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,7 +128,15 @@ public fun <T : Any> IOPlugin.readDataDirectory(
|
|||||||
public inline fun <reified T : Any> IOPlugin.readDataDirectory(
|
public inline fun <reified T : Any> IOPlugin.readDataDirectory(
|
||||||
path: Path,
|
path: Path,
|
||||||
noinline formatResolver: FileFormatResolver<T>,
|
noinline formatResolver: FileFormatResolver<T>,
|
||||||
): DataTree<Any> = readDataDirectory(typeOf<T>(), path, formatResolver)
|
): DataTree<T> = readDataDirectory(typeOf<T>(), path, formatResolver)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read raw binary data tree from the directory. All files are read as-is (save for meta files).
|
||||||
|
*/
|
||||||
|
@DFExperimental
|
||||||
|
public fun IOPlugin.readRawDirectory(
|
||||||
|
path: Path,
|
||||||
|
): DataTree<Binary> = readDataDirectory(path) { _, _ -> IOReader.binary }
|
||||||
|
|
||||||
|
|
||||||
@OptIn(DFExperimental::class)
|
@OptIn(DFExperimental::class)
|
||||||
@ -205,6 +219,7 @@ public suspend fun <T : Any> IOPlugin.writeDataDirectory(
|
|||||||
is DataTreeItem.Node -> {
|
is DataTreeItem.Node -> {
|
||||||
writeDataDirectory(childPath, item.tree, format, envelopeFormat)
|
writeDataDirectory(childPath, item.tree, format, envelopeFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
is DataTreeItem.Leaf -> {
|
is DataTreeItem.Leaf -> {
|
||||||
val envelope = item.data.toEnvelope(format)
|
val envelope = item.data.toEnvelope(format)
|
||||||
if (envelopeFormat != null) {
|
if (envelopeFormat != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user