Isolating build logic

This commit is contained in:
Alexander Nozik 2019-06-28 10:19:58 +03:00
parent 7f95dcf02c
commit 3bf49d3fae
14 changed files with 140 additions and 73 deletions

View File

@ -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 {
repositories {

View 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"
}

View File

@ -1,15 +1,10 @@
import com.jfrog.bintray.gradle.tasks.BintrayUploadTask
import org.gradle.api.Plugin
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.getValue
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
open class ScientifikMPPlugin : Plugin<Project> {
override fun apply(project: Project) {
@ -29,7 +24,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
kotlinOptions {
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "commonjs"
moduleKind = "umd"
}
}
}
@ -71,26 +66,11 @@ open class ScientifikMPPlugin : Plugin<Project> {
targets.all {
sourceSets.all {
languageSettings.progressiveMode = true
languageSettings.enableLanguageFeature("InlineClasses")
}
}
}
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"
})
}
}
languageSettings.apply{
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("ExperimentalUnsignedType")
}
}
}
}

View File

@ -19,11 +19,22 @@ import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask
open class ScientifikExtension {
var vcs = "https://github.com/altavir/dataforge-core"
var bintrayRepo = "dataforge"
var dokka = true
var vcs: String? = null
var bintrayRepo: String? = null
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> {
override fun apply(project: Project) {
@ -31,11 +42,16 @@ open class ScientifikPublishPlugin : Plugin<Project> {
project.plugins.apply("maven-publish")
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> {
repositories {
maven("https://bintray.com/mipt-npm/${extension.bintrayRepo}")
maven("https://bintray.com/mipt-npm/$bintrayRepo")
}
// Process each publication we have in this project
@ -45,7 +61,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(extension.vcs)
url.set(vcs)
licenses {
license {
@ -70,7 +86,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
}
}
if (extension.dokka) {
if (extension.kdoc) {
project.plugins.apply("org.jetbrains.dokka")
project.afterEvaluate {
@ -96,6 +112,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
path = sourceSets["jvmMain"].kotlin.srcDirs.first().toString()
platforms = listOf("JVM")
}
}
val kdocJar by tasks.registering(Jar::class) {
@ -113,6 +130,21 @@ open class ScientifikPublishPlugin : Plugin<Project> {
// Patch publications with fake javadoc
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
pkg.apply {
userOrg = "mipt-npm"
repo = extension.bintrayRepo
repo = bintrayRepo
name = project.name
issueTrackerUrl = "${extension.vcs}/issues"
setLicenses("Apache-2.0")

View File

@ -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"
}

View File

@ -4,7 +4,7 @@ plugins {
description = "Context and provider definitions"
val coroutinesVersion: String = Versions.coroutinesVersion
val coroutinesVersion: String = Scientifik.coroutinesVersion
kotlin {
sourceSets {

View File

@ -2,7 +2,7 @@ plugins {
id("scientifik.mpp")
}
val coroutinesVersion: String = Versions.coroutinesVersion
val coroutinesVersion: String = Scientifik.coroutinesVersion
kotlin {
jvm()

View File

@ -5,8 +5,8 @@ plugins {
description = "IO for meta"
val ioVersion: String = Versions.ioVersion
val serializationVersion: String = Versions.serializationVersion
val ioVersion: String = Scientifik.ioVersion
val serializationVersion: String = Scientifik.serializationVersion
kotlin {
jvm()

View File

@ -92,8 +92,7 @@ object BinaryMetaFormat : MetaFormat {
@Suppress("UNCHECKED_CAST")
private fun Input.readMetaItem(): MetaItem<MetaBuilder> {
val keyChar = readByte().toChar()
return when (keyChar) {
return when (val keyChar = readByte().toChar()) {
'S' -> MetaItem.ValueItem(StringValue(readString()))
'N' -> MetaItem.ValueItem(Null)
'+' -> MetaItem.ValueItem(True)
@ -120,6 +119,6 @@ object BinaryMetaFormat : MetaFormat {
MetaItem.NodeItem(meta)
}
else -> error("Unknown serialization key character: $keyChar")
} as MetaItem<MetaBuilder>
}
}
}

View File

@ -4,3 +4,6 @@ plugins {
description = "Meta definition and basic operations on meta"
scientifik{
}

View File

@ -1,5 +1,6 @@
package hep.dataforge.meta
import hep.dataforge.values.DoubleArrayValue
import hep.dataforge.values.Null
import hep.dataforge.values.Value
import kotlin.jvm.JvmName
@ -13,8 +14,13 @@ import kotlin.jvm.JvmName
fun Configurable.value(default: Any = Null, key: String? = null): MutableValueDelegate<Config> =
MutableValueDelegate(config, key, Value.of(default))
fun <T> Configurable.value(default: T? = null, key: String? = null, transform: (Value?) -> T): ReadWriteDelegateWrapper<Value?, T> =
MutableValueDelegate(config, key, default?.let { Value.of(it)}).transform(reader = transform)
fun <T> Configurable.value(
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> =
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) =
MutableMorphDelegate(config, key) { specification(builder).wrap(it) }
/*
* 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>> =
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) =
MutableMorphDelegate(config, key, converter)

View File

@ -113,8 +113,11 @@ class SafeEnumDelegate<E : Enum<E>>(
//Child node delegate
class ChildDelegate<T>(val meta: Meta, private val key: String? = null, private val converter: (Meta) -> T) :
ReadOnlyProperty<Any?, T?> {
class ChildDelegate<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? {
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) }
fun <T : Metoid> Metoid.child(key: String? = null, converter: (Meta) -> T) = ChildDelegate(meta, key, converter)
/* Read-write delegates */
class MutableValueDelegate<M : MutableMeta<M>>(

View File

@ -110,6 +110,8 @@ object False : Value {
override val type: ValueType get() = ValueType.BOOLEAN
override val number: Number get() = -1.0
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())
@ -206,9 +208,6 @@ fun String.asValue(): Value = StringValue(this)
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 LongArray.asValue(): Value = ListValue(map{NumberValue(it)})
@ -254,16 +253,3 @@ fun String.parseValue(): Value {
//Give up and return a StringValue
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()
}

View File

@ -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)