From bbd05b72f1bc342cfe9e8d82f43459a9bb2c77af Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Fri, 29 Jul 2022 19:19:19 +0300 Subject: [PATCH] gradle-plugin: treat SarifReportMergeTask as non-mandatory ### What's done: * Root project might not have a task `mergeDiktatReports` --- .../diktat/plugin/gradle/tasks/SarifReportMergeTask.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 9d17288a01..36718bd318 100644 --- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -17,6 +17,7 @@ import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskExecutionException +import org.gradle.api.tasks.VerificationTask import kotlinx.serialization.SerializationException import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString @@ -25,7 +26,7 @@ import kotlinx.serialization.json.Json /** * A task to merge SARIF reports produced by diktat check / diktat fix tasks. */ -abstract class SarifReportMergeTask : DefaultTask() { +abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { /** * Source reports that should be merged */ @@ -89,13 +90,13 @@ internal fun Project.configureMergeReportsTask(diktatExtension: DiktatExtension) reportMergeTask.output.set(mergedReportFile) } } - val reportMergeTaskTaskProvider = rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> + rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> if (isSarifReporterActive(createReporterFlag(diktatExtension))) { getOutputFile(diktatExtension)?.let { reportMergeTask.input.from(it) } reportMergeTask.shouldRunAfter(tasks.withType(DiktatJavaExecTaskBase::class.java)) } } tasks.withType(DiktatJavaExecTaskBase::class.java).configureEach { diktatJavaExecTaskBase -> - diktatJavaExecTaskBase.finalizedBy(reportMergeTaskTaskProvider) + diktatJavaExecTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) } }