Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping tasks into group booster #342

Merged
merged 1 commit into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.didiglobal.booster

const val BOOSTER = "booster"
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.didiglobal.booster.kotlinx.file
import com.didiglobal.booster.task.analyser.Build
import com.didiglobal.booster.task.analyser.performance.reporting.PerformanceReports
import com.didiglobal.booster.task.analyser.performance.reporting.PerformanceReportsImpl
import com.didiglobal.booster.task.analyser.reference.reporting.ReferenceReports
import com.didiglobal.booster.task.analyser.reference.reporting.ReferenceReportsImpl
import com.didiglobal.booster.transform.artifacts
import groovy.lang.Closure
import org.gradle.api.Action
Expand Down Expand Up @@ -81,7 +79,9 @@ open class PerformanceAnalysisTask : DefaultTask(), Reporting<PerformanceReports
}
}

PerformanceAnalyser(variant.extension.bootClasspath, classpath, variant.artifacts, project.properties).analyse(reports.dot.destination.parentFile)
val output = project.projectDir.file("build", "reports", Build.ARTIFACT, variant.dirName)

PerformanceAnalyser(variant.extension.bootClasspath, classpath, variant.artifacts, project.properties).analyse(output)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.pipeline.TransformManager
import com.android.build.gradle.internal.pipeline.TransformTask
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.extension
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.analyser.configureReportConvention
Expand All @@ -30,17 +31,17 @@ class PerformanceAnalysisVariantProcessor : VariantProcessor {
project.tasks.named(TASK_ANALYSE_PERFORMANCE)
} catch (e: UnknownTaskException) {
project.tasks.register(TASK_ANALYSE_PERFORMANCE) {
it.description = "Analyses performance issues for Android project"
it.group = "booster"
it.description = "Analyses performance issues for Android projects"
it.group = BOOSTER
}
}

