Skip to content

Commit

Permalink
Make all test tasks abstract, following gradle/gradle#22348
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Jan 26, 2023
1 parent 827dfa9 commit b164cc9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class TaskCreationConfigurationTest {
verifyNoMoreInteractions(mockConfiguration)
}

internal open class TestTask : DefaultTask()
@Suppress("UnnecessaryAbstractClass") // Gradle convention.
internal abstract class TestTask : DefaultTask()
}

private fun Project.collectCreatedTasks(): Map<String, Task> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import net.twisterrob.gradle.common.grouper.Grouper
import net.twisterrob.gradle.quality.Violations
import net.twisterrob.gradle.quality.report.TableGenerator

open class ConsoleReportTask : BaseViolationsTask() {
@Suppress("UnnecessaryAbstractClass") // Gradle convention.
abstract class ConsoleReportTask : BaseViolationsTask() {

override fun processViolations(violations: Grouper.Start<Violations>) {
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ package net.twisterrob.gradle.quality.tasks

import net.twisterrob.gradle.common.grouper.Grouper
import net.twisterrob.gradle.compat.conventionCompat
import net.twisterrob.gradle.compat.newOutputFileCompat
import net.twisterrob.gradle.dsl.reporting
import net.twisterrob.gradle.quality.Violations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.OutputFile
import java.io.File

open class FileCountReportTask : BaseViolationsTask() {
abstract class FileCountReportTask : BaseViolationsTask() {

private val outputFile: File
get() = output.asFile.get()

@get:OutputFile
val output: RegularFileProperty = newOutputFileCompat()
abstract val output: RegularFileProperty

init {
output.conventionCompat(project.reporting.baseDirectory.file("violations.count"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.android.build.api.variant.TestVariant
import com.android.build.gradle.api.AndroidBasePlugin
import com.android.build.gradle.internal.lint.AndroidLintGlobalTask
import com.android.build.gradle.internal.scope.InternalArtifactType
import net.twisterrob.gradle.android.isAbortOnErrorCompat
import net.twisterrob.gradle.android.androidComponents
import net.twisterrob.gradle.android.isAbortOnErrorCompat
import net.twisterrob.gradle.common.AGPVersions
import net.twisterrob.gradle.common.ALL_VARIANTS_NAME
import net.twisterrob.gradle.common.TaskCreationConfiguration
Expand All @@ -24,7 +24,7 @@ import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.file.RegularFile
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
Expand All @@ -35,17 +35,17 @@ import org.gradle.kotlin.dsl.withType
import se.bjurr.violations.lib.model.Violation
import java.io.File

open class GlobalLintGlobalFinalizerTask : DefaultTask() {
abstract class GlobalLintGlobalFinalizerTask : DefaultTask() {

/**
* This should only contain files that will definitely generate (i.e. `if (subTask.enabled)` in [mustRunAfter]).
* Currently, it is not the case if the submodules are configured from a parent project (see tests).
* At the usage we need to double-check if the file existed,
* otherwise it'll spam the logs with [java.io.FileNotFoundException]s.
*/
@InputFiles
@PathSensitive(PathSensitivity.NONE)
val xmlReports: MutableList<Provider<RegularFile>> = mutableListOf()
@get:InputFiles
@get:PathSensitive(PathSensitivity.NONE)
abstract val xmlReports: ListProperty<RegularFile>

@TaskAction
fun failOnFailures() {
Expand All @@ -56,7 +56,8 @@ open class GlobalLintGlobalFinalizerTask : DefaultTask() {
LintGlobalReportGathererPre7(ALL_VARIANTS_NAME)
}
val violationsByFile = xmlReports
.map { it.get().asFile }
.get()
.map { it.asFile }
.filter(File::exists)
.associateBy({ it }) { gatherer.findViolations(it) }
val totalCount = violationsByFile.values.sumBy { violations: List<Violation> -> violations.size }
Expand Down Expand Up @@ -123,8 +124,8 @@ open class GlobalLintGlobalFinalizerTask : DefaultTask() {
androidComponents.onVariants(androidComponents.selector().all()) { variant ->
if (variant !is TestVariant) {
taskProvider.configure { task ->
task.xmlReports += variant.artifacts.unwrapCast<ArtifactsImpl>()
.get(InternalArtifactType.LINT_XML_REPORT)
val artifacts = variant.artifacts.unwrapCast<ArtifactsImpl>()
task.xmlReports.add(artifacts.get(InternalArtifactType.LINT_XML_REPORT))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import com.android.utils.SdkUtils
import net.twisterrob.gradle.common.grouper.Grouper
import net.twisterrob.gradle.compat.conventionCompat
import net.twisterrob.gradle.compat.flatMapCompat
import net.twisterrob.gradle.compat.newInputFileCompat
import net.twisterrob.gradle.compat.newOutputFileCompat
import net.twisterrob.gradle.dsl.reporting
import net.twisterrob.gradle.quality.Violations
import net.twisterrob.gradle.quality.report.bestXMLTransformerFactory
Expand All @@ -22,19 +20,19 @@ import java.io.File
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource

open class HtmlReportTask : BaseViolationsTask() {
abstract class HtmlReportTask : BaseViolationsTask() {

private val xmlFile: File
get() = xml.asFile.get()

@get:OutputFile
val xml: RegularFileProperty = newOutputFileCompat()
abstract val xml: RegularFileProperty

private val htmlFile: File
get() = html.asFile.get()

@get:OutputFile
val html: RegularFileProperty = newOutputFileCompat()
abstract val html: RegularFileProperty

private val xslTemplateFile: File?
get() = xslTemplate.asFile.orNull
Expand All @@ -45,7 +43,7 @@ open class HtmlReportTask : BaseViolationsTask() {
@get:InputFile
@get:Optional
@get:PathSensitive(PathSensitivity.NONE)
val xslTemplate: RegularFileProperty = newInputFileCompat()
abstract val xslTemplate: RegularFileProperty

private val xslOutputFile: File
get() = xsl.asFile.get()
Expand All @@ -56,7 +54,7 @@ open class HtmlReportTask : BaseViolationsTask() {
*/
// TODO @InputFile as well? maybe separate task? or task steps API?
@get:OutputFile
val xsl: RegularFileProperty = newOutputFileCompat()
abstract val xsl: RegularFileProperty

init {
xml.conventionCompat(project.reporting.baseDirectory.file("violations.xml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import net.twisterrob.gradle.quality.QualityPlugin.Companion.REPORT_HTML_TASK_NA
import net.twisterrob.gradle.quality.Violations
import org.gradle.api.GradleException

open class ValidateViolationsTask : BaseViolationsTask() {
@Suppress("UnnecessaryAbstractClass") // Gradle convention.
abstract class ValidateViolationsTask : BaseViolationsTask() {

override fun processViolations(violations: Grouper.Start<Violations>) {
if (violations.list.any { it.violations.orEmpty().isNotEmpty() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.plugins.quality.PmdExtension
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.UntrackedTask

@Suppress("UnstableApiUsage", "UnnecessaryAbstractClass") // Gradle convention.
@UntrackedTask(because = "It is used to inspect Gradle state, output is console.")
abstract class VersionsTask : DefaultTask() {

Expand Down

0 comments on commit b164cc9

Please sign in to comment.