diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-02-06 12:32:57 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-06 12:32:57 +0530 |
commit | c021869f9750314df83d1d72ce05a17bf72b62f0 (patch) | |
tree | 33bf199fc42b9af7e053ce1c16f7def421716db0 /buildSrc/src/main/java/VersioningPlugin.kt | |
parent | 723acbf7673d51e40b443db75b658c08901fe289 (diff) |
Update MDC + Gradle and switch versioning to semver4j (#1306)
Diffstat (limited to 'buildSrc/src/main/java/VersioningPlugin.kt')
-rw-r--r-- | buildSrc/src/main/java/VersioningPlugin.kt | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/buildSrc/src/main/java/VersioningPlugin.kt b/buildSrc/src/main/java/VersioningPlugin.kt index 7ff9709f..a2c9ff81 100644 --- a/buildSrc/src/main/java/VersioningPlugin.kt +++ b/buildSrc/src/main/java/VersioningPlugin.kt @@ -5,7 +5,7 @@ import com.android.build.gradle.internal.plugins.AppPlugin -import com.github.zafarkhaja.semver.Version +import com.vdurmont.semver4j.Semver import java.io.OutputStream import java.util.Properties import org.gradle.api.Plugin @@ -33,16 +33,16 @@ class VersioningPlugin : Plugin<Project> { /** * Generate the Android 'versionCode' property */ - private fun Version.androidCode(): Int { - return majorVersion * 1_00_00 + - minorVersion * 1_00 + - patchVersion + private fun Semver.androidCode(): Int { + return major * 1_00_00 + + minor * 1_00 + + patch } /** * Write an Android-specific variant of [this] to [stream] */ - private fun Version.writeForAndroid(stream: OutputStream) { + private fun Semver.writeForAndroid(stream: OutputStream) { val newVersionCode = androidCode() val props = Properties() props.setProperty(VERSIONING_PROP_VERSION_CODE, "$newVersionCode") @@ -50,13 +50,6 @@ class VersioningPlugin : Plugin<Project> { props.store(stream, VERSIONING_PROP_COMMENT) } - /** - * Returns the same [Version], but with build metadata stripped. - */ - private fun Version.clearPreRelease(): Version { - return Version.forIntegers(majorVersion, minorVersion, patchVersion) - } - override fun apply(project: Project) { with(project) { val appPlugin = requireNotNull(plugins.findPlugin(AppPlugin::class.java)) { @@ -77,35 +70,38 @@ class VersioningPlugin : Plugin<Project> { appPlugin.extension.defaultConfig.versionName = versionName appPlugin.extension.defaultConfig.versionCode = versionCode afterEvaluate { - val version = Version.valueOf(versionName) + val version = Semver(versionName) tasks.register("clearPreRelease") { doLast { - version.clearPreRelease() + version.withClearedSuffix() .writeForAndroid(propFile.asFile.outputStream()) } } tasks.register("bumpMajor") { doLast { - version.incrementMajorVersion() + version.withIncMajor() + .withClearedSuffix() .writeForAndroid(propFile.asFile.outputStream()) } } tasks.register("bumpMinor") { doLast { - version.incrementMinorVersion() + version.withIncMinor() + .withClearedSuffix() .writeForAndroid(propFile.asFile.outputStream()) } } tasks.register("bumpPatch") { doLast { - version.incrementPatchVersion() + version.withIncPatch() + .withClearedSuffix() .writeForAndroid(propFile.asFile.outputStream()) } } tasks.register("bumpSnapshot") { doLast { - version.incrementMinorVersion() - .setPreReleaseVersion("SNAPSHOT") + version.withIncMinor() + .withSuffix("SNAPSHOT") .writeForAndroid(propFile.asFile.outputStream()) } } |