project.tasks.withType(TransformTask::class.java).find {
it.name.endsWith(variantName) && it.transform == transform
}?.let { transformTask ->
val profile = project.tasks.register("${TASK_ANALYSE_PERFORMANCE}${variantName}", PerformanceAnalysisTask::class.java) {
it.description = "Analyses performance issues for Android project"
it.group = "booster"
it.description = "Analyses performance issues for ${variant.name}"
it.group = BOOSTER
it.variant = variant
it.supplier = {
transformTask.outputs.files.single()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.android.build.gradle.BaseExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.getAndroid
import com.didiglobal.booster.gradle.getTaskName
import com.didiglobal.booster.gradle.isAndroid
Expand Down Expand Up @@ -47,8 +48,8 @@ private fun Project.setup(prerequisites: List<TaskProvider<*>>) {

private fun Project.setupJava(prerequisites: List<TaskProvider<*>>) {
tasks.register(TASK_ANALYSE_REFERENCE, ReferenceAnalysisTask::class.java) {
it.group = BOOSTER
it.description = "Analyses class reference for Java projects"
it.group = "booster"
it.variant = DEFAULT_VARIANT
it.configureReportConvention("reference", DEFAULT_VARIANT)
}.dependsOn(prerequisites)
Expand All @@ -61,13 +62,16 @@ private fun Project.setupAndroid(prerequisites: List<TaskProvider<*>>) {
else -> emptyList<BaseVariant>()
}.map { variant ->
tasks.register("${TASK_ANALYSE_REFERENCE}${variant.name.capitalize()}", ReferenceAnalysisTask::class.java) {
it.description = "Analyses class reference for Android project"
it.group = "booster"
it.group = BOOSTER
it.description = "Analyses class reference for ${variant.name}"
it.variant = variant.name
it.configureReportConvention("reference", variant.name)
}.dependsOn(prerequisites)
}
tasks.register(TASK_ANALYSE_REFERENCE).dependsOn(subtasks)
tasks.register(TASK_ANALYSE_REFERENCE) {
it.group = BOOSTER
it.description = "Analyses class reference"
}.dependsOn(subtasks)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.task.dependency

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.javaCompilerTaskProvider
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.spi.VariantProcessor
Expand All @@ -18,9 +19,14 @@ class CheckSnapshotVariantProcessor : VariantProcessor {
val checkSnapshot = try {
tasks.named(TASK_NAME)
} catch (e: UnknownTaskException) {
tasks.register(TASK_NAME)
tasks.register(TASK_NAME) {
it.group = BOOSTER
it.description = "Check snapshot dependencies"
}
}
tasks.register("check${variant.name.capitalize()}Snapshot", CheckSnapshot::class.java) {
it.group = BOOSTER
it.description = "Check snapshot dependencies for ${variant.name}"
it.variant = variant
it.outputs.upToDateWhen { false }
}.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.android.SdkConstants
import com.android.SdkConstants.DOT_PNG
import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.compression.CompressionReport
import com.didiglobal.booster.compression.CompressionResult
import com.didiglobal.booster.compression.CompressionResults
Expand Down Expand Up @@ -36,6 +37,8 @@ class ProcessedResourcesCompressionVariantProcessor : VariantProcessor {

override fun process(variant: BaseVariant) {
val compress = variant.project.tasks.register("compress${variant.name.capitalize()}ProcessedRes", CompressProcessedRes::class.java) {
it.group = BOOSTER
it.description = "Compress the processed resource file for ${variant.name}"
it.variant = variant
}
variant.processResTaskProvider?.let { processRes ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.compression

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.command.CommandInstaller
import com.didiglobal.booster.compression.task.CompressImages
import com.didiglobal.booster.compression.task.MATCH_ALL_RESOURCES
Expand Down Expand Up @@ -42,6 +43,8 @@ class SimpleCompressionTaskCreator(private val tool: CompressionTool, private va
val install = getCommandInstaller(variant)

return project.tasks.register("compress${variant.name.capitalize()}${name.capitalize()}With${tool.command.name.substringBefore('.').capitalize()}", getCompressionTaskClass(aapt2).java) { task ->
task.group = BOOSTER
task.description = "Compress image resources by ${tool.command.name} for ${variant.name}"
task.dependsOn(variant.preBuildTaskProvider.get())
task.tool = tool
task.variant = variant
Expand All @@ -57,7 +60,10 @@ class SimpleCompressionTaskCreator(private val tool: CompressionTool, private va
}

private fun getCommandInstaller(variant: BaseVariant): TaskProvider<out Task> {
return variant.project.tasks.register(getInstallTaskName(variant.name)).apply {
return variant.project.tasks.register(getInstallTaskName(variant.name)) {
it.group = BOOSTER
it.description = "Install ${tool.command.name} for ${variant.name}"
}.apply {
dependsOn(getCommandInstaller(variant.project))
dependsOn(variant.mergeResourcesTaskProvider)
}
Expand All @@ -70,6 +76,8 @@ class SimpleCompressionTaskCreator(private val tool: CompressionTool, private va
} catch (e: UnknownTaskException) {
null
} ?: project.tasks.register(name, CommandInstaller::class.java) {
it.group = BOOSTER
it.description = "Install ${tool.command.name}"
it.command = tool.command
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.task.artifact

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.spi.VariantProcessor
import com.google.auto.service.AutoService
Expand All @@ -17,9 +18,14 @@ class ListArtifactVariantProcessor : VariantProcessor {
val listArtifacts = try {
tasks.named(TASK_NAME)
} catch (e: UnknownTaskException) {
tasks.register(TASK_NAME)
tasks.register(TASK_NAME) {
it.group = BOOSTER
it.description = "List build artifacts"
}
}
tasks.register("list${variant.name.capitalize()}Artifacts", ListArtifact::class.java) {
it.group = BOOSTER
it.description = "List build artifacts for ${variant.name}"
it.variant = variant
it.outputs.upToDateWhen { false }
}.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.task.permission

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.spi.VariantProcessor
import com.google.auto.service.AutoService
Expand All @@ -17,9 +18,14 @@ class ListPermissionVariantProcessor : VariantProcessor {
val listPermissions = try {
tasks.named(TASK_NAME)
} catch (e: UnknownTaskException) {
tasks.register("listPermissions")
tasks.register("listPermissions") {
it.group = BOOSTER
it.description = "List the permissions declared in AndroidManifest.xml"
}
}
tasks.register("list${variant.name.capitalize()}Permissions", ListPermission::class.java) {
it.group = BOOSTER
it.description = "List the permission declared in AndroidManifest.xml for ${variant.name}"
it.variant = variant
it.outputs.upToDateWhen { false }
}.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.task.so

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.spi.VariantProcessor
import com.google.auto.service.AutoService
Expand All @@ -17,9 +18,14 @@ class ListSharedLibraryVariantProcessor : VariantProcessor {
val listSharedLibraries = try {
tasks.named(TASK_NAME)
} catch (e: UnknownTaskException) {
tasks.register(TASK_NAME)
tasks.register(TASK_NAME) {
it.group = BOOSTER
it.description = "List the shared libraries that current project depends on"
}
}
tasks.register("list${variant.name.capitalize()}SharedLibraries", ListSharedLibrary::class.java) {
it.group = BOOSTER
it.description = "List the shared libraries that current project depends on for ${variant.name}"
it.outputs.upToDateWhen { false }
it.variant = variant
}.also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.didiglobal.booster.task.resource.deredundancy

import com.android.build.gradle.api.BaseVariant
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.didiglobal.booster.BOOSTER
import com.didiglobal.booster.annotations.Priority
import com.didiglobal.booster.compression.CompressionResults
import com.didiglobal.booster.compression.generateReport
Expand Down Expand Up @@ -29,6 +30,8 @@ class ResourceDeredundancyVariantProcessor : VariantProcessor {
val results = CompressionResults()
val klassRemoveRedundantImages = if (project.isAapt2Enabled) RemoveRedundantFlatImages::class else RemoveRedundantImages::class
val deredundancy = variant.project.tasks.register("remove${variant.name.capitalize()}RedundantResources", klassRemoveRedundantImages.java) { task ->
task.group = BOOSTER
task.description = "Remove redundant resources for ${variant.name}"
task.outputs.upToDateWhen { false }
task.variant = variant
task.results = results
Expand Down