From ca8ec1f89f06a62bf51617a6093da64bd970af85 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 30 Jan 2021 17:17:39 +0300 Subject: [PATCH] Suppress API validation for experimental modules --- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 71 -------------- .../npm/gradle/KScienceReadmeExtension.kt | 97 +++++++++++++++++++ 2 files changed, 97 insertions(+), 71 deletions(-) create mode 100644 src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index 6fe1644..c5ccd8f 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -8,7 +8,6 @@ import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaTask -import java.io.File import kotlin.collections.component1 import kotlin.collections.component2 @@ -25,76 +24,6 @@ class KSciencePublishingExtension(val project: Project) { var bintrayRepo: String? by project.extra } -enum class Maturity { - PROTOTYPE, - EXPERIMENTAL, - DEVELOPMENT, - PRODUCTION -} - -class KScienceReadmeExtension(val project: Project) { - var description: String = "" - var maturity: Maturity = Maturity.EXPERIMENTAL - - var readmeTemplate: File = project.file("docs/README-TEMPLATE.md") - - data class Feature(val id: String, val ref: String, val description: String, val name: String = id) - - val features = ArrayList() - - fun feature(id: String, ref: String, description: String, name: String = id) { - features.add(Feature(id, ref, description, name)) - } - - val properties: MutableMap Any?> = mutableMapOf( - "name" to { project.name }, - "group" to { project.group }, - "version" to { project.version }, - "features" to { featuresString() } - ) - - private fun getActualizedProperties() = properties.mapValues { (_, value) -> - value.invoke() - } - - fun property(key: String, value: Any?) { - properties[key] = {value} - } - - fun propertyByTemplate(key: String, template: String) { - val actual = getActualizedProperties() - properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()} - } - - internal val additionalFiles = ArrayList() - - fun propertyByTemplate(key: String, template: File) { - val actual = getActualizedProperties() - properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()} - additionalFiles.add(template) - } - - /** - * Generate a markdown string listing features - */ - fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { - features.forEach { - appendln("$itemPrefix[${it.id}]($pathPrefix${it.ref}) : ${it.description}") - } - } - - /** - * Generate a readme string from the stub - */ - fun readmeString(): String? { - return if (readmeTemplate.exists()) { - val actual = getActualizedProperties() - SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() - } else { - null - } - } -} /** * Apply extension and repositories diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt new file mode 100644 index 0000000..2281106 --- /dev/null +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceReadmeExtension.kt @@ -0,0 +1,97 @@ +package ru.mipt.npm.gradle + +import groovy.text.SimpleTemplateEngine +import kotlinx.validation.ApiValidationExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.getByType +import java.io.File + +enum class Maturity { + PROTOTYPE, + EXPERIMENTAL, + DEVELOPMENT, + STABLE +} + + +class KScienceReadmeExtension(val project: Project) { + var description: String = "" + var maturity: Maturity = Maturity.EXPERIMENTAL + set(value) { + field = value + val projectName = project.name + if (value == Maturity.EXPERIMENTAL || value == Maturity.PROTOTYPE) { + project.rootProject.run { + plugins.withId("org.jetbrains.kotlinx.binary-compatibility-validator") { + extensions.getByType().apply { + project.logger.warn("$value project $projectName is excluded from API validation") + ignoredProjects.add(projectName) + } + } + } + } + } + + var readmeTemplate: File = project.file("docs/README-TEMPLATE.md") + + data class Feature(val id: String, val description: String, val ref: String?, val name: String = id) + + val features = ArrayList() + + fun feature(id: String, description: String, ref: String? = null, name: String = id) { + features.add(Feature(id, description, ref, name)) + } + + fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) { + features.add(Feature(id, description(), ref, name)) + } + + val properties: MutableMap Any?> = mutableMapOf( + "name" to { project.name }, + "group" to { project.group }, + "version" to { project.version }, + "features" to { featuresString() } + ) + + private fun getActualizedProperties() = properties.mapValues { (_, value) -> + value.invoke() + } + + fun property(key: String, value: Any?) { + properties[key] = { value } + } + + fun propertyByTemplate(key: String, template: String) { + val actual = getActualizedProperties() + properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } + } + + internal val additionalFiles = ArrayList() + + fun propertyByTemplate(key: String, template: File) { + val actual = getActualizedProperties() + properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } + additionalFiles.add(template) + } + + /** + * Generate a markdown string listing features + */ + fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { + features.forEach { + appendln("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") + } + } + + /** + * Generate a readme string from the stub + */ + fun readmeString(): String? { + return if (readmeTemplate.exists()) { + val actual = getActualizedProperties() + SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() + } else { + null + } + } +} \ No newline at end of file