diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2022-06-04 15:24:46 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-06-05 03:58:15 +0530 |
| commit | 504c8b466c44b4a8591976ed5d8662f7c83f67fc (patch) | |
| tree | 3ff0a7d13736da9a9103617a196e4562287705ea /build-logic/android-plugins/src/main/kotlin/versioning | |
| parent | fee75104962548404ed2ffc4f6ef9c397b86683f (diff) | |
| download | HardenedPass-504c8b466c44b4a8591976ed5d8662f7c83f67fc.tar.gz HardenedPass-504c8b466c44b4a8591976ed5d8662f7c83f67fc.zip | |
android-plugins: convert to full plugins
Diffstat (limited to 'build-logic/android-plugins/src/main/kotlin/versioning')
3 files changed, 0 insertions, 131 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/versioning/Constants.kt b/build-logic/android-plugins/src/main/kotlin/versioning/Constants.kt deleted file mode 100644 index 000f5438..00000000 --- a/build-logic/android-plugins/src/main/kotlin/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 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/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) - } - } - } - } -} diff --git a/build-logic/android-plugins/src/main/kotlin/versioning/VersioningTask.kt b/build-logic/android-plugins/src/main/kotlin/versioning/VersioningTask.kt deleted file mode 100644 index fe437c04..00000000 --- a/build-logic/android-plugins/src/main/kotlin/versioning/VersioningTask.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package 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) - } - } - - @TaskAction - fun execute() { - propertyFile.get().asFile.writeText(Semver(semverString.get()).toPropFileText()) - } -} |
