diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2022-02-05 01:57:41 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-05 01:57:41 +0530 |
| commit | 664e1fbba06792c82ad2ce71d16ca687077e9c9a (patch) | |
| tree | c4dffa3e696538e8b14d41b5679cd5b981703ac7 /build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt | |
| parent | 2b293e58056ea897c305bd39e21b42f5cd4d1a62 (diff) | |
| download | HardenedPass-664e1fbba06792c82ad2ce71d16ca687077e9c9a.tar.gz HardenedPass-664e1fbba06792c82ad2ce71d16ca687077e9c9a.zip | |
Begin rework for configuration cache compatibility (#1709)
Diffstat (limited to 'build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt')
| -rw-r--r-- | build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt | 71 |
1 files changed, 17 insertions, 54 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt b/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt index 3083921f..5d838b63 100644 --- a/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt +++ b/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt @@ -7,18 +7,10 @@ package versioning import com.android.build.gradle.internal.plugins.AppPlugin import com.vdurmont.semver4j.Semver -import java.io.OutputStream import java.util.Properties import org.gradle.api.Plugin import org.gradle.api.Project - -private const val VERSIONING_PROP_FILE = "version.properties" -private const val VERSIONING_PROP_VERSION_NAME = "versioning-plugin.versionName" -private const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode" -private const val VERSIONING_PROP_COMMENT = - """ -This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY. -""" +import org.gradle.kotlin.dsl.register /** * A Gradle [Plugin] that takes a [Project] with the [AppPlugin] applied and dynamically sets the @@ -26,23 +18,9 @@ This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUAL * the [Project.getBuildDir] directory. It also adds Gradle tasks to bump the major, minor, and * patch versions along with one to prepare the next snapshot. */ -@Suppress("UnstableApiUsage", "NAME_SHADOWING") +@Suppress("UnstableApiUsage", "NAME_SHADOWING", "Unused") class VersioningPlugin : Plugin<Project> { - /** Generate the Android 'versionCode' property */ - 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 Semver.writeForAndroid(stream: OutputStream) { - val newVersionCode = androidCode() - val props = Properties() - props.setProperty(VERSIONING_PROP_VERSION_CODE, "$newVersionCode") - props.setProperty(VERSIONING_PROP_VERSION_NAME, toString()) - props.store(stream, VERSIONING_PROP_COMMENT) - } - override fun apply(project: Project) { with(project) { val appPlugin = @@ -67,40 +45,25 @@ class VersioningPlugin : Plugin<Project> { appPlugin.extension.defaultConfig.versionCode = versionCode afterEvaluate { val version = Semver(versionName) - tasks.register("clearPreRelease") { - doLast { version.withClearedSuffix().writeForAndroid(propFile.asFile.outputStream()) } + tasks.register<VersioningTask>("clearPreRelease") { + semverString.set(version.withClearedSuffix().toString()) + propertyFile.set(propFile) } - tasks.register("bumpMajor") { - doLast { - version - .withIncMajor() - .withClearedSuffix() - .writeForAndroid(propFile.asFile.outputStream()) - } + tasks.register<VersioningTask>("bumpMajor") { + semverString.set(version.withIncMajor().withClearedSuffix().toString()) + propertyFile.set(propFile) } - tasks.register("bumpMinor") { - doLast { - version - .withIncMinor() - .withClearedSuffix() - .writeForAndroid(propFile.asFile.outputStream()) - } + tasks.register<VersioningTask>("bumpMinor") { + semverString.set(version.withIncMinor().withClearedSuffix().toString()) + propertyFile.set(propFile) } - tasks.register("bumpPatch") { - doLast { - version - .withIncPatch() - .withClearedSuffix() - .writeForAndroid(propFile.asFile.outputStream()) - } + tasks.register<VersioningTask>("bumpPatch") { + semverString.set(version.withIncPatch().withClearedSuffix().toString()) + propertyFile.set(propFile) } - tasks.register("bumpSnapshot") { - doLast { - version - .withIncMinor() - .withSuffix("SNAPSHOT") - .writeForAndroid(propFile.asFile.outputStream()) - } + tasks.register<VersioningTask>("bumpSnapshot") { + semverString.set(version.withIncMinor().withSuffix("SNAPSHOT").toString()) + propertyFile.set(propFile) } } } |
