aboutsummaryrefslogtreecommitdiffstats
path: root/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-06-04 15:24:46 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-06-05 03:58:15 +0530
commit504c8b466c44b4a8591976ed5d8662f7c83f67fc (patch)
tree3ff0a7d13736da9a9103617a196e4562287705ea /build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt
parentfee75104962548404ed2ffc4f6ef9c397b86683f (diff)
downloadHardenedPass-504c8b466c44b4a8591976ed5d8662f7c83f67fc.tar.gz
HardenedPass-504c8b466c44b4a8591976ed5d8662f7c83f67fc.zip
android-plugins: convert to full plugins
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.kt71
1 files changed, 0 insertions, 71 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
deleted file mode 100644
index 043cd280..00000000
--- a/build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package versioning
-
-import com.android.build.gradle.internal.plugins.AppPlugin
-import com.vdurmont.semver4j.Semver
-import java.util.Properties
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.register
-
-/**
- * A Gradle [Plugin] that takes a [Project] with the [AppPlugin] applied and dynamically sets the
- * versionCode and versionName properties based on values read from a [VERSIONING_PROP_FILE] file in
- * 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("Unused")
-class VersioningPlugin : Plugin<Project> {
-
- override fun apply(project: Project) {
- with(project) {
- val appPlugin =
- requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
- "Plugin 'com.android.application' must be applied to use this plugin"
- }
- val propFile = layout.projectDirectory.file(VERSIONING_PROP_FILE)
- require(propFile.asFile.exists()) {
- "A 'version.properties' file must exist in the project subdirectory to use this plugin"
- }
- val contents = providers.fileContents(propFile).asText
- val versionProps = Properties().also { it.load(contents.get().byteInputStream()) }
- val versionName =
- requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) {
- "version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property"
- }
- val versionCode =
- requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) {
- "version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property"
- }
- appPlugin.extension.defaultConfig.versionName = versionName
- appPlugin.extension.defaultConfig.versionCode = versionCode
- afterEvaluate {
- val version = Semver(versionName)
- tasks.register<VersioningTask>("clearPreRelease") {
- semverString.set(version.withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpMajor") {
- semverString.set(version.withIncMajor().withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpMinor") {
- semverString.set(version.withIncMinor().withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpPatch") {
- semverString.set(version.withIncPatch().withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpSnapshot") {
- semverString.set(version.withIncMinor().withSuffix("SNAPSHOT").toString())
- propertyFile.set(propFile)
- }
- }
- }
- }
-}