Isolating build logic
This commit is contained in:
parent
7f95dcf02c
commit
3bf49d3fae
@ -1,4 +1,7 @@
|
|||||||
val dataforgeVersion by extra("0.1.3-dev-6")
|
val dataforgeVersion by extra("0.1.3-dev-7")
|
||||||
|
|
||||||
|
val bintrayRepo by extra("dataforge")
|
||||||
|
val vcs by extra("https://github.com/mipt-npm/dataforge-core")
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
9
buildSrc/src/main/kotlin/Scientifik.kt
Normal file
9
buildSrc/src/main/kotlin/Scientifik.kt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* Build constants
|
||||||
|
*/
|
||||||
|
object Scientifik {
|
||||||
|
val ioVersion = "0.1.10"
|
||||||
|
val coroutinesVersion = "1.2.2"
|
||||||
|
val atomicfuVersion = "0.12.9"
|
||||||
|
val serializationVersion = "0.11.1"
|
||||||
|
}
|
@ -1,15 +1,10 @@
|
|||||||
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
|
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.publish.PublishingExtension
|
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
|
||||||
import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact
|
|
||||||
import org.gradle.kotlin.dsl.configure
|
import org.gradle.kotlin.dsl.configure
|
||||||
import org.gradle.kotlin.dsl.getValue
|
import org.gradle.kotlin.dsl.getValue
|
||||||
import org.gradle.kotlin.dsl.getting
|
import org.gradle.kotlin.dsl.getting
|
||||||
import org.gradle.kotlin.dsl.invoke
|
import org.gradle.kotlin.dsl.invoke
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
|
|
||||||
|
|
||||||
open class ScientifikMPPlugin : Plugin<Project> {
|
open class ScientifikMPPlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
@ -29,7 +24,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
|
|||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
sourceMap = true
|
sourceMap = true
|
||||||
sourceMapEmbedSources = "always"
|
sourceMapEmbedSources = "always"
|
||||||
moduleKind = "commonjs"
|
moduleKind = "umd"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,25 +66,10 @@ open class ScientifikMPPlugin : Plugin<Project> {
|
|||||||
|
|
||||||
targets.all {
|
targets.all {
|
||||||
sourceSets.all {
|
sourceSets.all {
|
||||||
languageSettings.progressiveMode = true
|
languageSettings.apply{
|
||||||
languageSettings.enableLanguageFeature("InlineClasses")
|
progressiveMode = true
|
||||||
}
|
enableLanguageFeature("InlineClasses")
|
||||||
}
|
useExperimentalAnnotation("ExperimentalUnsignedType")
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
project.tasks.filter { it is ArtifactoryTask || it is BintrayUploadTask }.forEach {
|
|
||||||
it.doFirst {
|
|
||||||
project.configure<PublishingExtension> {
|
|
||||||
publications
|
|
||||||
.filterIsInstance<MavenPublication>()
|
|
||||||
.forEach { publication ->
|
|
||||||
val moduleFile = project.buildDir.resolve("publications/${publication.name}/module.json")
|
|
||||||
if (moduleFile.exists()) {
|
|
||||||
publication.artifact(object : FileBasedMavenArtifact(moduleFile) {
|
|
||||||
override fun getDefaultExtension() = "module"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,22 @@ import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
|
|||||||
|
|
||||||
|
|
||||||
open class ScientifikExtension {
|
open class ScientifikExtension {
|
||||||
var vcs = "https://github.com/altavir/dataforge-core"
|
var vcs: String? = null
|
||||||
var bintrayRepo = "dataforge"
|
var bintrayRepo: String? = null
|
||||||
var dokka = true
|
var kdoc: Boolean = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recursively search up the project chain for configuration
|
||||||
|
private val Project.bintrayRepo: String?
|
||||||
|
get() = extensions.findByType<ScientifikExtension>()?.bintrayRepo
|
||||||
|
?: parent?.bintrayRepo
|
||||||
|
?: (findProperty("bintrayRepo") as? String)
|
||||||
|
|
||||||
|
private val Project.vcs: String?
|
||||||
|
get() = extensions.findByType<ScientifikExtension>()?.vcs
|
||||||
|
?: parent?.vcs
|
||||||
|
?: (findProperty("vcs") as? String)
|
||||||
|
|
||||||
open class ScientifikPublishPlugin : Plugin<Project> {
|
open class ScientifikPublishPlugin : Plugin<Project> {
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
@ -31,11 +42,16 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
project.plugins.apply("maven-publish")
|
project.plugins.apply("maven-publish")
|
||||||
val extension = project.extensions.create<ScientifikExtension>("scientifik")
|
val extension = project.extensions.create<ScientifikExtension>("scientifik")
|
||||||
|
|
||||||
|
val bintrayRepo = project.bintrayRepo
|
||||||
|
val vcs = project.vcs
|
||||||
|
|
||||||
|
if (bintrayRepo == null || vcs == null) {
|
||||||
|
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
|
||||||
|
}
|
||||||
|
|
||||||
project.configure<PublishingExtension> {
|
project.configure<PublishingExtension> {
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://bintray.com/mipt-npm/${extension.bintrayRepo}")
|
maven("https://bintray.com/mipt-npm/$bintrayRepo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process each publication we have in this project
|
// Process each publication we have in this project
|
||||||
@ -45,7 +61,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
publication.pom {
|
publication.pom {
|
||||||
name.set(project.name)
|
name.set(project.name)
|
||||||
description.set(project.description)
|
description.set(project.description)
|
||||||
url.set(extension.vcs)
|
url.set(vcs)
|
||||||
|
|
||||||
licenses {
|
licenses {
|
||||||
license {
|
license {
|
||||||
@ -70,7 +86,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extension.dokka) {
|
if (extension.kdoc) {
|
||||||
project.plugins.apply("org.jetbrains.dokka")
|
project.plugins.apply("org.jetbrains.dokka")
|
||||||
|
|
||||||
project.afterEvaluate {
|
project.afterEvaluate {
|
||||||
@ -96,6 +112,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
path = sourceSets["jvmMain"].kotlin.srcDirs.first().toString()
|
path = sourceSets["jvmMain"].kotlin.srcDirs.first().toString()
|
||||||
platforms = listOf("JVM")
|
platforms = listOf("JVM")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val kdocJar by tasks.registering(Jar::class) {
|
val kdocJar by tasks.registering(Jar::class) {
|
||||||
@ -113,6 +130,21 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
// Patch publications with fake javadoc
|
// Patch publications with fake javadoc
|
||||||
publication.artifact(kdocJar.get())
|
publication.artifact(kdocJar.get())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.filter { it is ArtifactoryTask || it is BintrayUploadTask }.forEach {
|
||||||
|
it.doFirst {
|
||||||
|
publications.filterIsInstance<MavenPublication>()
|
||||||
|
.forEach { publication ->
|
||||||
|
val moduleFile =
|
||||||
|
buildDir.resolve("publications/${publication.name}/module.json")
|
||||||
|
if (moduleFile.exists()) {
|
||||||
|
publication.artifact(object : FileBasedMavenArtifact(moduleFile) {
|
||||||
|
override fun getDefaultExtension() = "module"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +184,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
|
|||||||
// this is a problem of this plugin
|
// this is a problem of this plugin
|
||||||
pkg.apply {
|
pkg.apply {
|
||||||
userOrg = "mipt-npm"
|
userOrg = "mipt-npm"
|
||||||
repo = extension.bintrayRepo
|
repo = bintrayRepo
|
||||||
name = project.name
|
name = project.name
|
||||||
issueTrackerUrl = "${extension.vcs}/issues"
|
issueTrackerUrl = "${extension.vcs}/issues"
|
||||||
setLicenses("Apache-2.0")
|
setLicenses("Apache-2.0")
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
// Instead of defining runtime properties and use them dynamically
|
|
||||||
// define version in buildSrc and have autocompletion and compile-time check
|
|
||||||
// Also dependencies itself can be moved here
|
|
||||||
object Versions {
|
|
||||||
val ioVersion = "0.1.10"
|
|
||||||
val coroutinesVersion = "1.2.2"
|
|
||||||
val atomicfuVersion = "0.12.9"
|
|
||||||
val serializationVersion = "0.11.1"
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ plugins {
|
|||||||
|
|
||||||
description = "Context and provider definitions"
|
description = "Context and provider definitions"
|
||||||
|
|
||||||
val coroutinesVersion: String = Versions.coroutinesVersion
|
val coroutinesVersion: String = Scientifik.coroutinesVersion
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
@ -2,7 +2,7 @@ plugins {
|
|||||||
id("scientifik.mpp")
|
id("scientifik.mpp")
|
||||||
}
|
}
|
||||||
|
|
||||||
val coroutinesVersion: String = Versions.coroutinesVersion
|
val coroutinesVersion: String = Scientifik.coroutinesVersion
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm()
|
||||||
|
@ -5,8 +5,8 @@ plugins {
|
|||||||
description = "IO for meta"
|
description = "IO for meta"
|
||||||
|
|
||||||
|
|
||||||
val ioVersion: String = Versions.ioVersion
|
val ioVersion: String = Scientifik.ioVersion
|
||||||
val serializationVersion: String = Versions.serializationVersion
|
val serializationVersion: String = Scientifik.serializationVersion
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm()
|
||||||
|
@ -92,8 +92,7 @@ object BinaryMetaFormat : MetaFormat {
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun Input.readMetaItem(): MetaItem<MetaBuilder> {
|
private fun Input.readMetaItem(): MetaItem<MetaBuilder> {
|
||||||
val keyChar = readByte().toChar()
|
return when (val keyChar = readByte().toChar()) {
|
||||||
return when (keyChar) {
|
|
||||||
'S' -> MetaItem.ValueItem(StringValue(readString()))
|
'S' -> MetaItem.ValueItem(StringValue(readString()))
|
||||||
'N' -> MetaItem.ValueItem(Null)
|
'N' -> MetaItem.ValueItem(Null)
|
||||||
'+' -> MetaItem.ValueItem(True)
|
'+' -> MetaItem.ValueItem(True)
|
||||||
@ -120,6 +119,6 @@ object BinaryMetaFormat : MetaFormat {
|
|||||||
MetaItem.NodeItem(meta)
|
MetaItem.NodeItem(meta)
|
||||||
}
|
}
|
||||||
else -> error("Unknown serialization key character: $keyChar")
|
else -> error("Unknown serialization key character: $keyChar")
|
||||||
} as MetaItem<MetaBuilder>
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,3 +4,6 @@ plugins {
|
|||||||
|
|
||||||
description = "Meta definition and basic operations on meta"
|
description = "Meta definition and basic operations on meta"
|
||||||
|
|
||||||
|
scientifik{
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package hep.dataforge.meta
|
package hep.dataforge.meta
|
||||||
|
|
||||||
|
import hep.dataforge.values.DoubleArrayValue
|
||||||
import hep.dataforge.values.Null
|
import hep.dataforge.values.Null
|
||||||
import hep.dataforge.values.Value
|
import hep.dataforge.values.Value
|
||||||
import kotlin.jvm.JvmName
|
import kotlin.jvm.JvmName
|
||||||
@ -13,8 +14,13 @@ import kotlin.jvm.JvmName
|
|||||||
fun Configurable.value(default: Any = Null, key: String? = null): MutableValueDelegate<Config> =
|
fun Configurable.value(default: Any = Null, key: String? = null): MutableValueDelegate<Config> =
|
||||||
MutableValueDelegate(config, key, Value.of(default))
|
MutableValueDelegate(config, key, Value.of(default))
|
||||||
|
|
||||||
fun <T> Configurable.value(default: T? = null, key: String? = null, transform: (Value?) -> T): ReadWriteDelegateWrapper<Value?, T> =
|
fun <T> Configurable.value(
|
||||||
MutableValueDelegate(config, key, default?.let { Value.of(it)}).transform(reader = transform)
|
default: T? = null,
|
||||||
|
key: String? = null,
|
||||||
|
writer: (T) -> Value = { Value.of(it) },
|
||||||
|
reader: (Value?) -> T
|
||||||
|
): ReadWriteDelegateWrapper<Value?, T> =
|
||||||
|
MutableValueDelegate(config, key, default?.let { Value.of(it) }).transform(reader = reader, writer = writer)
|
||||||
|
|
||||||
fun Configurable.string(default: String? = null, key: String? = null): MutableStringDelegate<Config> =
|
fun Configurable.string(default: String? = null, key: String? = null): MutableStringDelegate<Config> =
|
||||||
MutableStringDelegate(config, key, default)
|
MutableStringDelegate(config, key, default)
|
||||||
@ -106,7 +112,6 @@ fun <T : Specific> Configurable.spec(spec: Specification<T>, key: String? = null
|
|||||||
fun <T : Specific> Configurable.spec(builder: (Config) -> T, key: String? = null) =
|
fun <T : Specific> Configurable.spec(builder: (Config) -> T, key: String? = null) =
|
||||||
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
|
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extra delegates for special cases
|
* Extra delegates for special cases
|
||||||
*/
|
*/
|
||||||
@ -117,7 +122,15 @@ fun Configurable.stringList(key: String? = null): ReadWriteDelegateWrapper<Value
|
|||||||
fun Configurable.numberList(key: String? = null): ReadWriteDelegateWrapper<Value?, List<Number>> =
|
fun Configurable.numberList(key: String? = null): ReadWriteDelegateWrapper<Value?, List<Number>> =
|
||||||
value(emptyList(), key) { it?.list?.map { value -> value.number } ?: emptyList() }
|
value(emptyList(), key) { it?.list?.map { value -> value.number } ?: emptyList() }
|
||||||
|
|
||||||
fun <T : Metoid> Metoid.child(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter)
|
/**
|
||||||
|
* A special delegate for double arrays
|
||||||
|
*/
|
||||||
|
fun Configurable.doubleArray(key: String? = null): ReadWriteDelegateWrapper<Value?, DoubleArray> =
|
||||||
|
value(doubleArrayOf(), key) {
|
||||||
|
(it as? DoubleArrayValue)?.value
|
||||||
|
?: it?.list?.map { value -> value.number.toDouble() }?.toDoubleArray()
|
||||||
|
?: doubleArrayOf()
|
||||||
|
}
|
||||||
|
|
||||||
fun <T : Configurable> Configurable.child(key: String? = null, converter: (Meta) -> T) =
|
fun <T : Configurable> Configurable.child(key: String? = null, converter: (Meta) -> T) =
|
||||||
MutableMorphDelegate(config, key, converter)
|
MutableMorphDelegate(config, key, converter)
|
@ -113,8 +113,11 @@ class SafeEnumDelegate<E : Enum<E>>(
|
|||||||
|
|
||||||
//Child node delegate
|
//Child node delegate
|
||||||
|
|
||||||
class ChildDelegate<T>(val meta: Meta, private val key: String? = null, private val converter: (Meta) -> T) :
|
class ChildDelegate<T>(
|
||||||
ReadOnlyProperty<Any?, T?> {
|
val meta: Meta,
|
||||||
|
private val key: String? = null,
|
||||||
|
private val converter: (Meta) -> T
|
||||||
|
) : ReadOnlyProperty<Any?, T?> {
|
||||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||||
return meta[key ?: property.name]?.node?.let { converter(it) }
|
return meta[key ?: property.name]?.node?.let { converter(it) }
|
||||||
}
|
}
|
||||||
@ -164,6 +167,8 @@ inline fun <reified E : Enum<E>> Meta.enum(default: E, key: String? = null) =
|
|||||||
SafeEnumDelegate(this, key, default) { enumValueOf(it) }
|
SafeEnumDelegate(this, key, default) { enumValueOf(it) }
|
||||||
|
|
||||||
|
|
||||||
|
fun <T : Metoid> Metoid.child(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter)
|
||||||
|
|
||||||
/* Read-write delegates */
|
/* Read-write delegates */
|
||||||
|
|
||||||
class MutableValueDelegate<M : MutableMeta<M>>(
|
class MutableValueDelegate<M : MutableMeta<M>>(
|
@ -110,6 +110,8 @@ object False : Value {
|
|||||||
override val type: ValueType get() = ValueType.BOOLEAN
|
override val type: ValueType get() = ValueType.BOOLEAN
|
||||||
override val number: Number get() = -1.0
|
override val number: Number get() = -1.0
|
||||||
override val string: String get() = "false"
|
override val string: String get() = "false"
|
||||||
|
|
||||||
|
override fun toString(): String = True.value.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val Value.boolean get() = this == True || this.list.firstOrNull() == True || (type == ValueType.STRING && string.toBoolean())
|
val Value.boolean get() = this == True || this.list.firstOrNull() == True || (type == ValueType.STRING && string.toBoolean())
|
||||||
@ -206,9 +208,6 @@ fun String.asValue(): Value = StringValue(this)
|
|||||||
|
|
||||||
fun Iterable<Value>.asValue(): Value = ListValue(this.toList())
|
fun Iterable<Value>.asValue(): Value = ListValue(this.toList())
|
||||||
|
|
||||||
//TODO maybe optimized storage performance
|
|
||||||
fun DoubleArray.asValue(): Value = ListValue(map{NumberValue(it)})
|
|
||||||
|
|
||||||
fun IntArray.asValue(): Value = ListValue(map{NumberValue(it)})
|
fun IntArray.asValue(): Value = ListValue(map{NumberValue(it)})
|
||||||
|
|
||||||
fun LongArray.asValue(): Value = ListValue(map{NumberValue(it)})
|
fun LongArray.asValue(): Value = ListValue(map{NumberValue(it)})
|
||||||
@ -254,16 +253,3 @@ fun String.parseValue(): Value {
|
|||||||
//Give up and return a StringValue
|
//Give up and return a StringValue
|
||||||
return StringValue(this)
|
return StringValue(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
class LazyParsedValue(override val string: String) : Value {
|
|
||||||
private val parsedValue by lazy { string.parseValue() }
|
|
||||||
|
|
||||||
override val value: Any?
|
|
||||||
get() = parsedValue.value
|
|
||||||
override val type: ValueType
|
|
||||||
get() = parsedValue.type
|
|
||||||
override val number: Number
|
|
||||||
get() = parsedValue.number
|
|
||||||
|
|
||||||
override fun toString(): String = value.toString()
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
package hep.dataforge.values
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value built from string which content and type are parsed on-demand
|
||||||
|
*/
|
||||||
|
class LazyParsedValue(override val string: String) : Value {
|
||||||
|
private val parsedValue by lazy { string.parseValue() }
|
||||||
|
|
||||||
|
override val value: Any? get() = parsedValue.value
|
||||||
|
override val type: ValueType get() = parsedValue.type
|
||||||
|
override val number: Number get() = parsedValue.number
|
||||||
|
|
||||||
|
override fun toString(): String = string
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.lazyParseValue(): LazyParsedValue = LazyParsedValue(this)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A performance optimized version of list value for doubles
|
||||||
|
*/
|
||||||
|
class DoubleArrayValue(override val value: DoubleArray) : Value {
|
||||||
|
override val type: ValueType get() = ValueType.NUMBER
|
||||||
|
override val number: Double get() = value.first()
|
||||||
|
override val string: String get() = value.first().toString()
|
||||||
|
override val list: List<Value> get() = value.map { NumberValue(it) }
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is Value) return false
|
||||||
|
|
||||||
|
return if (other is DoubleArrayValue) {
|
||||||
|
value.contentEquals(other.value)
|
||||||
|
} else {
|
||||||
|
list == other.list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return value.contentHashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun DoubleArray.asValue(): DoubleArrayValue = DoubleArrayValue(this)
|
Loading…
Reference in New Issue
Block a user