From 37e5603389e5877a405b8ac934d2cc4ae88b3752 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 26 Aug 2024 16:40:46 +0300 Subject: [PATCH] Add readme task validation --- gradle/libs.versions.toml | 2 +- .../kscience/gradle/KScienceProjectPlugin.kt | 25 ++++++++------ .../gradle/KScienceReadmeExtension.kt | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16cdbd7..c13af9e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ # @pin kotlin = "2.0.20" # @pin -tools = "0.15.6-kotlin-2.0.20" +tools = "0.15.7-kotlin-2.0.20" atomicfu = "0.25.0" changelog = "2.2.1" compose = "1.6.11" diff --git a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt index fdb73f1..d1ec666 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt @@ -126,6 +126,8 @@ public open class KScienceProjectPlugin : Plugin { group = "documentation" description = "Generate a README file if stub is present" + inputs.property("extension", readmeExtension) + if (readmeExtension.readmeTemplate.exists()) { inputs.file(readmeExtension.readmeTemplate) } @@ -161,6 +163,8 @@ public open class KScienceProjectPlugin : Plugin { } } + inputs.property("extension", rootReadmeExtension) + if (rootReadmeExtension.readmeTemplate.exists()) { inputs.file(rootReadmeExtension.readmeTemplate) } @@ -185,18 +189,17 @@ public open class KScienceProjectPlugin : Plugin { val modulesString = buildString { subprojects.forEach { subproject -> // val name = subproject.name - subproject.extensions.findByType() - ?.let { ext: KScienceReadmeExtension -> - val path = subproject.path.replaceFirst(":", "").replace(":", "/") - appendLine("\n### [$path]($path)") - ext.description?.let { appendLine("> ${ext.description}") } - appendLine(">\n> **Maturity**: ${ext.maturity}") - val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$path/") - if (featureString.isNotBlank()) { - appendLine(">\n> **Features:**") - appendLine(featureString) - } + subproject.extensions.findByType()?.let { ext -> + val path = subproject.path.replaceFirst(":", "").replace(":", "/") + appendLine("\n### [$path]($path)") + ext.description?.let { appendLine("> ${ext.description}") } + appendLine(">\n> **Maturity**: ${ext.maturity}") + val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$path/") + if (featureString.isNotBlank()) { + appendLine(">\n> **Features:**") + appendLine(featureString) } + } } } diff --git a/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt b/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt index af16822..8345fac 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceReadmeExtension.kt @@ -190,4 +190,38 @@ public class KScienceReadmeExtension(public val project: Project) { project.logger.warn("Template with name ${ex.templateName} not found in ${project.name}") null } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as KScienceReadmeExtension + + if (project != other.project) return false + if (maturity != other.maturity) return false + if (useDefaultReadmeTemplate != other.useDefaultReadmeTemplate) return false + if (readmeTemplate != other.readmeTemplate) return false + if (fmLoader != other.fmLoader) return false + if (fmCfg != other.fmCfg) return false + if (features != other.features) return false + if (properties != other.properties) return false + if (inputFiles != other.inputFiles) return false + + return true + } + + override fun hashCode(): Int { + var result = project.hashCode() + result = 31 * result + maturity.hashCode() + result = 31 * result + useDefaultReadmeTemplate.hashCode() + result = 31 * result + readmeTemplate.hashCode() + result = 31 * result + fmLoader.hashCode() + result = 31 * result + fmCfg.hashCode() + result = 31 * result + features.hashCode() + result = 31 * result + properties.hashCode() + result = 31 * result + inputFiles.hashCode() + return result + } + + }