refactor: replace semver4j with jsemver

This commit is contained in:
Harsh Shandilya 2024-01-27 12:55:18 +05:30
parent ad2582a28e
commit 0e5caf591a
3 changed files with 15 additions and 15 deletions

View File

@ -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<Project> {
}
}
}
val version = Semver(versionName)
val version = Version.parse(versionName)
tasks.register<VersioningTask>("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<VersioningTask>("bumpMajor") {
description = "Increment the major version"
semverString.set(version.withIncMajor().withClearedSuffix().toString())
semverString.set(version.nextMajorVersion().toString())
propertyFile.set(propFile)
}
tasks.register<VersioningTask>("bumpMinor") {
description = "Increment the minor version"
semverString.set(version.withIncMinor().withClearedSuffix().toString())
semverString.set(version.nextMinorVersion().toString())
propertyFile.set(propFile)
}
tasks.register<VersioningTask>("bumpPatch") {
description = "Increment the patch version"
semverString.set(version.withIncPatch().withClearedSuffix().toString())
semverString.set(version.nextPatchVersion().toString())
propertyFile.set(propFile)
}
tasks.register<VersioningTask>("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 {

View File

@ -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())
}
}

View File

@ -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" }