diff --git a/.teamcity/src/main/kotlin/projects/unified/plugin/PluginProject.kt b/.teamcity/src/main/kotlin/projects/unified/plugin/PluginProject.kt index 769cc641..2745a215 100644 --- a/.teamcity/src/main/kotlin/projects/unified/plugin/PluginProject.kt +++ b/.teamcity/src/main/kotlin/projects/unified/plugin/PluginProject.kt @@ -53,7 +53,7 @@ class PluginProject(private val buildAndTest: BuildType) : Project({ steps { step(configuredGradle { name = "Change to Release Version" - tasks = ":unified-plugin:build-update-utils:changeSnapshotToReleaseVersion" + tasks = ":unified-plugin:changeSnapshotToReleaseVersion" workingDir = "unified-prototype" }) step(configuredGradle { @@ -64,7 +64,7 @@ class PluginProject(private val buildAndTest: BuildType) : Project({ }) step(configuredGradle { name = "Change to next Snapshot Version" - tasks = ":unified-plugin:build-update-utils:changeReleaseToNextSnapshotVersion" + tasks = ":unified-plugin:changeReleaseToNextSnapshotVersion" workingDir = "unified-prototype" }) script { diff --git a/unified-prototype/unified-plugin/build-logic/build.gradle.kts b/unified-prototype/unified-plugin/build-logic/build.gradle.kts index 27e26a9c..13d80257 100644 --- a/unified-prototype/unified-plugin/build-logic/build.gradle.kts +++ b/unified-prototype/unified-plugin/build-logic/build.gradle.kts @@ -5,3 +5,12 @@ plugins { dependencies { implementation("com.gradle.publish:plugin-publish-plugin:1.2.1") } + +gradlePlugin { + plugins { + create("build-logic.build-update-utils") { + id = "build-logic.build-update-utils" + implementationClass = "buildlogic.BuildUpdateUtilsPlugin" + } + } +} diff --git a/unified-prototype/unified-plugin/build-logic/src/main/kotlin/buildlogic/BuildUpdateUtilsPlugin.kt b/unified-prototype/unified-plugin/build-logic/src/main/kotlin/buildlogic/BuildUpdateUtilsPlugin.kt new file mode 100644 index 00000000..8fadb9b3 --- /dev/null +++ b/unified-prototype/unified-plugin/build-logic/src/main/kotlin/buildlogic/BuildUpdateUtilsPlugin.kt @@ -0,0 +1,67 @@ +package buildlogic + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.process.ExecOperations +import javax.inject.Inject + +open class BuildUpdateUtilsPlugin @Inject constructor( + private val execOperations: ExecOperations +) : Plugin { + + companion object { + private const val CI_UPDATE_TASKS = "CI Update Tasks" + } + + override fun apply(target: Project) { + target.run { + val versionFile = rootProject.file("version.txt") + + fun getVersionFromFile() = versionFile.readText().trim() + + fun writeNewVersion(newVersion: String) = versionFile.writeText(newVersion) + + tasks.register("changeSnapshotToReleaseVersion") { + description = "Change the version of the plugin to a release version" + group = CI_UPDATE_TASKS + doLast { + val version = getVersionFromFile() + val newVersion = version.removeSuffix("-SNAPSHOT") + if (version == newVersion) { + throw IllegalStateException("Version is not a snapshot version: $version") + } + writeNewVersion(newVersion) + execOperations.exec { + commandLine("git", "commit", "-m", "Release version $newVersion", versionFile.absolutePath) + } + execOperations.exec { + commandLine("git", "tag", "v${newVersion}", "-m", "Release version $newVersion") + } + } + } + + tasks.register("changeReleaseToNextSnapshotVersion") { + description = "Change the version of the plugin to a snapshot version" + group = CI_UPDATE_TASKS + doLast { + val version = getVersionFromFile() + if (!version.matches(Regex("\\d+\\.\\d+\\.\\d+"))) { + throw IllegalStateException("Version is not a release version: $version") + } + val versionParts = version.split(".") + val newVersion = "${versionParts[0]}.${versionParts[1]}.${versionParts[2].toInt() + 1}-SNAPSHOT" + writeNewVersion(newVersion) + execOperations.exec { + commandLine( + "git", + "commit", + "-m", + "Switch to next snapshot version $newVersion", + versionFile.absolutePath + ) + } + } + } + } + } +} diff --git a/unified-prototype/unified-plugin/build-update-utils/build.gradle.kts b/unified-prototype/unified-plugin/build-update-utils/build.gradle.kts deleted file mode 100644 index fa3d6cab..00000000 --- a/unified-prototype/unified-plugin/build-update-utils/build.gradle.kts +++ /dev/null @@ -1,56 +0,0 @@ -description = "Utility tasks for CI to use to release a version of the plugin" - -val ciUpdateTasks = "CI Update Tasks" - -val versionFile = rootProject.file("version.txt") - -open class ExecOperationsHelper @Inject constructor(val execOperations: ExecOperations) { -} - -val execOperations = project.objects.newInstance().execOperations - -tasks.register("changeSnapshotToReleaseVersion") { - description = "Change the version of the plugin to a release version" - group = ciUpdateTasks - doLast { - val version = getVersionFromFile() - val newVersion = version.removeSuffix("-SNAPSHOT") - if (version == newVersion) { - throw IllegalStateException("Version is not a snapshot version: $version") - } - writeNewVersion(newVersion) - execOperations.exec { - commandLine("git", "commit", "-m", "Release version $newVersion", versionFile.absolutePath) - } - execOperations.exec { - commandLine("git", "tag", "v${newVersion}", "-m", "Release version $newVersion") - } - } -} - -tasks.register("changeReleaseToNextSnapshotVersion") { - description = "Change the version of the plugin to a snapshot version" - group = ciUpdateTasks - doLast { - val version = getVersionFromFile() - if (!version.matches(Regex("\\d+\\.\\d+\\.\\d+"))) { - throw IllegalStateException("Version is not a release version: $version") - } - val versionParts = version.split(".") - val newVersion = "${versionParts[0]}.${versionParts[1]}.${versionParts[2].toInt() + 1}-SNAPSHOT" - writeNewVersion(newVersion) - execOperations.exec { - commandLine( - "git", - "commit", - "-m", - "Switch to next snapshot version $newVersion", - versionFile.absolutePath - ) - } - } -} - -fun getVersionFromFile() = versionFile.readText().trim() - -fun writeNewVersion(newVersion: String) = versionFile.writeText(newVersion) diff --git a/unified-prototype/unified-plugin/build.gradle.kts b/unified-prototype/unified-plugin/build.gradle.kts index 056ac2cd..99f4200a 100644 --- a/unified-prototype/unified-plugin/build.gradle.kts +++ b/unified-prototype/unified-plugin/build.gradle.kts @@ -1,5 +1,6 @@ plugins { kotlin("jvm").version(libs.versions.kotlin).apply(false) + id("build-logic.build-update-utils") } version = file("version.txt").readText().trim()