From 504c8b466c44b4a8591976ed5d8662f7c83f67fc Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 4 Jun 2022 15:24:46 +0530 Subject: android-plugins: convert to full plugins --- .../src/main/kotlin/versioning/Constants.kt | 14 ----- .../src/main/kotlin/versioning/VersioningPlugin.kt | 71 ---------------------- .../src/main/kotlin/versioning/VersioningTask.kt | 46 -------------- 3 files changed, 131 deletions(-) delete mode 100644 build-logic/android-plugins/src/main/kotlin/versioning/Constants.kt delete mode 100644 build-logic/android-plugins/src/main/kotlin/versioning/VersioningPlugin.kt delete mode 100644 build-logic/android-plugins/src/main/kotlin/versioning/VersioningTask.kt (limited to 'build-logic/android-plugins/src/main/kotlin/versioning') 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 { - - 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("clearPreRelease") { - semverString.set(version.withClearedSuffix().toString()) - propertyFile.set(propFile) - } - tasks.register("bumpMajor") { - semverString.set(version.withIncMajor().withClearedSuffix().toString()) - propertyFile.set(propFile) - } - tasks.register("bumpMinor") { - semverString.set(version.withIncMinor().withClearedSuffix().toString()) - propertyFile.set(propFile) - } - tasks.register("bumpPatch") { - semverString.set(version.withIncPatch().withClearedSuffix().toString()) - propertyFile.set(propFile) - } - tasks.register("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 - - @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()) - } -} -- cgit v1.2.3