diff --git a/buildSrc/src/main/kotlin/Plugins.kt b/buildSrc/src/main/kotlin/Plugins.kt index c8a21c6f86..232a873778 100644 --- a/buildSrc/src/main/kotlin/Plugins.kt +++ b/buildSrc/src/main/kotlin/Plugins.kt @@ -6,6 +6,7 @@ object Plugins { const val NEXUS_STAGING = "io.codearte.nexus-staging" const val BEN_MANES_PLUGIN = "com.github.ben-manes.versions" const val MAVEN_VERSION_CHECK = "maven-version-check" + const val CHECK_VERSION_UPDATED = "check-version-updated" object Kotlin { const val PLUGIN_JVM = "jvm" const val PLUGIN_SERIALIZATION = "plugin.serialization" diff --git a/buildSrc/src/main/kotlin/Utils.kt b/buildSrc/src/main/kotlin/Utils.kt deleted file mode 100644 index df1ac57161..0000000000 --- a/buildSrc/src/main/kotlin/Utils.kt +++ /dev/null @@ -1,25 +0,0 @@ -import org.gradle.api.Project -import java.io.ByteArrayOutputStream - -fun Project.execAndGetStdout(vararg args: String): String { - val stdout = ByteArrayOutputStream() - exec { - commandLine(*args) - standardOutput = stdout - workingDir = projectDir - } - return stdout.toString().trimEnd() -} - -// TODO replace with plugin in #2063 -fun Project.isVersionChangedInBuildGradle(): Boolean { - - val localResultsStream = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts") - .split("\n") - val commitedResultsStream = execAndGetStdout("git", "diff", "origin/master", "--", "build.gradle.kts") - .split("\n") - return (commitedResultsStream + localResultsStream) - .filter { it.startsWith("-version = ") || it.startsWith("+version = ") } - .isNotEmpty() -} - diff --git a/check_version_updated/build.gradle.kts b/check_version_updated/build.gradle.kts new file mode 100644 index 0000000000..5e95fdad57 --- /dev/null +++ b/check_version_updated/build.gradle.kts @@ -0,0 +1,15 @@ +repositories { + mavenCentral() +} + +plugins { + `kotlin-dsl` + `java-gradle-plugin` +} + +gradlePlugin { + plugins.register("check-version-updated") { + id = "check-version-updated" + implementationClass = "com.github.flank.gradle.CheckVersionUpdated" + } +} diff --git a/check_version_updated/settings.gradle.kts b/check_version_updated/settings.gradle.kts new file mode 100644 index 0000000000..cd1a5448d4 --- /dev/null +++ b/check_version_updated/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "check-version-updated" diff --git a/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdated.kt b/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdated.kt new file mode 100644 index 0000000000..c98dc1e21c --- /dev/null +++ b/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdated.kt @@ -0,0 +1,42 @@ +package com.github.flank.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.get +import java.io.ByteArrayOutputStream + +class CheckVersionUpdated : Plugin { + + private val taskName = "checkIfVersionUpdated" + + override fun apply(project: Project) { + + project.tasks.register(taskName, CheckVersionUpdatedTask::class.java) + + project.afterEvaluate { + project.tasks["lintKotlin"].dependsOn(taskName) + } + } + + private fun Project.execAndGetStdout(vararg args: String): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine(*args) + standardOutput = stdout + workingDir = projectDir + } + return stdout.toString().trimEnd() + } + + private fun Project.isVersionChangedInBuildGradle(): Boolean { + + val localResultsStream = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts") + .split("\n") + val commitedResultsStream = execAndGetStdout("git", "diff", "origin/master", "--", "build.gradle.kts") + .split("\n") + return (commitedResultsStream + localResultsStream) + .filter { it.startsWith("-version = ") || it.startsWith("+version = ") } + .isNotEmpty() + } + +} diff --git a/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdatedTask.kt b/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdatedTask.kt new file mode 100644 index 0000000000..cef9326503 --- /dev/null +++ b/check_version_updated/src/main/kotlin/com/github/flank/gradle/CheckVersionUpdatedTask.kt @@ -0,0 +1,47 @@ +package com.github.flank.gradle + +import org.gradle.api.DefaultTask +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.tasks.TaskAction +import java.io.ByteArrayOutputStream + +open class CheckVersionUpdatedTask : DefaultTask() { + + @TaskAction + fun action() { + project.execAndGetStdout("git", "fetch", "--no-tags") + val changedFiles = project.execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") + + project.execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n") + val isVersionChanged = changedFiles.any { it.startsWith(project.name) }.not() || + (changedFiles.contains("${project.name}/build.gradle.kts") && project.isVersionChangedInBuildGradle()) + + if (isVersionChanged.not()) { + throw GradleException( + """ + ${project.path} version is not updated, but files changed. + Please update version according to schema: .. + """.trimIndent() + ) + } + } + + private fun Project.execAndGetStdout(vararg args: String): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine(*args) + standardOutput = stdout + workingDir = projectDir + } + return stdout.toString().trimEnd() + } + + private fun Project.isVersionChangedInBuildGradle(): Boolean { + val localResultsStream = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--", "build.gradle.kts") + .split("\n") + val commitedResultsStream = execAndGetStdout("git", "diff", "origin/master", "--", "build.gradle.kts") + .split("\n") + return (commitedResultsStream + localResultsStream) + .any { it.startsWith("-version = ") || it.startsWith("+version = ") } + } +} diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 47f5da2e38..0e0f2a1fe0 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -8,6 +8,7 @@ plugins { kotlin(Plugins.Kotlin.PLUGIN_SERIALIZATION) version Versions.KOTLIN id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW id(Plugins.MAVEN_PUBLISH) + id(Plugins.CHECK_VERSION_UPDATED) } val artifactID = "flank-scripts" @@ -25,7 +26,7 @@ shadowJar.apply { } } // .. -version = "1.9.24" +version = "1.9.25" group = "com.github.flank" application { @@ -125,29 +126,6 @@ val download by tasks.registering(Exec::class) { } } -// TODO replace with plugin in #2063 -val checkIfVersionUpdated by tasks.registering(Exec::class) { - group = "verification" - commandLine("git", "fetch", "--no-tags") - - doLast { - val changedFiles = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") + - execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n") - val isVersionChanged = changedFiles.any { it.startsWith("flank-scripts") }.not() || - (changedFiles.contains("flank-scripts/build.gradle.kts") && isVersionChangedInBuildGradle()) - - if (isVersionChanged.not()) { - throw GradleException( - """ - Flank scripts version is not updated, but files changed. - Please update version according to schema: .. - """.trimIndent() - - ) - } - } -} - val releaseFlankScripts by tasks.registering(Exec::class) { dependsOn(":flank-scripts:publish") commandLine( @@ -157,5 +135,3 @@ val releaseFlankScripts by tasks.registering(Exec::class) { "-p" ) } - -tasks["lintKotlin"].dependsOn(checkIfVersionUpdated) diff --git a/flank_wrapper/build.gradle.kts b/flank_wrapper/build.gradle.kts index 3fcc0bc27e..e5cb9cff8f 100644 --- a/flank_wrapper/build.gradle.kts +++ b/flank_wrapper/build.gradle.kts @@ -6,6 +6,7 @@ plugins { kotlin(Plugins.Kotlin.PLUGIN_JVM) id(Plugins.PLUGIN_SHADOW_JAR) version Versions.SHADOW id(Plugins.MAVEN_PUBLISH) + id(Plugins.CHECK_VERSION_UPDATED) } val artifactID = "flank_wrapper" @@ -23,7 +24,7 @@ shadowJar.apply { } } // .. -version = "1.2.0" +version = "1.2.1" group = "com.github.flank" repositories { @@ -101,29 +102,6 @@ application { mainClass.set(runnerClass) } -// TODO replace with plugin in #2063 -val checkIfVersionUpdated by tasks.registering(Exec::class) { - group = "verification" - commandLine("git", "fetch", "--no-tags") - - doLast { - val changedFiles = execAndGetStdout("git", "diff", "origin/master", "HEAD", "--name-only").split("\n") + - execAndGetStdout("git", "diff", "origin/master", "--name-only").split("\n") - val isVersionChanged = changedFiles.any { it.startsWith("flank_wrapper") }.not() || - (changedFiles.contains("flank_wrapper/build.gradle.kts") && isVersionChangedInBuildGradle()) - - if (isVersionChanged.not()) { - throw GradleException( - """ - Flank wrapper version is not updated, but files changed. - Please update version according to schema: .. - """.trimIndent() - - ) - } - } -} - val prepareJar by tasks.registering(Copy::class) { dependsOn("shadowJar") from("$buildDir/libs") @@ -143,5 +121,3 @@ val setWrapperVersion by tasks.registering { tasks.processResources { dependsOn(setWrapperVersion) } - -tasks["lintKotlin"].dependsOn(checkIfVersionUpdated) diff --git a/flank_wrapper/src/main/resources/version.txt b/flank_wrapper/src/main/resources/version.txt index 867e52437a..cb174d58a5 100644 --- a/flank_wrapper/src/main/resources/version.txt +++ b/flank_wrapper/src/main/resources/version.txt @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.2.1 \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 2f7589d4a4..465c193985 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ import org.gradle.kotlin.dsl.support.serviceOf rootProject.name = "flank" includeBuild("maven_version_check") +includeBuild("check_version_updated") include( ":test_runner",