From 93ee16df3827cc8cee1029a0c6b70a4d1db8f94d Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Fri, 22 Mar 2024 00:03:48 +0530 Subject: refactor(build): migrate to java-semver --- .../passwordstore/gradle/versioning/VersioningPlugin.kt | 14 +++++++------- .../app/passwordstore/gradle/versioning/VersioningTask.kt | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'build-logic/src/main') diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt index b6b0a4ad..8ba800b5 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningPlugin.kt @@ -8,7 +8,7 @@ package app.passwordstore.gradle.versioning import com.android.build.api.variant.ApplicationAndroidComponentsExtension import com.android.build.api.variant.VariantOutputConfiguration import com.android.build.gradle.internal.plugins.AppPlugin -import com.vdurmont.semver4j.Semver +import com.github.zafarkhaja.semver.Version import java.util.Properties import java.util.concurrent.atomic.AtomicBoolean import org.gradle.api.Plugin @@ -56,30 +56,30 @@ class VersioningPlugin : Plugin { } } } - val version = Semver(versionName) + val version = Version.parse(versionName) tasks.register("clearPreRelease") { description = "Remove the pre-release suffix from the version" - semverString.set(version.withClearedSuffix().toString()) + semverString.set(version.toStableVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpMajor") { description = "Increment the major version" - semverString.set(version.withIncMajor().withClearedSuffix().toString()) + semverString.set(version.nextMajorVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpMinor") { description = "Increment the minor version" - semverString.set(version.withIncMinor().withClearedSuffix().toString()) + semverString.set(version.nextMinorVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpPatch") { description = "Increment the patch version" - semverString.set(version.withIncPatch().withClearedSuffix().toString()) + semverString.set(version.nextPatchVersion().toString()) propertyFile.set(propFile) } tasks.register("bumpSnapshot") { description = "Increment the minor version and add the `SNAPSHOT` suffix" - semverString.set(version.withIncMinor().withSuffix("SNAPSHOT").toString()) + semverString.set(version.nextMinorVersion("SNAPSHOT").toString()) propertyFile.set(propFile) } afterEvaluate { diff --git a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningTask.kt b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningTask.kt index 7eb19a89..306311e9 100644 --- a/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningTask.kt +++ b/build-logic/src/main/kotlin/app/passwordstore/gradle/versioning/VersioningTask.kt @@ -5,7 +5,7 @@ package app.passwordstore.gradle.versioning -import com.vdurmont.semver4j.Semver +import com.github.zafarkhaja.semver.Version import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property @@ -21,11 +21,11 @@ abstract class VersioningTask : DefaultTask() { @get:OutputFile abstract val propertyFile: RegularFileProperty /** Generate the Android 'versionCode' property */ - private fun Semver.androidCode(): Int { - return major * 1_00_00 + minor * 1_00 + patch + private fun Version.androidCode(): Long { + return majorVersion() * 1_00_00 + minorVersion() * 1_00 + patchVersion() } - private fun Semver.toPropFileText(): String { + private fun Version.toPropFileText(): String { val newVersionCode = androidCode() val newVersionName = toString() return buildString { @@ -45,6 +45,6 @@ abstract class VersioningTask : DefaultTask() { @TaskAction fun execute() { - propertyFile.get().asFile.writeText(Semver(semverString.get()).toPropFileText()) + propertyFile.get().asFile.writeText(Version.parse(semverString.get()).toPropFileText()) } } -- cgit v1.2.3