Use explicit Gradle tasks to handle build artifact collection (#1745)
This commit is contained in:
parent
f08ad35d2e
commit
acc448ce74
10 changed files with 98 additions and 13 deletions
|
@ -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"))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"))
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import flavors.FlavorDimensions
|
||||
import flavors.ProductFlavors
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import com.android.build.gradle.TestedExtension
|
||||
import flavors.configureSlimTests
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import artifacts.CollectApksTask
|
||||
import artifacts.CollectBundleTask
|
||||
import com.android.build.api.artifact.SingleArtifact
|
||||
|
||||
plugins { id("com.android.application") }
|
||||
|
||||
androidComponents {
|
||||
onVariants { variant ->
|
||||
project.tasks.register<CollectApksTask>("collect${variant.name.capitalize()}Apks") {
|
||||
variantName.set(variant.name)
|
||||
apkFolder.set(variant.artifacts.get(SingleArtifact.APK))
|
||||
builtArtifactsLoader.set(variant.artifacts.getBuiltArtifactsLoader())
|
||||
outputDirectory.set(project.layout.projectDirectory.dir("outputs"))
|
||||
}
|
||||
project.tasks.register<CollectBundleTask>("collect${variant.name.capitalize()}Bundle") {
|
||||
variantName.set(variant.name)
|
||||
versionName.set(android.defaultConfig.versionName)
|
||||
bundleFile.set(variant.artifacts.get(SingleArtifact.BUNDLE))
|
||||
outputDirectory.set(project.layout.projectDirectory.dir("outputs"))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ private const val EXCEPTION_MESSAGE =
|
|||
private const val CROWDIN_BUILD_API_URL =
|
||||
"https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s"
|
||||
|
||||
@Suppress("Unused")
|
||||
class CrowdinDownloadPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gradle.kotlin.dsl.register
|
|||
* Base on PublicSuffixListGenerator from OkHttp:
|
||||
* https://github.com/square/okhttp/blob/master/okhttp/src/test/java/okhttp3/internal/publicsuffix/PublicSuffixListGenerator.java
|
||||
*/
|
||||
@Suppress("Unused")
|
||||
class PublicSuffixListPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
project.tasks.register<PSLUpdateTask>("updatePSL") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue