From e1a11452d2d9e266e28e4e8fc81b05f19bbf361e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 15 Mar 2022 13:03:32 +0300 Subject: [PATCH] Update release task generation --- .../mipt/npm/gradle/KScienceProjectPlugin.kt | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt index f48f6d0..22f7ec6 100644 --- a/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/ru/mipt/npm/gradle/KScienceProjectPlugin.kt @@ -166,39 +166,9 @@ public open class KScienceProjectPlugin : Plugin { } } - tasks.withType { - dependsOn(generateReadme) - } - } - - val releaseAll by tasks.creating { - group = RELEASE_GROUP - description = "Publish development or production release based on version suffix" - } - - allprojects { - afterEvaluate { - ksciencePublish.repositoryNames.forEach { repositoryName -> - val repositoryNameCapitalized = repositoryName.capitalize() - - tasks.withType() - .filter { it.name.startsWith("publish") && it.name.endsWith("To${repositoryNameCapitalized}Repository") } - .forEach { - val theName = "release${ - it.name.removePrefix("publish").removeSuffix("To${repositoryNameCapitalized}Repository") - }" - - val targetReleaseTask = tasks.findByName(theName) ?: tasks.create(theName) { - group = RELEASE_GROUP - description = "Publish platform release artifact" - } - - releaseAll.dependsOn(targetReleaseTask) - - targetReleaseTask.dependsOn(it) - } - } - } +// tasks.withType { +// dependsOn(generateReadme) +// } } val generateReadme by tasks.creating { @@ -264,6 +234,39 @@ public open class KScienceProjectPlugin : Plugin { dependsOn(generateReadme) } + + val releaseAll by tasks.creating { + group = RELEASE_GROUP + description = "Publish development or production release based on version suffix" + dependsOn(generateReadme) + } + + allprojects { + afterEvaluate { + ksciencePublish.repositoryNames.forEach { repositoryName -> + val repositoryNameCapitalized = repositoryName.capitalize() + + val pattern = "publish(?.*)PublicationTo${repositoryNameCapitalized}Repository" + .toRegex() + + tasks.withType().toList().forEach forEachPublication@ { + val matchResult = pattern.matchEntire(it.name) ?: return@forEachPublication + val publicationName = matchResult.groups["publication"]!!.value.capitalize() + val releaseTaskName = "release$publicationName" + + val targetReleaseTask = rootProject.tasks.findByName(releaseTaskName) ?: rootProject.tasks.create(releaseTaskName) { + group = RELEASE_GROUP + description = "Publish platform release artifact for $publicationName to all repositories" + } + + releaseAll.dependsOn(targetReleaseTask) + + targetReleaseTask.dependsOn(it) + } + } + } + } + // Disable API validation for snapshots if (isSnapshot()) { extensions.findByType()?.apply {