aboutsummaryrefslogtreecommitdiffstats
path: root/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-07-15 00:53:48 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-07-15 01:13:47 +0530
commit549ee790d3e52bc62565ddf92e6a556e98b5195e (patch)
treed5758e5eb80093704e683c8da926838e18182588 /build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning
parent010c6e227c9cc27f4d01bc912311f977b2aeb3a7 (diff)
downloadHardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.tar.gz
HardenedPass-549ee790d3e52bc62565ddf92e6a556e98b5195e.zip
all: re-do package structure yet again
Diffstat (limited to 'build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning')
-rw-r--r--build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/Constants.kt14
-rw-r--r--build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningPlugin.kt88
-rw-r--r--build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningTask.kt50
3 files changed, 0 insertions, 152 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/Constants.kt b/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/Constants.kt
deleted file mode 100644
index 0d6f5c67..00000000
--- a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/Constants.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package dev.msfjarvis.aps.gradle.versioning
-
-const val VERSIONING_PROP_FILE = "version.properties"
-const val VERSIONING_PROP_VERSION_NAME = "versioning-plugin.versionName"
-const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode"
-const val VERSIONING_PROP_COMMENT =
- """#
-# This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY.
-#"""
diff --git a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningPlugin.kt b/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningPlugin.kt
deleted file mode 100644
index 5272dd8a..00000000
--- a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningPlugin.kt
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package dev.msfjarvis.aps.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 java.util.Properties
-import java.util.concurrent.atomic.AtomicBoolean
-import org.gradle.api.Plugin
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.getByType
-import org.gradle.kotlin.dsl.register
-import org.gradle.kotlin.dsl.withType
-
-/**
- * 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 androidAppPluginApplied = AtomicBoolean(false)
- 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"
- }
- project.plugins.withType<AppPlugin> {
- androidAppPluginApplied.set(true)
- extensions.getByType<ApplicationAndroidComponentsExtension>().onVariants { variant ->
- val mainOutput =
- variant.outputs.single { it.outputType == VariantOutputConfiguration.OutputType.SINGLE }
- mainOutput.versionName.set(versionName)
- mainOutput.versionCode.set(versionCode)
- }
- }
- val version = Semver(versionName)
- tasks.register<VersioningTask>("clearPreRelease") {
- description = "Remove the pre-release suffix from the version"
- semverString.set(version.withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpMajor") {
- description = "Increment the major version"
- semverString.set(version.withIncMajor().withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpMinor") {
- description = "Increment the minor version"
- semverString.set(version.withIncMinor().withClearedSuffix().toString())
- propertyFile.set(propFile)
- }
- tasks.register<VersioningTask>("bumpPatch") {
- description = "Increment the patch version"
- semverString.set(version.withIncPatch().withClearedSuffix().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())
- propertyFile.set(propFile)
- }
- afterEvaluate {
- check(androidAppPluginApplied.get()) {
- "Plugin 'com.android.application' must be applied to ${project.displayName} to use the Versioning Plugin"
- }
- }
- }
- }
-}
diff --git a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningTask.kt b/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningTask.kt
deleted file mode 100644
index b39fdaa4..00000000
--- a/build-logic/android-plugins/src/main/kotlin/dev/msfjarvis/aps/gradle/versioning/VersioningTask.kt
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package dev.msfjarvis.aps.gradle.versioning
-
-import com.vdurmont.semver4j.Semver
-import org.gradle.api.DefaultTask
-import org.gradle.api.file.RegularFileProperty
-import org.gradle.api.provider.Property
-import org.gradle.api.tasks.CacheableTask
-import org.gradle.api.tasks.Input
-import org.gradle.api.tasks.OutputFile
-import org.gradle.api.tasks.TaskAction
-
-@CacheableTask
-abstract class VersioningTask : DefaultTask() {
- @get:Input abstract val semverString: Property<String>
-
- @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 Semver.toPropFileText(): String {
- val newVersionCode = androidCode()
- val newVersionName = toString()
- return buildString {
- appendLine(VERSIONING_PROP_COMMENT)
- append(VERSIONING_PROP_VERSION_CODE)
- append('=')
- appendLine(newVersionCode)
- append(VERSIONING_PROP_VERSION_NAME)
- append('=')
- appendLine(newVersionName)
- }
- }
-
- override fun getGroup(): String {
- return "versioning"
- }
-
- @TaskAction
- fun execute() {
- propertyFile.get().asFile.writeText(Semver(semverString.get()).toPropFileText())
- }
-}