diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-02-23 14:25:03 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-23 14:25:03 +0530 |
commit | acc448ce740b3756c622daf35d7be8372e76cebb (patch) | |
tree | d826cfae39eea5c71104e5a13cd94eea1783e36b /build-logic/android-plugins/src/main/kotlin/artifacts | |
parent | f08ad35d2e26b3f222cca4f973a865bdd815eeb3 (diff) |
Use explicit Gradle tasks to handle build artifact collection (#1745)
Diffstat (limited to 'build-logic/android-plugins/src/main/kotlin/artifacts')
-rw-r--r-- | build-logic/android-plugins/src/main/kotlin/artifacts/CollectApksTask.kt | 39 | ||||
-rw-r--r-- | build-logic/android-plugins/src/main/kotlin/artifacts/CollectBundleTask.kt | 30 |
2 files changed, 69 insertions, 0 deletions
diff --git a/build-logic/android-plugins/src/main/kotlin/artifacts/CollectApksTask.kt b/build-logic/android-plugins/src/main/kotlin/artifacts/CollectApksTask.kt new file mode 100644 index 00000000..23f94f22 --- /dev/null +++ b/build-logic/android-plugins/src/main/kotlin/artifacts/CollectApksTask.kt @@ -0,0 +1,39 @@ +package artifacts + +import com.android.build.api.variant.BuiltArtifactsLoader +import java.io.File +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.CacheableTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.PathSensitive +import org.gradle.api.tasks.PathSensitivity +import org.gradle.api.tasks.TaskAction + +/** Task to collect APKs in a given [outputDirectory]. */ +@CacheableTask +abstract class CollectApksTask : DefaultTask() { + @get:InputFiles @get:PathSensitive(PathSensitivity.NONE) abstract val apkFolder: DirectoryProperty + + @get:Input abstract val variantName: Property<String> + + @get:Internal abstract val builtArtifactsLoader: Property<BuiltArtifactsLoader> + + @get:OutputDirectory abstract val outputDirectory: DirectoryProperty + + @TaskAction + fun run() { + val outputDir = outputDirectory.asFile.get() + outputDir.mkdirs() + val builtArtifacts = + builtArtifactsLoader.get().load(apkFolder.get()) ?: throw RuntimeException("Cannot load APKs") + builtArtifacts.elements.forEach { artifact -> + File(artifact.outputFile) + .renameTo(outputDir.resolve("APS-${variantName.get()}-${artifact.versionName}.apk")) + } + } +} diff --git a/build-logic/android-plugins/src/main/kotlin/artifacts/CollectBundleTask.kt b/build-logic/android-plugins/src/main/kotlin/artifacts/CollectBundleTask.kt new file mode 100644 index 00000000..a735fb7b --- /dev/null +++ b/build-logic/android-plugins/src/main/kotlin/artifacts/CollectBundleTask.kt @@ -0,0 +1,30 @@ +package artifacts + +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +abstract class CollectBundleTask : DefaultTask() { + @get:InputFile abstract val bundleFile: RegularFileProperty + + @get:Input abstract val variantName: Property<String> + + @get:Input abstract val versionName: Property<String> + + @get:OutputDirectory abstract val outputDirectory: DirectoryProperty + + @TaskAction + fun taskAction() { + val outputDir = outputDirectory.asFile.get() + outputDir.mkdirs() + bundleFile + .get() + .asFile + .renameTo(outputDir.resolve("APS-${variantName.get()}-${versionName.get()}.aab")) + } +} |