From 0e5caf591ab7f67cc46cb7775c0bde6cdcabd62e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 27 Jan 2024 12:55:18 +0530 Subject: [PATCH] refactor: replace semver4j with jsemver --- .../claw/gradle/versioning/VersioningPlugin.kt | 16 ++++++++-------- .../claw/gradle/versioning/VersioningTask.kt | 12 ++++++------ gradle/libs.versions.toml | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt index 4894aedd..f8756737 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningPlugin.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2022-2023 Harsh Shandilya. + * Copyright © 2022-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -9,7 +9,7 @@ package dev.msfjarvis.claw.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 @@ -57,30 +57,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/dev/msfjarvis/claw/gradle/versioning/VersioningTask.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningTask.kt index e2536f02..fc8c0c32 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningTask.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/versioning/VersioningTask.kt @@ -1,12 +1,12 @@ /* - * Copyright © 2022 Harsh Shandilya. + * Copyright © 2022-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ package dev.msfjarvis.claw.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 @@ -22,11 +22,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 { @@ -46,6 +46,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()) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 33cc03b0..cc6cc107 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -57,7 +57,7 @@ androidx-work-runtime = { module = "androidx.work:work-runtime", version.ref = " build-agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } build-cachefix = "org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:3.0" build-kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } -build-semver = "com.vdurmont:semver4j:3.1.0" +build-semver = "com.github.zafarkhaja:java-semver:0.10.2" build-sentry = "io.sentry.android.gradle:io.sentry.android.gradle.gradle.plugin:4.2.0" build-spotless = "com.diffplug.spotless:spotless-plugin-gradle:6.25.0" coil = { module = "io.coil-kt:coil", version.ref = "coil" }