From 34960d0190459d83da70ea7ec6dba89383e06864 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 17 Nov 2023 18:13:32 +0300 Subject: [PATCH 01/26] Support configuration of reporters in DSL ### What's done: - extended DiktatExtension to support configuration of reporters in DSL --- .../diktat/plugin/gradle/DiktatExtension.kt | 36 +++--- .../plugin/gradle/DiktatGradlePlugin.kt | 24 ++-- .../plugin/gradle/DiktatJavaExecTaskBase.kt | 9 -- .../saveourtool/diktat/plugin/gradle/Utils.kt | 80 ++----------- .../plugin/gradle/extension/Reporter.kt | 15 +++ .../plugin/gradle/extension/ReportersDsl.kt | 107 ++++++++++++++++++ .../plugin/gradle/tasks/DiktatCheckTask.kt | 12 +- .../plugin/gradle/tasks/DiktatFixTask.kt | 12 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 52 ++++++--- .../gradle/tasks/SarifReportMergeTask.kt | 25 ++-- .../plugin/gradle/DiktatGradlePluginTest.kt | 14 ++- .../plugin/gradle/DiktatJavaExecTaskTest.kt | 1 + .../plugin/gradle/ReporterSelectionTest.kt | 12 +- ...diktat-convention-configuration.gradle.kts | 17 ++- ...iktat-convention-configuration.gradle.kts_ | 25 ++++ 15 files changed, 284 insertions(+), 157 deletions(-) delete mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt create mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt create mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt create mode 100644 gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt index a51ed2152f..00983f308e 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt @@ -1,20 +1,30 @@ package com.saveourtool.diktat.plugin.gradle +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl +import org.gradle.api.Action +import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.util.PatternFilterable import org.gradle.api.tasks.util.PatternSet import java.io.File +import javax.inject.Inject /** * An extension to configure diktat in build.gradle(.kts) file * * @param patternSet + * @param reporters */ -open class DiktatExtension( - private val patternSet: PatternSet +open class DiktatExtension @Inject constructor( + private val objectFactory: ObjectFactory, + private val patternSet: PatternSet, + reporters: List, ) { + private val reportersDsl: ReportersDsl = objectFactory.newInstance(ReportersDsl::class.java, reporters) + /** * Boolean flag to support `ignoreFailures` property of [VerificationTask]. */ @@ -25,21 +35,6 @@ open class DiktatExtension( */ var debug = false - /** - * Property that will be used if you need to publish the report to GitHub - */ - var githubActions = false - - /** - * Type of the reporter to use - */ - var reporter: String = "" - - /** - * Destination for reporter. If empty, will write to stdout. - */ - var output: String = "" - /** * Baseline file, containing a list of errors that will be ignored. * If this file doesn't exist, it will be created on the first invocation. @@ -62,4 +57,11 @@ open class DiktatExtension( fun inputs(action: PatternFilterable.() -> Unit) { action(patternSet) } + + /** + * Configure reporters + * + * @param action configuration lambda for [ReportersDsl] + */ + fun reporters(action: Action): Unit = action.execute(reportersDsl) } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index 8ed30418fe..a7e1378bdc 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -1,5 +1,7 @@ package com.saveourtool.diktat.plugin.gradle +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl import com.saveourtool.diktat.plugin.gradle.tasks.DiktatCheckTask.Companion.registerDiktatCheckTask import com.saveourtool.diktat.plugin.gradle.tasks.DiktatFixTask.Companion.registerDiktatFixTask import com.saveourtool.diktat.plugin.gradle.tasks.configureMergeReportsTask @@ -10,25 +12,25 @@ import org.gradle.api.tasks.util.PatternSet /** * Plugin that configures diktat and registers tasks to run diktat */ -@Suppress("unused", "MagicNumber") class DiktatGradlePlugin : Plugin { /** * @param project a gradle [Project] that the plugin is applied to */ - @Suppress("TOO_LONG_FUNCTION") override fun apply(project: Project) { val patternSet = PatternSet() + val reporters = mutableListOf() val diktatExtension = project.extensions.create( DIKTAT_EXTENSION, DiktatExtension::class.java, - patternSet + patternSet, + reporters, ).apply { diktatConfigFile = project.rootProject.file("diktat-analysis.yml") } - project.registerDiktatCheckTask(diktatExtension, patternSet) - project.registerDiktatFixTask(diktatExtension, patternSet) - project.configureMergeReportsTask(diktatExtension) + project.registerDiktatCheckTask(diktatExtension, patternSet, reporters) + project.registerDiktatFixTask(diktatExtension, patternSet, reporters) + project.configureMergeReportsTask(reporters) } companion object { @@ -37,11 +39,6 @@ class DiktatGradlePlugin : Plugin { */ const val DIKTAT_CHECK_TASK = "diktatCheck" - /** - * DiKTat configuration - */ - const val DIKTAT_CONFIGURATION = "diktat" - /** * DiKTat extension */ @@ -56,10 +53,5 @@ class DiktatGradlePlugin : Plugin { * Name of the task that merges SARIF reports of diktat tasks */ internal const val MERGE_SARIF_REPORTS_TASK_NAME = "mergeDiktatReports" - - /** - * Version of JVM with more strict module system, which requires `add-opens` for kotlin compiler - */ - const val MIN_JVM_REQUIRES_ADD_OPENS = 16 } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt deleted file mode 100644 index 25d1093126..0000000000 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.saveourtool.diktat.plugin.gradle - -import org.gradle.api.Task - -/** - * An interface with old name for base class for backward compatibility in plugin configuration - */ -@Deprecated("will be removed in 2.x") -interface DiktatJavaExecTaskBase : Task diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/Utils.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/Utils.kt index 273f70df71..65259bf542 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/Utils.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/Utils.kt @@ -7,74 +7,18 @@ package com.saveourtool.diktat.plugin.gradle import org.gradle.api.Project -import java.io.File -import java.nio.file.Files -import java.nio.file.Path +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.Provider +import org.gradle.api.reporting.ReportingExtension /** - * @param diktatExtension - * @return returns sourceRootDir as projectDir for sarif report + * @param fileName + * @param extension + * @return default location of report with provided [extension] */ -fun Project.getSourceRootDir(diktatExtension: DiktatExtension): Path? = when { - diktatExtension.githubActions -> projectDir.toPath() - diktatExtension.reporter == "sarif" -> projectDir.toPath() - else -> null -} - -/** - * Create CLI flag to set reporter for ktlint based on [diktatExtension]. - * [DiktatExtension.githubActions] should have higher priority than a custom input. - * - * @param diktatExtension extension of type [DiktatExtension] - * @return CLI flag as string - */ -fun Project.getReporterType(diktatExtension: DiktatExtension): String { - val name = diktatExtension.reporter.trim() - val validReporters = listOf("sarif", "plain", "json", "html") - val reporterType = when { - diktatExtension.githubActions -> { - if (diktatExtension.reporter.isNotEmpty()) { - logger.warn("`diktat.githubActions` is set to true, so custom reporter [$name] will be ignored and SARIF reporter will be used") - } - "sarif" - } - name.isEmpty() -> { - logger.info("Reporter name was not set. Using 'plain' reporter") - "plain" - } - name !in validReporters -> { - logger.warn("Reporter name is invalid (provided value: [$name]). Falling back to 'plain' reporter") - "plain" - } - else -> name - } - - return reporterType -} - -/** - * Get destination file for Diktat report or null if stdout is used. - * [DiktatExtension.githubActions] should have higher priority than a custom input. - * - * @param diktatExtension extension of type [DiktatExtension] - * @return destination [File] or null if stdout is used - */ -internal fun Project.getOutputFile(diktatExtension: DiktatExtension): File? = when { - diktatExtension.githubActions -> project.layout.buildDirectory - .file("reports/diktat/diktat.sarif") - .get() - .asFile - .also { - Files.createDirectories(it.parentFile.toPath()) - } - diktatExtension.output.isNotEmpty() -> file(diktatExtension.output) - else -> null -} - -/** - * Whether SARIF reporter is enabled or not - * - * @param reporterFlag - * @return whether SARIF reporter is enabled - */ -internal fun isSarifReporterActive(reporterFlag: String) = reporterFlag.contains("sarif") +internal fun Project.defaultReportLocation( + extension: String, + fileName: String = "diktat", +): Provider = project.layout + .buildDirectory + .file("${ReportingExtension.DEFAULT_REPORTS_DIR_NAME}/diktat/$fileName.$extension") diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt new file mode 100644 index 0000000000..d7d129f931 --- /dev/null +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt @@ -0,0 +1,15 @@ +package com.saveourtool.diktat.plugin.gradle.extension + +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input + +/** + * A base interface for reporter + */ +interface Reporter { + /** + * Location for output + */ + val output: RegularFileProperty +} diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt new file mode 100644 index 0000000000..c5ecbc3b1e --- /dev/null +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt @@ -0,0 +1,107 @@ +package com.saveourtool.diktat.plugin.gradle.extension + +import com.saveourtool.diktat.plugin.gradle.defaultReportLocation +import org.gradle.api.Action +import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import javax.inject.Inject + +/** + * Configuration for reporters + */ +abstract class ReportersDsl @Inject constructor( + private val project: Project, + private val objectFactory: ObjectFactory, + private val values: MutableList, +) { + + fun plain(action: Action): Unit = action.execute(newReporter("txt")) + + fun plain() { + plain(emptyAction()) + } + + + fun json(action: Action): Unit = action.execute(newReporter("json")) + + fun json() { + json(emptyAction()) + } + + fun sarif(action: Action): Unit = action.execute(newReporter("json")) + + fun sarif() { + sarif(emptyAction()) + } + + fun githubAction() { + sarif(Action { + it.output.set(project.defaultReportLocation(extension = "sarif")) + it.mergeOutput.set(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) + }) + } + + fun checkstyle(action: Action): Unit = action.execute(newReporter("xml")) + + fun checkstyle() { + checkstyle(emptyAction()) + } + + fun html() { + newReporter("html") + } + + fun html(action: Action): Unit = action.execute(newReporter("html")) + + fun custom(action: Action): Unit = action.execute(newReporter()) + + private inline fun newReporter(extension: String? = null): T = objectFactory.newInstance(T::class.java) + .apply { values.add(this) } + .also { reporter -> + extension?.run { + reporter.output.convention(project.defaultReportLocation(extension)) + } + } + + private inline fun emptyAction() = Action { } + + companion object { + fun Reporter.getId(): String = when (this) { + is JsonReporter -> "json" + is SarifReporter -> "sarif" + is CheckstyleReporter -> "checkstyle" + is HtmlReporter -> "html" + is PlainReporter -> "plain" + is CustomReporter -> id.get() + else -> error("Not supported reporter ${this.javaClass.name}") + } + } +} + + +abstract class JsonReporter: Reporter + +abstract class SarifReporter: Reporter { + /** + * Location for merged output + */ + abstract val mergeOutput: RegularFileProperty +} +abstract class CheckstyleReporter: Reporter +abstract class HtmlReporter: Reporter +abstract class PlainReporter: Reporter + +abstract class CustomReporter : Reporter { + /** + * id of reporter for custom reporter + */ + abstract val id: Property + + /** + * dependency for custom reporter + */ + abstract val dependency: Property +} + diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt index 6f656825a8..c84e2303f7 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt @@ -4,6 +4,8 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl import org.gradle.api.Project import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.util.PatternFilterable @@ -15,8 +17,9 @@ import javax.inject.Inject */ abstract class DiktatCheckTask @Inject constructor( extension: DiktatExtension, - inputs: PatternFilterable -) : DiktatTaskBase(extension, inputs) { + inputs: PatternFilterable, + reporters: List, +) : DiktatTaskBase(extension, inputs, reporters) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments @@ -30,11 +33,12 @@ abstract class DiktatCheckTask @Inject constructor( */ fun Project.registerDiktatCheckTask( diktatExtension: DiktatExtension, - patternSet: PatternSet + patternSet: PatternSet, + reporters: List, ): TaskProvider = tasks.register( DiktatGradlePlugin.DIKTAT_CHECK_TASK, DiktatCheckTask::class.java, - diktatExtension, patternSet + diktatExtension, patternSet, reporters, ) } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt index 0e7fdc4e4e..3cad9fcbe5 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt @@ -4,6 +4,8 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl import org.gradle.api.Project import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.util.PatternFilterable @@ -15,8 +17,9 @@ import javax.inject.Inject */ abstract class DiktatFixTask @Inject constructor( extension: DiktatExtension, - inputs: PatternFilterable -) : DiktatTaskBase(extension, inputs) { + inputs: PatternFilterable, + reporters: List, +) : DiktatTaskBase(extension, inputs, reporters) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments @@ -32,11 +35,12 @@ abstract class DiktatFixTask @Inject constructor( */ fun Project.registerDiktatFixTask( diktatExtension: DiktatExtension, - patternSet: PatternSet + patternSet: PatternSet, + reporters: List, ): TaskProvider = tasks.register( DiktatGradlePlugin.DIKTAT_FIX_TASK, DiktatFixTask::class.java, - diktatExtension, patternSet + diktatExtension, patternSet, reporters, ) } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index d200f19278..ad57055318 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -9,8 +9,8 @@ import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl import com.saveourtool.diktat.plugin.gradle.DiktatExtension -import com.saveourtool.diktat.plugin.gradle.getOutputFile -import com.saveourtool.diktat.plugin.gradle.getReporterType +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl.Companion.getId import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl @@ -19,13 +19,17 @@ import generated.KTLINT_VERSION import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.file.FileCollection +import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.IgnoreEmptyDirectories +import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Optional import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SkipWhenEmpty import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.VerificationTask import org.gradle.api.tasks.util.PatternFilterable import org.gradle.language.base.plugins.LifecycleBasePlugin @@ -35,14 +39,23 @@ import java.nio.file.Path /** * A base task to run `diktat` * - * @param inputs * @property extension + * @param inputs + * @param reporters */ @Suppress("WRONG_NEWLINES", "Deprecation") abstract class DiktatTaskBase( @get:Internal internal val extension: DiktatExtension, private val inputs: PatternFilterable, -) : DefaultTask(), VerificationTask, com.saveourtool.diktat.plugin.gradle.DiktatJavaExecTaskBase { + private val reporters: List, +) : DefaultTask(), VerificationTask { + @get:InputFile + abstract val configFile: RegularFileProperty + + @get:Optional + @get:InputFile + abstract val baselineFile: RegularFileProperty + /** * Files that will be analyzed by diktat */ @@ -85,12 +98,14 @@ abstract class DiktatTaskBase( val sourceRootDir by lazy { project.rootProject.projectDir.toPath() } - val reporterId = project.getReporterType(extension) - val reporterCreationArguments = DiktatReporterCreationArguments( - id = reporterId, - outputStream = project.getOutputFile(extension)?.outputStream(), - sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, - ) + val reporterCreationArgumentsList = reporters.map { reporter -> + val reporterId = reporter.getId() + DiktatReporterCreationArguments( + id = reporterId, + outputStream = reporter.output.map { it.asFile.outputStream() }.orNull, + sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, + ) + } val loggingListener = object : DiktatProcessorListener { override fun beforeAll(files: Collection) { project.logger.info("Analyzing {} files with diktat in project {}", files.size, project.name) @@ -101,11 +116,11 @@ abstract class DiktatTaskBase( } } DiktatRunnerArguments( - configFile = extension.diktatConfigFile.toPath(), + configInputStream = configFile.get().asFile.inputStream(), sourceRootDir = sourceRootDir, files = actualInputs.files.map { it.toPath() }, - baselineFile = extension.baseline?.let { project.file(it).toPath() }, - reporterArgsList = listOf(reporterCreationArguments), + baselineFile = baselineFile.map { it.asFile.toPath() }.orNull, + reporterArgsList = reporterCreationArgumentsList, loggingListener = loggingListener, ) } @@ -119,7 +134,6 @@ abstract class DiktatTaskBase( } init { - ignoreFailures = extension.ignoreFailures group = LifecycleBasePlugin.VERIFICATION_GROUP } @@ -166,4 +180,14 @@ abstract class DiktatTaskBase( runner: DiktatRunner, args: DiktatRunnerArguments ): Int + + companion object { + fun TaskProvider.configure(extension: DiktatExtension) { + configure { + it.configFile.set(it.project.file(extension.diktatConfigFile)) + extension.baseline.let { baseline -> it.baselineFile.set(it.project.file(baseline)) } + it.ignoreFailures = extension.ignoreFailures + } + } + } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 7991df9f01..5525fbbe4e 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -2,9 +2,8 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME -import com.saveourtool.diktat.plugin.gradle.getOutputFile -import com.saveourtool.diktat.plugin.gradle.getReporterType -import com.saveourtool.diktat.plugin.gradle.isSarifReporterActive +import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.SarifReporter import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask @@ -20,7 +19,6 @@ import org.gradle.api.tasks.TaskExecutionException import org.gradle.api.tasks.VerificationTask import kotlinx.serialization.SerializationException -import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -82,21 +80,26 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { /** * @param diktatExtension extension of type [DiktatExtension] */ -internal fun Project.configureMergeReportsTask(diktatExtension: DiktatExtension) { +internal fun Project.configureMergeReportsTask( + reporters: List, +) { if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> + reporters.filterIsInstance() + .map { reporter -> reporter.mergeOutput.zip(reporter.output, ::Pair) } + .forEach { pair -> + reportMergeTask.inputs.file(pair.map { it.first }) + reportMergeTask.inputs.file(pair.map { it.second }) + } val mergedReportFile = project.layout.buildDirectory.file("reports/diktat/diktat-merged.sarif") reportMergeTask.outputs.file(mergedReportFile) reportMergeTask.output.set(mergedReportFile) } } rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> - if (isSarifReporterActive(getReporterType(diktatExtension))) { - getOutputFile(diktatExtension)?.let { reportMergeTask.input.from(it) } - reportMergeTask.shouldRunAfter(tasks.withType(DiktatTaskBase::class.java)) - } + reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) } - tasks.withType(DiktatTaskBase::class.java).configureEach { diktatJavaExecTaskBase -> - diktatJavaExecTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) + tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> + diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) } } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt index 18c9f2a46a..f37d58583d 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt @@ -5,7 +5,9 @@ import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.junit.jupiter.api.fail class DiktatGradlePluginTest { private val projectBuilder = ProjectBuilder.builder() @@ -39,11 +41,13 @@ class DiktatGradlePluginTest { } @Test + @Disabled fun `check default reporter type value`() { - val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension - Assertions.assertEquals("", diktatExtension.reporter) - - val reporterFlag = project.getReporterType(diktatExtension) - Assertions.assertEquals("plain", reporterFlag) + fail("need to fix") +// val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension +// Assertions.assertEquals("", diktatExtension.reporter) +// +// val reporterFlag = project.getReporterType(diktatExtension) +// Assertions.assertEquals("plain", reporterFlag) } } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index c5b4d1430f..af924ecc78 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -155,6 +155,7 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") + githubActions = true reporter = "json" output = "report.json" diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt index 3d9d9e71d4..c9c2e0d48a 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt @@ -5,7 +5,9 @@ import org.gradle.api.tasks.util.PatternSet import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.junit.jupiter.api.fail class ReporterSelectionTest { private val projectBuilder = ProjectBuilder.builder() @@ -21,14 +23,8 @@ class ReporterSelectionTest { } @Test + @Disabled("FIXME") fun `should fallback to plain reporter for unknown reporter types`() { - val diktatExtension = DiktatExtension(PatternSet()).apply { - reporter = "jsonx" - } - - Assertions.assertEquals( - "plain", - project.getReporterType(diktatExtension) - ) + fail("need to test default behaviour") } } diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts index 532aba2bf6..ec9a6892ad 100644 --- a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts @@ -6,7 +6,22 @@ plugins { diktat { diktatConfigFile = rootProject.file("diktat-analysis.yml") - githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false +// githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false + + +// reporters { +// directory = project.rootProject.layout.buildDirectory.file("reports/diktat") +// json { +// output = "report.json" +// } +// sarif { +// mergeOutput = "" +// } +// custom { +// dependency = "bla.bla:foo.foo:1.2.3" +// output = "report.txt" +// } +// } inputs { // using `Project#path` here, because it must be unique in gradle's project hierarchy if (path == rootProject.path) { diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ new file mode 100644 index 0000000000..532aba2bf6 --- /dev/null +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ @@ -0,0 +1,25 @@ +package com.saveourtool.diktat.buildutils + +plugins { + id("com.saveourtool.diktat") +} + +diktat { + diktatConfigFile = rootProject.file("diktat-analysis.yml") + githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false + inputs { + // using `Project#path` here, because it must be unique in gradle's project hierarchy + if (path == rootProject.path) { + include("gradle/plugins/src/**/*.kt", "*.kts", "gradle/plugins/**/*.kts") + exclude("gradle/plugins/build/**") + } else { + include("src/**/*.kt", "**/*.kts") + exclude( + "src/test/**/*.kt", + "src/test/**/*.kts", + "src/*Test/**/*.kt", + "build/**/*.kts", + ) + } + } +} From 70bd8e5b3fbafc681ba93dbd356b84c3b26da02f Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Fri, 17 Nov 2023 18:35:54 +0300 Subject: [PATCH 02/26] fixed found issues --- .../plugin/gradle/tasks/DiktatCheckTask.kt | 2 +- .../plugin/gradle/tasks/DiktatFixTask.kt | 2 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 28 ++++++++++------- .../plugin/gradle/DiktatJavaExecTaskTest.kt | 30 +++++++++++++------ 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt index c84e2303f7..c03376cc12 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt @@ -39,6 +39,6 @@ abstract class DiktatCheckTask @Inject constructor( tasks.register( DiktatGradlePlugin.DIKTAT_CHECK_TASK, DiktatCheckTask::class.java, diktatExtension, patternSet, reporters, - ) + ).also { it.configure(diktatExtension) } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt index 3cad9fcbe5..a7cc8de574 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt @@ -41,6 +41,6 @@ abstract class DiktatFixTask @Inject constructor( tasks.register( DiktatGradlePlugin.DIKTAT_FIX_TASK, DiktatFixTask::class.java, diktatExtension, patternSet, reporters, - ) + ).also { it.configure(diktatExtension) } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index ad57055318..4a522adc2f 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -9,6 +9,7 @@ import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl import com.saveourtool.diktat.plugin.gradle.DiktatExtension +import com.saveourtool.diktat.plugin.gradle.extension.PlainReporter import com.saveourtool.diktat.plugin.gradle.extension.Reporter import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl.Companion.getId import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl @@ -33,6 +34,7 @@ import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.VerificationTask import org.gradle.api.tasks.util.PatternFilterable import org.gradle.language.base.plugins.LifecycleBasePlugin +import java.nio.file.Files import java.nio.file.Path @@ -98,14 +100,18 @@ abstract class DiktatTaskBase( val sourceRootDir by lazy { project.rootProject.projectDir.toPath() } - val reporterCreationArgumentsList = reporters.map { reporter -> - val reporterId = reporter.getId() - DiktatReporterCreationArguments( - id = reporterId, - outputStream = reporter.output.map { it.asFile.outputStream() }.orNull, - sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, - ) + val defaultPlainReporter by lazy { + project.objects.newInstance(PlainReporter::class.java) } + val reporterCreationArgumentsList = (reporters.takeUnless { it.isEmpty() } ?: listOf(defaultPlainReporter)) + .map { reporter -> + val reporterId = reporter.getId() + DiktatReporterCreationArguments( + id = reporterId, + outputStream = reporter.output.map { file -> file.asFile.also { Files.createDirectories(it.parentFile.toPath()) }.outputStream() }.orNull, + sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, + ) + } val loggingListener = object : DiktatProcessorListener { override fun beforeAll(files: Collection) { project.logger.info("Analyzing {} files with diktat in project {}", files.size, project.name) @@ -183,10 +189,10 @@ abstract class DiktatTaskBase( companion object { fun TaskProvider.configure(extension: DiktatExtension) { - configure { - it.configFile.set(it.project.file(extension.diktatConfigFile)) - extension.baseline.let { baseline -> it.baselineFile.set(it.project.file(baseline)) } - it.ignoreFailures = extension.ignoreFailures + configure { task -> + task.configFile.set(task.project.file(extension.diktatConfigFile)) + extension.baseline?.let { baseline -> task.baselineFile.set(task.project.file(baseline)) } + task.ignoreFailures = extension.ignoreFailures } } } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index af924ecc78..b35fa04230 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -7,6 +7,7 @@ import com.saveourtool.diktat.util.DiktatProcessorListenerWrapper.Companion.unwr import com.pinterest.ktlint.cli.reporter.json.JsonReporter import com.pinterest.ktlint.cli.reporter.plain.PlainReporter import com.pinterest.ktlint.cli.reporter.sarif.SarifReporter +import org.gradle.api.Action import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder @@ -117,8 +118,11 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - reporter = "json" - output = "some.txt" + reporters { reportersDsl -> + reportersDsl.json { jsonDsl -> + jsonDsl.output.set(project.layout.buildDirectory.file("some.txt")) + } + } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is JsonReporter) @@ -129,7 +133,9 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - reporter = "json" + reporters { reportersDsl -> + reportersDsl.json() + } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is JsonReporter) @@ -140,7 +146,9 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - githubActions = true + reporters { reportersDsl -> + reportersDsl.githubAction() + } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is SarifReporter) @@ -155,10 +163,12 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - - githubActions = true - reporter = "json" - output = "report.json" + reporters { reportersDsl -> + reportersDsl.githubAction() + reportersDsl.json { jsonDsl -> + jsonDsl.output.set(project.layout.buildDirectory.file("report.json")) + } + } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is SarifReporter) @@ -173,7 +183,9 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - reporter = "sarif" + reporters { reportersDsl -> + reportersDsl.sarif() + } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is SarifReporter) From 55e1bbdf02b3965a8c63a5581e9aeaf4ece1ad29 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 15:09:34 +0300 Subject: [PATCH 03/26] a small refactoring --- .../diktat/plugin/gradle/DiktatExtension.kt | 15 ++- .../plugin/gradle/DiktatGradlePlugin.kt | 5 +- .../gradle/extension/DefaultReporter.kt | 68 +++++++++++ .../plugin/gradle/extension/Reporter.kt | 9 +- .../plugin/gradle/extension/Reporters.kt | 102 +++++++++++++++++ .../plugin/gradle/extension/ReportersDsl.kt | 107 ------------------ .../plugin/gradle/tasks/DiktatCheckTask.kt | 11 +- .../plugin/gradle/tasks/DiktatFixTask.kt | 10 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 32 ++++-- .../gradle/tasks/SarifReportMergeTask.kt | 4 +- 10 files changed, 220 insertions(+), 143 deletions(-) create mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt create mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt delete mode 100644 diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt index 00983f308e..8ea48e7363 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt @@ -1,10 +1,10 @@ package com.saveourtool.diktat.plugin.gradle -import com.saveourtool.diktat.plugin.gradle.extension.Reporter -import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl +import com.saveourtool.diktat.plugin.gradle.extension.Reporters import org.gradle.api.Action import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.util.PatternFilterable @@ -16,14 +16,13 @@ import javax.inject.Inject * An extension to configure diktat in build.gradle(.kts) file * * @param patternSet - * @param reporters */ open class DiktatExtension @Inject constructor( - private val objectFactory: ObjectFactory, + objectFactory: ObjectFactory, private val patternSet: PatternSet, - reporters: List, ) { - private val reportersDsl: ReportersDsl = objectFactory.newInstance(ReportersDsl::class.java, reporters) + @get:Internal + val reporters: Reporters = objectFactory.newInstance(Reporters::class.java) /** * Boolean flag to support `ignoreFailures` property of [VerificationTask]. @@ -61,7 +60,7 @@ open class DiktatExtension @Inject constructor( /** * Configure reporters * - * @param action configuration lambda for [ReportersDsl] + * @param action configuration lambda for [Reporters] */ - fun reporters(action: Action): Unit = action.execute(reportersDsl) + fun reporters(action: Action): Unit = action.execute(reporters) } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index a7e1378bdc..3e8f5a351e 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -1,7 +1,6 @@ package com.saveourtool.diktat.plugin.gradle -import com.saveourtool.diktat.plugin.gradle.extension.Reporter -import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl +import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.tasks.DiktatCheckTask.Companion.registerDiktatCheckTask import com.saveourtool.diktat.plugin.gradle.tasks.DiktatFixTask.Companion.registerDiktatFixTask import com.saveourtool.diktat.plugin.gradle.tasks.configureMergeReportsTask @@ -18,7 +17,7 @@ class DiktatGradlePlugin : Plugin { */ override fun apply(project: Project) { val patternSet = PatternSet() - val reporters = mutableListOf() + val reporters = mutableListOf() val diktatExtension = project.extensions.create( DIKTAT_EXTENSION, DiktatExtension::class.java, diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt new file mode 100644 index 0000000000..1a0e9e3df2 --- /dev/null +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -0,0 +1,68 @@ +package com.saveourtool.diktat.plugin.gradle.extension + +import com.saveourtool.diktat.plugin.gradle.defaultReportLocation +import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory +import javax.inject.Inject + +/** + * A base interface for reporter + * + * @property id identifier of reporter + * @param extension extension of generated report + * @param objectFactory + * @param project + */ +abstract class DefaultReporter @Inject constructor( + val id: String, + extension: String, + objectFactory: ObjectFactory, + project: Project, +): Reporter() { + override val output: RegularFileProperty = objectFactory.fileProperty() + .also { fileProperty -> + fileProperty.set(project.defaultReportLocation(extension = extension)) + } +} + + +abstract class PlainReporter @Inject constructor( + objectFactory: ObjectFactory, + project: Project, +): DefaultReporter("plain", "txt", objectFactory, project) + +abstract class JsonReporter @Inject constructor( + objectFactory: ObjectFactory, + project: Project, +): DefaultReporter("json", "json", objectFactory, project) + +abstract class SarifReporter @Inject constructor( + objectFactory: ObjectFactory, + project: Project, +): DefaultReporter("sarif", "sarif", objectFactory, project) { + /** + * Location for merged output + */ + abstract val mergeOutput: RegularFileProperty +} + +abstract class GithubActionsReporter @Inject constructor( + project: Project, + objectFactory: ObjectFactory, +) : SarifReporter(objectFactory, project) { + override val mergeOutput: RegularFileProperty = objectFactory.fileProperty() + .also { fileProperty -> + fileProperty.set(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) + } +} + +abstract class CheckstyleReporter @Inject constructor( + objectFactory: ObjectFactory, + project: Project, +): DefaultReporter("checkstyle", "xml", objectFactory, project) + +abstract class HtmlReporter @Inject constructor( + objectFactory: ObjectFactory, + project: Project, +): DefaultReporter("html", "html", objectFactory, project) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt index d7d129f931..91b56c270b 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt @@ -1,15 +1,16 @@ package com.saveourtool.diktat.plugin.gradle.extension import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import javax.inject.Inject /** * A base interface for reporter */ -interface Reporter { +abstract class Reporter { /** * Location for output */ - val output: RegularFileProperty + @get:OutputFile + abstract val output: RegularFileProperty } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt new file mode 100644 index 0000000000..d093b7910b --- /dev/null +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt @@ -0,0 +1,102 @@ +package com.saveourtool.diktat.plugin.gradle.extension + +import org.gradle.api.Action +import org.gradle.api.model.ObjectFactory +import javax.inject.Inject + +/** + * Configuration for reporters + */ +open class Reporters @Inject constructor( + private val objectFactory: ObjectFactory, +) { + /** + * All reporters + */ + val all: MutableList = mutableListOf() + + /** + * Configure *plain* reporter with [action] configuration + * + * @param action + */ + fun plain(action: Action): Unit = action.execute(newReporter()) + + /** + * Configure *plain* reporter with default configuration + */ + fun plain() { + plain(emptyAction()) + } + + /** + * Configure *json* reporter with [action] configuration + * + * @param action + */ + fun json(action: Action): Unit = action.execute(newReporter()) + + /** + * Configure *json* reporter with default configuration + */ + fun json() { + json(emptyAction()) + } + + /** + * Configure *sarif* reporter with [action] configuration + * + * @param action + */ + fun sarif(action: Action): Unit = action.execute(newReporter()) + + /** + * Configure *sarif* reporter with default configuration + */ + fun sarif() { + sarif(emptyAction()) + } + + /** + * Configure *sarif* reporter for github actions + */ + fun githubAction() { + newReporter() + } + + /** + * Configure *checkstyle* reporter with [action] configuration + * + * @param action + */ + fun checkstyle(action: Action): Unit = action.execute(newReporter()) + + /** + * Configure *checkstyle* reporter with default configuration + */ + fun checkstyle() { + checkstyle(emptyAction()) + } + + /** + * Configure *html* reporter with default configuration + */ + fun html() { + html(emptyAction()) + } + + /** + * Configure *html* reporter with [action] configuration + * + * @param action + */ + fun html(action: Action): Unit = action.execute(newReporter()) + + private inline fun newReporter(): T = objectFactory.newInstance(T::class.java) + .apply { all.add(this) } + + private inline fun emptyAction() = Action { } +} + + + diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt deleted file mode 100644 index c5ecbc3b1e..0000000000 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/ReportersDsl.kt +++ /dev/null @@ -1,107 +0,0 @@ -package com.saveourtool.diktat.plugin.gradle.extension - -import com.saveourtool.diktat.plugin.gradle.defaultReportLocation -import org.gradle.api.Action -import org.gradle.api.Project -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.model.ObjectFactory -import org.gradle.api.provider.Property -import javax.inject.Inject - -/** - * Configuration for reporters - */ -abstract class ReportersDsl @Inject constructor( - private val project: Project, - private val objectFactory: ObjectFactory, - private val values: MutableList, -) { - - fun plain(action: Action): Unit = action.execute(newReporter("txt")) - - fun plain() { - plain(emptyAction()) - } - - - fun json(action: Action): Unit = action.execute(newReporter("json")) - - fun json() { - json(emptyAction()) - } - - fun sarif(action: Action): Unit = action.execute(newReporter("json")) - - fun sarif() { - sarif(emptyAction()) - } - - fun githubAction() { - sarif(Action { - it.output.set(project.defaultReportLocation(extension = "sarif")) - it.mergeOutput.set(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) - }) - } - - fun checkstyle(action: Action): Unit = action.execute(newReporter("xml")) - - fun checkstyle() { - checkstyle(emptyAction()) - } - - fun html() { - newReporter("html") - } - - fun html(action: Action): Unit = action.execute(newReporter("html")) - - fun custom(action: Action): Unit = action.execute(newReporter()) - - private inline fun newReporter(extension: String? = null): T = objectFactory.newInstance(T::class.java) - .apply { values.add(this) } - .also { reporter -> - extension?.run { - reporter.output.convention(project.defaultReportLocation(extension)) - } - } - - private inline fun emptyAction() = Action { } - - companion object { - fun Reporter.getId(): String = when (this) { - is JsonReporter -> "json" - is SarifReporter -> "sarif" - is CheckstyleReporter -> "checkstyle" - is HtmlReporter -> "html" - is PlainReporter -> "plain" - is CustomReporter -> id.get() - else -> error("Not supported reporter ${this.javaClass.name}") - } - } -} - - -abstract class JsonReporter: Reporter - -abstract class SarifReporter: Reporter { - /** - * Location for merged output - */ - abstract val mergeOutput: RegularFileProperty -} -abstract class CheckstyleReporter: Reporter -abstract class HtmlReporter: Reporter -abstract class PlainReporter: Reporter - -abstract class CustomReporter : Reporter { - /** - * id of reporter for custom reporter - */ - abstract val id: Property - - /** - * dependency for custom reporter - */ - abstract val dependency: Property -} - diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt index c03376cc12..310d20dd55 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt @@ -4,9 +4,9 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin -import com.saveourtool.diktat.plugin.gradle.extension.Reporter -import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl +import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.util.PatternFilterable import org.gradle.api.tasks.util.PatternSet @@ -18,8 +18,8 @@ import javax.inject.Inject abstract class DiktatCheckTask @Inject constructor( extension: DiktatExtension, inputs: PatternFilterable, - reporters: List, -) : DiktatTaskBase(extension, inputs, reporters) { + objectFactory: ObjectFactory, +) : DiktatTaskBase(extension, inputs, objectFactory) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments @@ -34,11 +34,10 @@ abstract class DiktatCheckTask @Inject constructor( fun Project.registerDiktatCheckTask( diktatExtension: DiktatExtension, patternSet: PatternSet, - reporters: List, ): TaskProvider = tasks.register( DiktatGradlePlugin.DIKTAT_CHECK_TASK, DiktatCheckTask::class.java, - diktatExtension, patternSet, reporters, + diktatExtension, patternSet, ).also { it.configure(diktatExtension) } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt index a7cc8de574..1011b4c591 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt @@ -4,9 +4,9 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin -import com.saveourtool.diktat.plugin.gradle.extension.Reporter -import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl +import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.util.PatternFilterable import org.gradle.api.tasks.util.PatternSet @@ -18,8 +18,8 @@ import javax.inject.Inject abstract class DiktatFixTask @Inject constructor( extension: DiktatExtension, inputs: PatternFilterable, - reporters: List, -) : DiktatTaskBase(extension, inputs, reporters) { + objectFactory: ObjectFactory, +) : DiktatTaskBase(extension, inputs, objectFactory) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments @@ -36,7 +36,7 @@ abstract class DiktatFixTask @Inject constructor( fun Project.registerDiktatFixTask( diktatExtension: DiktatExtension, patternSet: PatternSet, - reporters: List, + reporters: List, ): TaskProvider = tasks.register( DiktatGradlePlugin.DIKTAT_FIX_TASK, DiktatFixTask::class.java, diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 4a522adc2f..6db8dca18f 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -9,9 +9,9 @@ import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl import com.saveourtool.diktat.plugin.gradle.DiktatExtension +import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.extension.PlainReporter -import com.saveourtool.diktat.plugin.gradle.extension.Reporter -import com.saveourtool.diktat.plugin.gradle.extension.ReportersDsl.Companion.getId +import com.saveourtool.diktat.plugin.gradle.extension.Reporters import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl @@ -19,13 +19,16 @@ import generated.DIKTAT_VERSION import generated.KTLINT_VERSION import org.gradle.api.DefaultTask import org.gradle.api.GradleException +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.IgnoreEmptyDirectories import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFiles import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SkipWhenEmpty @@ -43,13 +46,12 @@ import java.nio.file.Path * * @property extension * @param inputs - * @param reporters */ @Suppress("WRONG_NEWLINES", "Deprecation") abstract class DiktatTaskBase( @get:Internal internal val extension: DiktatExtension, private val inputs: PatternFilterable, - private val reporters: List, + objectFactory: ObjectFactory, ) : DefaultTask(), VerificationTask { @get:InputFile abstract val configFile: RegularFileProperty @@ -77,6 +79,19 @@ abstract class DiktatTaskBase( ) } + @get:Internal + abstract val reporters: Reporters + + @get:Internal + @get:OutputFiles + @get:Optional + val reporterOutputs: ConfigurableFileCollection = objectFactory.fileCollection() + .also { fileCollection -> + fileCollection.setFrom(reporters.all.mapNotNull { it.output.orNull }) + fileCollection.finalizeValue() + } + + /** * Whether diktat should be executed */ @@ -103,13 +118,13 @@ abstract class DiktatTaskBase( val defaultPlainReporter by lazy { project.objects.newInstance(PlainReporter::class.java) } - val reporterCreationArgumentsList = (reporters.takeUnless { it.isEmpty() } ?: listOf(defaultPlainReporter)) + val reporterCreationArgumentsList = (reporters.all.takeUnless { it.isEmpty() } ?: listOf(defaultPlainReporter)) + .filterIsInstance() .map { reporter -> - val reporterId = reporter.getId() DiktatReporterCreationArguments( - id = reporterId, + id = reporter.id, outputStream = reporter.output.map { file -> file.asFile.also { Files.createDirectories(it.parentFile.toPath()) }.outputStream() }.orNull, - sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, + sourceRootDir = sourceRootDir.takeIf { reporter.id == "sarif" }, ) } val loggingListener = object : DiktatProcessorListener { @@ -193,6 +208,7 @@ abstract class DiktatTaskBase( task.configFile.set(task.project.file(extension.diktatConfigFile)) extension.baseline?.let { baseline -> task.baselineFile.set(task.project.file(baseline)) } task.ignoreFailures = extension.ignoreFailures + task.reporters.all.addAll(extension.reporters.all) } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 5525fbbe4e..c051ca61d7 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -2,7 +2,7 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME -import com.saveourtool.diktat.plugin.gradle.extension.Reporter +import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.extension.SarifReporter import io.github.detekt.sarif4k.SarifSchema210 @@ -81,7 +81,7 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { * @param diktatExtension extension of type [DiktatExtension] */ internal fun Project.configureMergeReportsTask( - reporters: List, + reporters: List, ) { if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> From 6aa4ffbb29faef57eacb02dfe473b9d87e97b4d2 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 15:12:40 +0300 Subject: [PATCH 04/26] fixed compilation error --- .../saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt | 6 +++--- .../saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt | 3 +-- .../diktat/plugin/gradle/tasks/SarifReportMergeTask.kt | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index 3e8f5a351e..e74c0aab34 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -27,9 +27,9 @@ class DiktatGradlePlugin : Plugin { diktatConfigFile = project.rootProject.file("diktat-analysis.yml") } - project.registerDiktatCheckTask(diktatExtension, patternSet, reporters) - project.registerDiktatFixTask(diktatExtension, patternSet, reporters) - project.configureMergeReportsTask(reporters) + project.registerDiktatCheckTask(diktatExtension, patternSet) + project.registerDiktatFixTask(diktatExtension, patternSet) + project.configureMergeReportsTask(diktatExtension) } companion object { diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt index 1011b4c591..032a2b09b2 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt @@ -36,11 +36,10 @@ abstract class DiktatFixTask @Inject constructor( fun Project.registerDiktatFixTask( diktatExtension: DiktatExtension, patternSet: PatternSet, - reporters: List, ): TaskProvider = tasks.register( DiktatGradlePlugin.DIKTAT_FIX_TASK, DiktatFixTask::class.java, - diktatExtension, patternSet, reporters, + diktatExtension, patternSet, ).also { it.configure(diktatExtension) } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index c051ca61d7..b584f524e2 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -2,7 +2,6 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME -import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.extension.SarifReporter import io.github.detekt.sarif4k.SarifSchema210 @@ -81,11 +80,12 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { * @param diktatExtension extension of type [DiktatExtension] */ internal fun Project.configureMergeReportsTask( - reporters: List, + diktatExtension: DiktatExtension, ) { if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - reporters.filterIsInstance() + diktatExtension.reporters.all + .filterIsInstance() .map { reporter -> reporter.mergeOutput.zip(reporter.output, ::Pair) } .forEach { pair -> reportMergeTask.inputs.file(pair.map { it.first }) From 38d21615ee5fc329156203321725cb3cf24fa433 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 15:40:16 +0300 Subject: [PATCH 05/26] fixed compilation error --- .../com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index e74c0aab34..5dce0c250f 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -1,6 +1,5 @@ package com.saveourtool.diktat.plugin.gradle -import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.tasks.DiktatCheckTask.Companion.registerDiktatCheckTask import com.saveourtool.diktat.plugin.gradle.tasks.DiktatFixTask.Companion.registerDiktatFixTask import com.saveourtool.diktat.plugin.gradle.tasks.configureMergeReportsTask @@ -17,12 +16,10 @@ class DiktatGradlePlugin : Plugin { */ override fun apply(project: Project) { val patternSet = PatternSet() - val reporters = mutableListOf() val diktatExtension = project.extensions.create( DIKTAT_EXTENSION, DiktatExtension::class.java, patternSet, - reporters, ).apply { diktatConfigFile = project.rootProject.file("diktat-analysis.yml") } From eb26bacc25413d56f28e0f18c4d8d6bea0215d76 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 15:45:01 +0300 Subject: [PATCH 06/26] gradle cannot create a user specific class --- .../saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 6db8dca18f..56577b7970 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -80,7 +80,7 @@ abstract class DiktatTaskBase( } @get:Internal - abstract val reporters: Reporters + val reporters: Reporters = objectFactory.newInstance(Reporters::class.java) @get:Internal @get:OutputFiles From 039abf1f123d05ccc9bd82ff433c5a033ca7b99a Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 16:09:31 +0300 Subject: [PATCH 07/26] added missed property --- .../diktat/plugin/gradle/DiktatExtension.kt | 5 +++ .../plugin/gradle/extension/Reporters.kt | 7 ++-- .../plugin/gradle/tasks/DiktatTaskBase.kt | 9 ++++-- .../plugin/gradle/DiktatJavaExecTaskTest.kt | 5 ++- ...diktat-convention-configuration.gradle.kts | 32 +++++++++++-------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt index 8ea48e7363..fb269b69f8 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt @@ -34,6 +34,11 @@ open class DiktatExtension @Inject constructor( */ var debug = false + /** + * Property that will be used if you need to publish the report to GitHub + */ + var githubActions = false + /** * Baseline file, containing a list of errors that will be ignored. * If this file doesn't exist, it will be created on the first invocation. diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt index d093b7910b..b6833ee301 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt @@ -58,9 +58,9 @@ open class Reporters @Inject constructor( } /** - * Configure *sarif* reporter for github actions + * Configure *sarif* reporter for GitHub actions */ - fun githubAction() { + fun githubActions() { newReporter() } @@ -97,6 +97,3 @@ open class Reporters @Inject constructor( private inline fun emptyAction() = Action { } } - - - diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 56577b7970..df4f406901 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -44,8 +44,8 @@ import java.nio.file.Path /** * A base task to run `diktat` * - * @property extension * @param inputs + * @property extension */ @Suppress("WRONG_NEWLINES", "Deprecation") abstract class DiktatTaskBase( @@ -91,7 +91,6 @@ abstract class DiktatTaskBase( fileCollection.finalizeValue() } - /** * Whether diktat should be executed */ @@ -203,12 +202,18 @@ abstract class DiktatTaskBase( ): Int companion object { + /** + * @param extension + */ fun TaskProvider.configure(extension: DiktatExtension) { configure { task -> task.configFile.set(task.project.file(extension.diktatConfigFile)) extension.baseline?.let { baseline -> task.baselineFile.set(task.project.file(baseline)) } task.ignoreFailures = extension.ignoreFailures task.reporters.all.addAll(extension.reporters.all) + if (extension.githubActions) { + task.reporters.githubActions() + } } } } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index b35fa04230..8c7fe61855 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -7,7 +7,6 @@ import com.saveourtool.diktat.util.DiktatProcessorListenerWrapper.Companion.unwr import com.pinterest.ktlint.cli.reporter.json.JsonReporter import com.pinterest.ktlint.cli.reporter.plain.PlainReporter import com.pinterest.ktlint.cli.reporter.sarif.SarifReporter -import org.gradle.api.Action import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder @@ -147,7 +146,7 @@ class DiktatJavaExecTaskTest { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") reporters { reportersDsl -> - reportersDsl.githubAction() + reportersDsl.githubActions() } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask @@ -164,7 +163,7 @@ class DiktatJavaExecTaskTest { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") reporters { reportersDsl -> - reportersDsl.githubAction() + reportersDsl.githubActions() reportersDsl.json { jsonDsl -> jsonDsl.output.set(project.layout.buildDirectory.file("report.json")) } diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts index ec9a6892ad..8fc7270631 100644 --- a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts @@ -6,22 +6,26 @@ plugins { diktat { diktatConfigFile = rootProject.file("diktat-analysis.yml") -// githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false + // githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false + reporters { + json() + githubActions() + } -// reporters { -// directory = project.rootProject.layout.buildDirectory.file("reports/diktat") -// json { -// output = "report.json" -// } -// sarif { -// mergeOutput = "" -// } -// custom { -// dependency = "bla.bla:foo.foo:1.2.3" -// output = "report.txt" -// } -// } + // reporters { + // directory = project.rootProject.layout.buildDirectory.file("reports/diktat") + // json { + // output = "report.json" + // } + // sarif { + // mergeOutput = "" + // } + // custom { + // dependency = "bla.bla:foo.foo:1.2.3" + // output = "report.txt" + // } + // } inputs { // using `Project#path` here, because it must be unique in gradle's project hierarchy if (path == rootProject.path) { From 4eea7039636270e72b91bd598bfc1acaaad8d9da Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 16:28:39 +0300 Subject: [PATCH 08/26] a small refactoring --- .../gradle/extension/DefaultReporter.kt | 51 +++++++++++++++---- .../plugin/gradle/extension/Reporter.kt | 1 - .../plugin/gradle/extension/Reporters.kt | 2 +- .../plugin/gradle/tasks/DiktatCheckTask.kt | 7 ++- .../plugin/gradle/tasks/DiktatFixTask.kt | 7 ++- 5 files changed, 52 insertions(+), 16 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 1a0e9e3df2..3989b5fa8b 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -9,38 +9,52 @@ import javax.inject.Inject /** * A base interface for reporter * - * @property id identifier of reporter * @param extension extension of generated report * @param objectFactory * @param project + * @property id identifier of reporter */ abstract class DefaultReporter @Inject constructor( val id: String, extension: String, objectFactory: ObjectFactory, project: Project, -): Reporter() { +) : Reporter() { override val output: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> - fileProperty.set(project.defaultReportLocation(extension = extension)) + fileProperty.convention(project.defaultReportLocation(extension = extension)) } } - abstract class PlainReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, -): DefaultReporter("plain", "txt", objectFactory, project) +) : DefaultReporter( + id = "plain", + extension = "txt", + objectFactory, + project +) abstract class JsonReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, -): DefaultReporter("json", "json", objectFactory, project) +) : DefaultReporter( + id = "json", + extension = "json", + objectFactory, + project +) abstract class SarifReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, -): DefaultReporter("sarif", "sarif", objectFactory, project) { +) : DefaultReporter( + id = "sarif", + extension = "sarif", + objectFactory, + project +) { /** * Location for merged output */ @@ -51,18 +65,35 @@ abstract class GithubActionsReporter @Inject constructor( project: Project, objectFactory: ObjectFactory, ) : SarifReporter(objectFactory, project) { + override val output: RegularFileProperty = objectFactory.fileProperty() + .also { fileProperty -> + fileProperty.convention(project.defaultReportLocation(extension = "sarif")) + .finalizeValue() + } + override val mergeOutput: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> - fileProperty.set(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) + fileProperty.convention(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) + .finalizeValue() } } abstract class CheckstyleReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, -): DefaultReporter("checkstyle", "xml", objectFactory, project) +) : DefaultReporter( + id = "checkstyle", + extension = "xml", + objectFactory, + project +) abstract class HtmlReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, -): DefaultReporter("html", "html", objectFactory, project) +) : DefaultReporter( + id = "html", + extension = "html", + objectFactory, + project +) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt index 91b56c270b..04596e07c6 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt @@ -2,7 +2,6 @@ package com.saveourtool.diktat.plugin.gradle.extension import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.OutputFile -import javax.inject.Inject /** * A base interface for reporter diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt index b6833ee301..32a50534c2 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt @@ -20,7 +20,7 @@ open class Reporters @Inject constructor( * * @param action */ - fun plain(action: Action): Unit = action.execute(newReporter()) + fun plain(action: Action): Unit = action.execute(newReporter()) /** * Configure *plain* reporter with default configuration diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt index 310d20dd55..0bd16a3cc3 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatCheckTask.kt @@ -4,7 +4,6 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin -import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import org.gradle.api.Project import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.TaskProvider @@ -19,7 +18,11 @@ abstract class DiktatCheckTask @Inject constructor( extension: DiktatExtension, inputs: PatternFilterable, objectFactory: ObjectFactory, -) : DiktatTaskBase(extension, inputs, objectFactory) { +) : DiktatTaskBase( + extension, + inputs, + objectFactory +) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt index 032a2b09b2..eeee80a933 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatFixTask.kt @@ -4,7 +4,6 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin -import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import org.gradle.api.Project import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.TaskProvider @@ -19,7 +18,11 @@ abstract class DiktatFixTask @Inject constructor( extension: DiktatExtension, inputs: PatternFilterable, objectFactory: ObjectFactory, -) : DiktatTaskBase(extension, inputs, objectFactory) { +) : DiktatTaskBase( + extension, + inputs, + objectFactory +) { override fun doRun( runner: DiktatRunner, args: DiktatRunnerArguments From 0b6e8d7ada8d010022f5f581dd3f988af75d8af1 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 16:32:14 +0300 Subject: [PATCH 09/26] reverted changes --- ...diktat-convention-configuration.gradle.kts | 21 +--------------- ...iktat-convention-configuration.gradle.kts_ | 25 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts index 8fc7270631..532aba2bf6 100644 --- a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts @@ -6,26 +6,7 @@ plugins { diktat { diktatConfigFile = rootProject.file("diktat-analysis.yml") - // githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false - - reporters { - json() - githubActions() - } - - // reporters { - // directory = project.rootProject.layout.buildDirectory.file("reports/diktat") - // json { - // output = "report.json" - // } - // sarif { - // mergeOutput = "" - // } - // custom { - // dependency = "bla.bla:foo.foo:1.2.3" - // output = "report.txt" - // } - // } + githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false inputs { // using `Project#path` here, because it must be unique in gradle's project hierarchy if (path == rootProject.path) { diff --git a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ b/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ deleted file mode 100644 index 532aba2bf6..0000000000 --- a/gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts_ +++ /dev/null @@ -1,25 +0,0 @@ -package com.saveourtool.diktat.buildutils - -plugins { - id("com.saveourtool.diktat") -} - -diktat { - diktatConfigFile = rootProject.file("diktat-analysis.yml") - githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false - inputs { - // using `Project#path` here, because it must be unique in gradle's project hierarchy - if (path == rootProject.path) { - include("gradle/plugins/src/**/*.kt", "*.kts", "gradle/plugins/**/*.kts") - exclude("gradle/plugins/build/**") - } else { - include("src/**/*.kt", "**/*.kts") - exclude( - "src/test/**/*.kt", - "src/test/**/*.kts", - "src/*Test/**/*.kt", - "build/**/*.kts", - ) - } - } -} From ddeeb298456ca93227b29bf5c78d1f8d8f663bb2 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 16:47:27 +0300 Subject: [PATCH 10/26] diktatFix --- .../diktat/plugin/gradle/DiktatExtension.kt | 4 ++ .../gradle/extension/DefaultReporter.kt | 45 ++++++++++++++++++- .../plugin/gradle/extension/Reporter.kt | 4 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 12 +++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt index fb269b69f8..0828de3819 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatExtension.kt @@ -15,12 +15,16 @@ import javax.inject.Inject /** * An extension to configure diktat in build.gradle(.kts) file * + * @param objectFactory * @param patternSet */ open class DiktatExtension @Inject constructor( objectFactory: ObjectFactory, private val patternSet: PatternSet, ) { + /** + * All reporters + */ @get:Internal val reporters: Reporters = objectFactory.newInstance(Reporters::class.java) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 3989b5fa8b..c8aa0d245c 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -1,3 +1,9 @@ +/** + * All default reporters + */ + +@file:Suppress("UnnecessaryAbstractClass") + package com.saveourtool.diktat.plugin.gradle.extension import com.saveourtool.diktat.plugin.gradle.defaultReportLocation @@ -19,13 +25,19 @@ abstract class DefaultReporter @Inject constructor( extension: String, objectFactory: ObjectFactory, project: Project, -) : Reporter() { +) : Reporter { override val output: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> fileProperty.convention(project.defaultReportLocation(extension = extension)) } } +/** + * Plain reporter + * + * @param objectFactory + * @param project + */ abstract class PlainReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, @@ -36,6 +48,12 @@ abstract class PlainReporter @Inject constructor( project ) +/** + * JSON reporter + * + * @param objectFactory + * @param project + */ abstract class JsonReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, @@ -46,6 +64,12 @@ abstract class JsonReporter @Inject constructor( project ) +/** + * SARIF reporter + * + * @param objectFactory + * @param project + */ abstract class SarifReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, @@ -61,6 +85,12 @@ abstract class SarifReporter @Inject constructor( abstract val mergeOutput: RegularFileProperty } +/** + * GitHub actions reporter + * + * @param objectFactory + * @param project + */ abstract class GithubActionsReporter @Inject constructor( project: Project, objectFactory: ObjectFactory, @@ -70,7 +100,6 @@ abstract class GithubActionsReporter @Inject constructor( fileProperty.convention(project.defaultReportLocation(extension = "sarif")) .finalizeValue() } - override val mergeOutput: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> fileProperty.convention(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) @@ -78,6 +107,12 @@ abstract class GithubActionsReporter @Inject constructor( } } +/** + * Checkstyle reporter + * + * @param objectFactory + * @param project + */ abstract class CheckstyleReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, @@ -88,6 +123,12 @@ abstract class CheckstyleReporter @Inject constructor( project ) +/** + * HTML reporter + * + * @param objectFactory + * @param project + */ abstract class HtmlReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt index 04596e07c6..2ccb3c0060 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporter.kt @@ -6,10 +6,10 @@ import org.gradle.api.tasks.OutputFile /** * A base interface for reporter */ -abstract class Reporter { +interface Reporter { /** * Location for output */ @get:OutputFile - abstract val output: RegularFileProperty + val output: RegularFileProperty } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index df4f406901..0a60d959cc 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -53,9 +53,15 @@ abstract class DiktatTaskBase( private val inputs: PatternFilterable, objectFactory: ObjectFactory, ) : DefaultTask(), VerificationTask { + /** + * Config file + */ @get:InputFile abstract val configFile: RegularFileProperty + /** + * Baseline + */ @get:Optional @get:InputFile abstract val baselineFile: RegularFileProperty @@ -79,9 +85,15 @@ abstract class DiktatTaskBase( ) } + /** + * All reporters + */ @get:Internal val reporters: Reporters = objectFactory.newInstance(Reporters::class.java) + /** + * Outputs for all reporters + */ @get:Internal @get:OutputFiles @get:Optional From 600367b2b38f14047baf704895474c96090c2e04 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 17:52:10 +0300 Subject: [PATCH 11/26] renamed GitHub actions reporter --- .../gradle/extension/DefaultReporter.kt | 2 +- .../plugin/gradle/extension/Reporters.kt | 4 +-- .../plugin/gradle/tasks/DiktatTaskBase.kt | 2 +- .../gradle/tasks/SarifReportMergeTask.kt | 34 ++++++++----------- .../plugin/gradle/DiktatJavaExecTaskTest.kt | 4 +-- .../plugin/gradle/ReporterSelectionTest.kt | 30 ---------------- 6 files changed, 21 insertions(+), 55 deletions(-) delete mode 100644 diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index c8aa0d245c..6da0cd3f1c 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -91,7 +91,7 @@ abstract class SarifReporter @Inject constructor( * @param objectFactory * @param project */ -abstract class GithubActionsReporter @Inject constructor( +abstract class GitHubActionsReporter @Inject constructor( project: Project, objectFactory: ObjectFactory, ) : SarifReporter(objectFactory, project) { diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt index 32a50534c2..8dec50d6c1 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/Reporters.kt @@ -60,8 +60,8 @@ open class Reporters @Inject constructor( /** * Configure *sarif* reporter for GitHub actions */ - fun githubActions() { - newReporter() + fun gitHubActions() { + newReporter() } /** diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 0a60d959cc..0f6ffa344d 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -224,7 +224,7 @@ abstract class DiktatTaskBase( task.ignoreFailures = extension.ignoreFailures task.reporters.all.addAll(extension.reporters.all) if (extension.githubActions) { - task.reporters.githubActions() + task.reporters.gitHubActions() } } } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index b584f524e2..7b450ab718 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -2,7 +2,7 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME -import com.saveourtool.diktat.plugin.gradle.extension.SarifReporter +import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask @@ -82,24 +82,20 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { internal fun Project.configureMergeReportsTask( diktatExtension: DiktatExtension, ) { - if (path == rootProject.path) { - tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - diktatExtension.reporters.all - .filterIsInstance() - .map { reporter -> reporter.mergeOutput.zip(reporter.output, ::Pair) } - .forEach { pair -> - reportMergeTask.inputs.file(pair.map { it.first }) - reportMergeTask.inputs.file(pair.map { it.second }) + diktatExtension.reporters.all.filterIsInstance() + .firstOrNull() + ?.let { gitHubActionsReporter -> + if (path == rootProject.path) { + tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> + reportMergeTask.output.set(gitHubActionsReporter.mergeOutput) } - val mergedReportFile = project.layout.buildDirectory.file("reports/diktat/diktat-merged.sarif") - reportMergeTask.outputs.file(mergedReportFile) - reportMergeTask.output.set(mergedReportFile) + } + rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> + reportMergeTask.input.from(gitHubActionsReporter.output) + reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) + } + tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> + diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) + } } - } - rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> - reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) - } - tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> - diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) - } } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index 8c7fe61855..aab6aca163 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -146,7 +146,7 @@ class DiktatJavaExecTaskTest { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") reporters { reportersDsl -> - reportersDsl.githubActions() + reportersDsl.gitHubActions() } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask @@ -163,7 +163,7 @@ class DiktatJavaExecTaskTest { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") reporters { reportersDsl -> - reportersDsl.githubActions() + reportersDsl.gitHubActions() reportersDsl.json { jsonDsl -> jsonDsl.output.set(project.layout.buildDirectory.file("report.json")) } diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt deleted file mode 100644 index c9c2e0d48a..0000000000 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/ReporterSelectionTest.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.saveourtool.diktat.plugin.gradle - -import org.gradle.api.Project -import org.gradle.api.tasks.util.PatternSet -import org.gradle.testfixtures.ProjectBuilder -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.fail - -class ReporterSelectionTest { - private val projectBuilder = ProjectBuilder.builder() - private lateinit var project: Project - - @BeforeEach - fun setUp() { - project = projectBuilder.build() - // mock kotlin sources - project.mkdir("src/main/kotlin") - project.file("src/main/kotlin/Test.kt").createNewFile() - project.pluginManager.apply(DiktatGradlePlugin::class.java) - } - - @Test - @Disabled("FIXME") - fun `should fallback to plain reporter for unknown reporter types`() { - fail("need to test default behaviour") - } -} From 7f20855225ee69b720a8ec357504e2400bba5b04 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 18:41:12 +0300 Subject: [PATCH 12/26] moved detecting github actions --- .../gradle/tasks/SarifReportMergeTask.kt | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 7b450ab718..0e9975350b 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -82,20 +82,26 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { internal fun Project.configureMergeReportsTask( diktatExtension: DiktatExtension, ) { - diktatExtension.reporters.all.filterIsInstance() - .firstOrNull() - ?.let { gitHubActionsReporter -> - if (path == rootProject.path) { - tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> + if (path == rootProject.path) { + tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> + diktatExtension.reporters.all + .filterIsInstance() + .firstOrNull() + ?.let { gitHubActionsReporter -> reportMergeTask.output.set(gitHubActionsReporter.mergeOutput) } - } - rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> + } + } + rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> + diktatExtension.reporters.all + .filterIsInstance() + .firstOrNull() + ?.let { gitHubActionsReporter -> reportMergeTask.input.from(gitHubActionsReporter.output) - reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) - } - tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> - diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) } - } + reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) + } + tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> + diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) + } } From cd1a88378f9caacc011106ee4003ba7b713d8129 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 18:49:14 +0300 Subject: [PATCH 13/26] removed Internal --- .../com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 0f6ffa344d..437b2c7c04 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -94,7 +94,6 @@ abstract class DiktatTaskBase( /** * Outputs for all reporters */ - @get:Internal @get:OutputFiles @get:Optional val reporterOutputs: ConfigurableFileCollection = objectFactory.fileCollection() From 34fb7ee202237159c97c6863166dfe3643f535f6 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 18:59:03 +0300 Subject: [PATCH 14/26] make output as optional --- .../diktat/plugin/gradle/tasks/SarifReportMergeTask.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 0e9975350b..af0c7336b7 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -10,6 +10,7 @@ import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.InputFiles +import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.PathSensitivity @@ -36,6 +37,7 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { * Destination for the merged report */ @get:OutputFile + @get:Optional abstract val output: RegularFileProperty /** From 4e96f13eb2c1d63d7111d888bb3b6a45cff7cd71 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 23:22:07 +0300 Subject: [PATCH 15/26] refactored merge task and removed test --- .../gradle/extension/DefaultReporter.kt | 12 ++++---- .../gradle/tasks/SarifReportMergeTask.kt | 28 +++++++++++-------- .../plugin/gradle/DiktatGradlePluginTest.kt | 11 -------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 6da0cd3f1c..f9ef272fe6 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -78,12 +78,7 @@ abstract class SarifReporter @Inject constructor( extension = "sarif", objectFactory, project -) { - /** - * Location for merged output - */ - abstract val mergeOutput: RegularFileProperty -} +) /** * GitHub actions reporter @@ -100,7 +95,10 @@ abstract class GitHubActionsReporter @Inject constructor( fileProperty.convention(project.defaultReportLocation(extension = "sarif")) .finalizeValue() } - override val mergeOutput: RegularFileProperty = objectFactory.fileProperty() + /** + * Location for merged output + */ + val mergeOutput: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> fileProperty.convention(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) .finalizeValue() diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index af0c7336b7..50b1e47618 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -1,11 +1,14 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatExtension +import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_CHECK_TASK import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter +import com.saveourtool.diktat.plugin.gradle.extension.Reporters import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty @@ -86,24 +89,25 @@ internal fun Project.configureMergeReportsTask( ) { if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - diktatExtension.reporters.all - .filterIsInstance() + diktatExtension.reporters + .getGitHubActionsReporters() .firstOrNull() ?.let { gitHubActionsReporter -> reportMergeTask.output.set(gitHubActionsReporter.mergeOutput) } } } - rootProject.tasks.withType(SarifReportMergeTask::class.java).configureEach { reportMergeTask -> - diktatExtension.reporters.all - .filterIsInstance() - .firstOrNull() - ?.let { gitHubActionsReporter -> - reportMergeTask.input.from(gitHubActionsReporter.output) - } - reportMergeTask.dependsOn(tasks.withType(DiktatTaskBase::class.java)) + + val rootMergeSarifReportsTask = rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) + val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) + + rootMergeSarifReportsTask.configure { reportMergeTask -> + reportMergeTask.input.from(diktatCheckTask.map { task -> task.reporters.getGitHubActionsReporters().map { it.output } }) + reportMergeTask.dependsOn(diktatCheckTask) } - tasks.withType(DiktatTaskBase::class.java).configureEach { diktatTaskBase -> - diktatTaskBase.finalizedBy(rootProject.tasks.withType(SarifReportMergeTask::class.java)) + diktatCheckTask.configure { + it.finalizedBy(rootMergeSarifReportsTask) } } + +private fun Reporters.getGitHubActionsReporters() = all.filterIsInstance() diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt index f37d58583d..1d51c6bb78 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt @@ -39,15 +39,4 @@ class DiktatGradlePluginTest { Assertions.assertIterableEquals(project.fileTree("src").files, actualInputs.files) Assertions.assertTrue(actualInputs.files.isNotEmpty()) } - - @Test - @Disabled - fun `check default reporter type value`() { - fail("need to fix") -// val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension -// Assertions.assertEquals("", diktatExtension.reporter) -// -// val reporterFlag = project.getReporterType(diktatExtension) -// Assertions.assertEquals("plain", reporterFlag) - } } From bc6c5b770eca453f0cea92cb18ecf0239b97818f Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Mon, 20 Nov 2023 23:51:40 +0300 Subject: [PATCH 16/26] diktatFix --- .../plugin/gradle/extension/DefaultReporter.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index f9ef272fe6..171ea57e78 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -45,8 +45,13 @@ abstract class PlainReporter @Inject constructor( id = "plain", extension = "txt", objectFactory, - project -) + project, +) { + /** + * Remove the default value for plain to print to stdout by default + */ + abstract override val output: RegularFileProperty +} /** * JSON reporter @@ -77,7 +82,7 @@ abstract class SarifReporter @Inject constructor( id = "sarif", extension = "sarif", objectFactory, - project + project, ) /** @@ -95,6 +100,7 @@ abstract class GitHubActionsReporter @Inject constructor( fileProperty.convention(project.defaultReportLocation(extension = "sarif")) .finalizeValue() } + /** * Location for merged output */ @@ -118,7 +124,7 @@ abstract class CheckstyleReporter @Inject constructor( id = "checkstyle", extension = "xml", objectFactory, - project + project, ) /** @@ -134,5 +140,5 @@ abstract class HtmlReporter @Inject constructor( id = "html", extension = "html", objectFactory, - project + project, ) From 4e93d6972ae144bf44bf346b8b767b2e575b36b5 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 00:01:25 +0300 Subject: [PATCH 17/26] fix Plain --- .../diktat/plugin/gradle/extension/DefaultReporter.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 171ea57e78..fe930eb2d2 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -10,6 +10,7 @@ import com.saveourtool.diktat.plugin.gradle.defaultReportLocation import org.gradle.api.Project import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory +import java.io.File import javax.inject.Inject /** @@ -50,7 +51,10 @@ abstract class PlainReporter @Inject constructor( /** * Remove the default value for plain to print to stdout by default */ - abstract override val output: RegularFileProperty + override val output: RegularFileProperty = objectFactory.fileProperty() + .also { fileProperty -> + fileProperty.set(null as File?) + } } /** @@ -66,7 +70,7 @@ abstract class JsonReporter @Inject constructor( id = "json", extension = "json", objectFactory, - project + project, ) /** From 173e8d10865065b3a5a4513209e96cc5777bf135 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 00:06:49 +0300 Subject: [PATCH 18/26] removed unused import --- .../diktat/plugin/gradle/tasks/SarifReportMergeTask.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 50b1e47618..8130fd5b7d 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -8,7 +8,6 @@ import com.saveourtool.diktat.plugin.gradle.extension.Reporters import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask -import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty From 76290cf44558e68f7ca22cb1fc5433bce9b201cc Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 00:28:55 +0300 Subject: [PATCH 19/26] fixed merge task --- .../plugin/gradle/DiktatGradlePlugin.kt | 2 +- .../gradle/tasks/SarifReportMergeTask.kt | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index 5dce0c250f..e8f241d677 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -26,7 +26,7 @@ class DiktatGradlePlugin : Plugin { project.registerDiktatCheckTask(diktatExtension, patternSet) project.registerDiktatFixTask(diktatExtension, patternSet) - project.configureMergeReportsTask(diktatExtension) + project.configureMergeReportsTask(project.providers) } companion object { diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index 8130fd5b7d..ba83101593 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -4,13 +4,14 @@ import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_CHECK_TASK import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter -import com.saveourtool.diktat.plugin.gradle.extension.Reporters import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Provider +import org.gradle.api.provider.ProviderFactory import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputFile @@ -18,7 +19,9 @@ 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.TaskProvider import org.gradle.api.tasks.VerificationTask +import java.util.concurrent.Callable import kotlinx.serialization.SerializationException import kotlinx.serialization.encodeToString @@ -81,27 +84,22 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { } /** - * @param diktatExtension extension of type [DiktatExtension] + * @param providerFactory */ internal fun Project.configureMergeReportsTask( - diktatExtension: DiktatExtension, + providerFactory: ProviderFactory, ) { - if (path == rootProject.path) { + val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) + val rootMergeSarifReportsTask = if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - diktatExtension.reporters - .getGitHubActionsReporters() - .firstOrNull() - ?.let { gitHubActionsReporter -> - reportMergeTask.output.set(gitHubActionsReporter.mergeOutput) - } + reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter(providerFactory).flatMap { it.mergeOutput }) } + } else { + rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) } - val rootMergeSarifReportsTask = rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) - val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) - rootMergeSarifReportsTask.configure { reportMergeTask -> - reportMergeTask.input.from(diktatCheckTask.map { task -> task.reporters.getGitHubActionsReporters().map { it.output } }) + reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter(providerFactory).flatMap { it.output }) reportMergeTask.dependsOn(diktatCheckTask) } diktatCheckTask.configure { @@ -109,4 +107,10 @@ internal fun Project.configureMergeReportsTask( } } -private fun Reporters.getGitHubActionsReporters() = all.filterIsInstance() +private fun TaskProvider.getGitHubActionsReporter( + providerFactory: ProviderFactory, +): Provider = flatMap { task -> + providerFactory.provider(Callable { + task.reporters.all.filterIsInstance().firstOrNull() + }) +} From cf135b1b85ad220ea8939b2c4f3717e12caad759 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 00:33:40 +0300 Subject: [PATCH 20/26] output is optional --- .../diktat/plugin/gradle/tasks/SarifReportMergeTask.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index ba83101593..f5744ee22f 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -50,6 +50,10 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { */ @TaskAction fun mergeReports() { + if (!output.isPresent) { + logger.debug("Skipping merging SARIF reports because output is not set") + return + } val sarifReports = input.files .filter { it.exists() } .also { logger.info("Merging SARIF reports from files $it") } From 03921eab1859dfe7e1bbdb2301e3bd046295d5c8 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 01:14:41 +0300 Subject: [PATCH 21/26] one more try to fix merge task --- .../gradle/tasks/SarifReportMergeTask.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index f5744ee22f..afef52cfde 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -1,6 +1,5 @@ package com.saveourtool.diktat.plugin.gradle.tasks -import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_CHECK_TASK import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter @@ -9,6 +8,7 @@ import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Provider import org.gradle.api.provider.ProviderFactory @@ -21,7 +21,6 @@ import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskExecutionException import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.VerificationTask -import java.util.concurrent.Callable import kotlinx.serialization.SerializationException import kotlinx.serialization.encodeToString @@ -36,6 +35,7 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { */ @get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE) + @get:Optional abstract val input: ConfigurableFileCollection /** @@ -96,14 +96,14 @@ internal fun Project.configureMergeReportsTask( val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) val rootMergeSarifReportsTask = if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter(providerFactory).flatMap { it.mergeOutput }) + reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter(providerFactory) { it.mergeOutput }) } } else { rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) } rootMergeSarifReportsTask.configure { reportMergeTask -> - reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter(providerFactory).flatMap { it.output }) + reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter(providerFactory) { it.output }) reportMergeTask.dependsOn(diktatCheckTask) } diktatCheckTask.configure { @@ -113,8 +113,11 @@ internal fun Project.configureMergeReportsTask( private fun TaskProvider.getGitHubActionsReporter( providerFactory: ProviderFactory, -): Provider = flatMap { task -> - providerFactory.provider(Callable { - task.reporters.all.filterIsInstance().firstOrNull() - }) + getter: (GitHubActionsReporter) -> RegularFileProperty, +): Provider = providerFactory.provider { + map { it.reporters.all.filterIsInstance() } + .orNull + ?.firstOrNull() + ?.let(getter) + ?.orNull } From 49b13d54f8a98ee9c888481b149354c4f72b47c0 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 01:43:19 +0300 Subject: [PATCH 22/26] a next try to fix --- .../plugin/gradle/DiktatGradlePlugin.kt | 2 +- .../gradle/tasks/SarifReportMergeTask.kt | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt index e8f241d677..f76a0103c8 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePlugin.kt @@ -26,7 +26,7 @@ class DiktatGradlePlugin : Plugin { project.registerDiktatCheckTask(diktatExtension, patternSet) project.registerDiktatFixTask(diktatExtension, patternSet) - project.configureMergeReportsTask(project.providers) + project.configureMergeReportsTask() } companion object { diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index afef52cfde..d86a2efb6a 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -88,22 +88,20 @@ abstract class SarifReportMergeTask : DefaultTask(), VerificationTask { } /** - * @param providerFactory + * Configure [MERGE_SARIF_REPORTS_TASK_NAME] */ -internal fun Project.configureMergeReportsTask( - providerFactory: ProviderFactory, -) { +internal fun Project.configureMergeReportsTask() { val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) val rootMergeSarifReportsTask = if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter(providerFactory) { it.mergeOutput }) + reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter { it.mergeOutput }) } } else { rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) } rootMergeSarifReportsTask.configure { reportMergeTask -> - reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter(providerFactory) { it.output }) + reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter { it.output }.asProvider(providers)) reportMergeTask.dependsOn(diktatCheckTask) } diktatCheckTask.configure { @@ -112,12 +110,13 @@ internal fun Project.configureMergeReportsTask( } private fun TaskProvider.getGitHubActionsReporter( - providerFactory: ProviderFactory, getter: (GitHubActionsReporter) -> RegularFileProperty, -): Provider = providerFactory.provider { - map { it.reporters.all.filterIsInstance() } - .orNull - ?.firstOrNull() - ?.let(getter) - ?.orNull -} +): RegularFile? = map { it.reporters.all.filterIsInstance() } + .orNull + ?.singleOrNull() + ?.let(getter) + ?.orNull + +private fun T?.asProvider( + providerFactory: ProviderFactory, +): Provider = providerFactory.provider { this } From 4f3f3b82094db98ccbebd05bd4bbd3db5bf79aa0 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 01:54:35 +0300 Subject: [PATCH 23/26] hardcoded value for sarif report merge --- .../gradle/extension/DefaultReporter.kt | 19 +++++++++++++-- .../gradle/tasks/SarifReportMergeTask.kt | 23 ++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index fe930eb2d2..39db6c6adf 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -8,8 +8,10 @@ package com.saveourtool.diktat.plugin.gradle.extension import com.saveourtool.diktat.plugin.gradle.defaultReportLocation import org.gradle.api.Project +import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Provider import java.io.File import javax.inject.Inject @@ -101,7 +103,7 @@ abstract class GitHubActionsReporter @Inject constructor( ) : SarifReporter(objectFactory, project) { override val output: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> - fileProperty.convention(project.defaultReportLocation(extension = "sarif")) + fileProperty.convention(project.getGitHubActionReporterOutput()) .finalizeValue() } @@ -110,9 +112,22 @@ abstract class GitHubActionsReporter @Inject constructor( */ val mergeOutput: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> - fileProperty.convention(project.rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif")) + fileProperty.convention(project.getGitHubActionReporterMergeOutput()) .finalizeValue() } + + companion object { + /** + * @return [RegularFile] for output + */ + fun Project.getGitHubActionReporterOutput(): Provider = defaultReportLocation(extension = "sarif") + + /** + * @return [RegularFile] for mergeOutput + */ + fun Project.getGitHubActionReporterMergeOutput(): Provider = + rootProject.defaultReportLocation(fileName = "diktat-merged", extension = "sarif") + } } /** diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt index d86a2efb6a..972665d383 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/SarifReportMergeTask.kt @@ -2,16 +2,14 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_CHECK_TASK import com.saveourtool.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MERGE_SARIF_REPORTS_TASK_NAME -import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter +import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter.Companion.getGitHubActionReporterMergeOutput +import com.saveourtool.diktat.plugin.gradle.extension.GitHubActionsReporter.Companion.getGitHubActionReporterOutput import io.github.detekt.sarif4k.SarifSchema210 import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Provider -import org.gradle.api.provider.ProviderFactory import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputFile @@ -19,7 +17,6 @@ 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.TaskProvider import org.gradle.api.tasks.VerificationTask import kotlinx.serialization.SerializationException @@ -94,29 +91,17 @@ internal fun Project.configureMergeReportsTask() { val diktatCheckTask = tasks.named(DIKTAT_CHECK_TASK, DiktatCheckTask::class.java) val rootMergeSarifReportsTask = if (path == rootProject.path) { tasks.register(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) { reportMergeTask -> - reportMergeTask.output.set(diktatCheckTask.getGitHubActionsReporter { it.mergeOutput }) + reportMergeTask.output.set(getGitHubActionReporterMergeOutput()) } } else { rootProject.tasks.named(MERGE_SARIF_REPORTS_TASK_NAME, SarifReportMergeTask::class.java) } rootMergeSarifReportsTask.configure { reportMergeTask -> - reportMergeTask.input.from(diktatCheckTask.getGitHubActionsReporter { it.output }.asProvider(providers)) + reportMergeTask.input.from(getGitHubActionReporterOutput()) reportMergeTask.dependsOn(diktatCheckTask) } diktatCheckTask.configure { it.finalizedBy(rootMergeSarifReportsTask) } } - -private fun TaskProvider.getGitHubActionsReporter( - getter: (GitHubActionsReporter) -> RegularFileProperty, -): RegularFile? = map { it.reporters.all.filterIsInstance() } - .orNull - ?.singleOrNull() - ?.let(getter) - ?.orNull - -private fun T?.asProvider( - providerFactory: ProviderFactory, -): Provider = providerFactory.provider { this } From 358f2f5fa384a90b4e2e6ab381520cd46a6330e9 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 11:49:11 +0300 Subject: [PATCH 24/26] updated tests --- .../plugin/gradle/DiktatJavaExecTaskTest.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index aab6aca163..22b2d95f90 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -145,9 +145,7 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") - reporters { reportersDsl -> - reportersDsl.gitHubActions() - } + githubActions = true } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask assert(task.diktatRunner.diktatReporter.unwrapFirst() is SarifReporter) @@ -162,15 +160,24 @@ class DiktatJavaExecTaskTest { assertFiles(emptyList()) { inputs { exclude("*") } diktatConfigFile = project.file("../diktat-analysis.yml") + githubActions = true reporters { reportersDsl -> - reportersDsl.gitHubActions() reportersDsl.json { jsonDsl -> jsonDsl.output.set(project.layout.buildDirectory.file("report.json")) } } } val task = project.tasks.getByName(DIKTAT_CHECK_TASK) as DiktatCheckTask - assert(task.diktatRunner.diktatReporter.unwrapFirst() is SarifReporter) + val (first, second) = task.diktatRunner.diktatReporter + .unwrap>() + .first() + .unwrap() + .unwrap>() + .toList() + + assert(first.unwrapToKtlint() is JsonReporter) + assert(second.unwrapToKtlint() is SarifReporter) + Assertions.assertEquals( project.rootDir.toString(), System.getProperty("user.home") From bb7d0a22290eae7d119081a3b50f75e11f4d5e5c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 12:34:54 +0300 Subject: [PATCH 25/26] added DiktatReporterType --- .../api/DiktatReporterCreationArguments.kt | 24 +++++++++---------- .../diktat/api/DiktatReporterFactory.kt | 17 ------------- .../diktat/api/DiktatReporterType.kt | 17 +++++++++++++ .../diktat/cli/DiktatProperties.kt | 23 +++++++----------- .../gradle/extension/DefaultReporter.kt | 23 +++++++----------- .../plugin/gradle/tasks/DiktatTaskBase.kt | 5 ++-- .../ktlint/DiktatReporterFactoryImpl.kt | 22 ++++++++--------- .../diktat/plugin/maven/DiktatBaseMojo.kt | 19 ++++++++------- 8 files changed, 70 insertions(+), 80 deletions(-) create mode 100644 diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterType.kt diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterCreationArguments.kt b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterCreationArguments.kt index 1ac5424ddc..3d4edbc280 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterCreationArguments.kt +++ b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterCreationArguments.kt @@ -12,9 +12,9 @@ import java.nio.file.Path */ sealed interface DiktatReporterCreationArguments { /** - * Identifier of [DiktatReporter] which needs to be created + * Type of [DiktatReporter] which needs to be created */ - val id: String + val reporterType: DiktatReporterType /** * Output for [DiktatReporter] @@ -33,23 +33,23 @@ sealed interface DiktatReporterCreationArguments { companion object { /** - * @param id ID of [DiktatReporter] + * @param reporterType type of [DiktatReporter] * @param outputStream stdout will be used when it's empty * @param sourceRootDir a dir to detect relative path for processing files - * @param colorNameInPlain a color name for colorful output which is applicable for plain ([DiktatReporterFactory.PLAIN_ID]) reporter only, + * @param colorNameInPlain a color name for colorful output which is applicable for plain ([DiktatReporterType.PLAIN]) reporter only, * `null` means to disable colorization. - * @param groupByFileInPlain a flag `groupByFile` which is applicable for plain ([DiktatReporterFactory.PLAIN_ID]) reporter only. + * @param groupByFileInPlain a flag `groupByFile` which is applicable for plain ([DiktatReporterType.PLAIN]) reporter only. * @return created [DiktatReporter] */ operator fun invoke( - id: String, + reporterType: DiktatReporterType, outputStream: OutputStream?, sourceRootDir: Path?, colorNameInPlain: String? = null, groupByFileInPlain: Boolean? = null, ): DiktatReporterCreationArguments { val (outputStreamOrStdout, closeOutputStreamAfterAll) = outputStream?.let { it to true } ?: (System.`out` to false) - return if (id == DiktatReporterFactory.PLAIN_ID) { + return if (reporterType == DiktatReporterType.PLAIN) { PlainDiktatReporterCreationArguments( outputStreamOrStdout, closeOutputStreamAfterAll, sourceRootDir, colorNameInPlain, groupByFileInPlain ) @@ -61,7 +61,7 @@ sealed interface DiktatReporterCreationArguments { "groupByFile is applicable only for plain reporter" } DiktatReporterCreationArgumentsImpl( - id, outputStreamOrStdout, closeOutputStreamAfterAll, sourceRootDir + reporterType, outputStreamOrStdout, closeOutputStreamAfterAll, sourceRootDir ) } } @@ -69,7 +69,7 @@ sealed interface DiktatReporterCreationArguments { } /** - * Implementation of [DiktatReporterCreationArguments] for [DiktatReporterFactory.PLAIN_ID] + * Implementation of [DiktatReporterCreationArguments] for [DiktatReporterType.PLAIN] * * @property outputStream * @property closeOutputStreamAfterAll @@ -84,17 +84,17 @@ data class PlainDiktatReporterCreationArguments( val colorName: String? = null, val groupByFile: Boolean? = null, ) : DiktatReporterCreationArguments { - override val id: String = DiktatReporterFactory.PLAIN_ID + override val reporterType: DiktatReporterType = DiktatReporterType.PLAIN } /** - * @property id + * @property reporterType * @property outputStream * @property closeOutputStreamAfterAll * @property sourceRootDir */ private data class DiktatReporterCreationArgumentsImpl( - override val id: String, + override val reporterType: DiktatReporterType, override val outputStream: OutputStream, override val closeOutputStreamAfterAll: Boolean, override val sourceRootDir: Path?, diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterFactory.kt b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterFactory.kt index a9c27aa959..5384c15f87 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterFactory.kt +++ b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterFactory.kt @@ -6,11 +6,6 @@ typealias DiktatReporter = DiktatProcessorListener * A factory to create [DiktatReporter] */ interface DiktatReporterFactory : Function1 { - /** - * Set of supported IDs, must contain [DiktatReporterFactory.NONE_ID] - */ - val ids: Set - /** * Names of color for plain output */ @@ -23,16 +18,4 @@ interface DiktatReporterFactory : Function1(), fullName = "reporter", shortName = "r", description = "The reporter to use" ) - .default(PLAIN_ID) + .default(DiktatReporterType.PLAIN) /** * @param diktatReporterFactory diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 39db6c6adf..95351a43e5 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -6,6 +6,7 @@ package com.saveourtool.diktat.plugin.gradle.extension +import com.saveourtool.diktat.api.DiktatReporterType import com.saveourtool.diktat.plugin.gradle.defaultReportLocation import org.gradle.api.Project import org.gradle.api.file.RegularFile @@ -21,17 +22,16 @@ import javax.inject.Inject * @param extension extension of generated report * @param objectFactory * @param project - * @property id identifier of reporter + * @property type type of reporter */ abstract class DefaultReporter @Inject constructor( - val id: String, - extension: String, + val type: DiktatReporterType, objectFactory: ObjectFactory, project: Project, ) : Reporter { override val output: RegularFileProperty = objectFactory.fileProperty() .also { fileProperty -> - fileProperty.convention(project.defaultReportLocation(extension = extension)) + fileProperty.convention(project.defaultReportLocation(extension = type.extension)) } } @@ -45,8 +45,7 @@ abstract class PlainReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, ) : DefaultReporter( - id = "plain", - extension = "txt", + type = DiktatReporterType.PLAIN, objectFactory, project, ) { @@ -69,8 +68,7 @@ abstract class JsonReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, ) : DefaultReporter( - id = "json", - extension = "json", + type = DiktatReporterType.JSON, objectFactory, project, ) @@ -85,8 +83,7 @@ abstract class SarifReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, ) : DefaultReporter( - id = "sarif", - extension = "sarif", + type = DiktatReporterType.SARIF, objectFactory, project, ) @@ -140,8 +137,7 @@ abstract class CheckstyleReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, ) : DefaultReporter( - id = "checkstyle", - extension = "xml", + type = DiktatReporterType.CHECKSTYLE, objectFactory, project, ) @@ -156,8 +152,7 @@ abstract class HtmlReporter @Inject constructor( objectFactory: ObjectFactory, project: Project, ) : DefaultReporter( - id = "html", - extension = "html", + type = DiktatReporterType.HTML, objectFactory, project, ) diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt index 437b2c7c04..21e8553e2b 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt @@ -5,6 +5,7 @@ import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.DiktatRunnerFactory import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments +import com.saveourtool.diktat.api.DiktatReporterType import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl @@ -132,9 +133,9 @@ abstract class DiktatTaskBase( .filterIsInstance() .map { reporter -> DiktatReporterCreationArguments( - id = reporter.id, + reporterType = reporter.type, outputStream = reporter.output.map { file -> file.asFile.also { Files.createDirectories(it.parentFile.toPath()) }.outputStream() }.orNull, - sourceRootDir = sourceRootDir.takeIf { reporter.id == "sarif" }, + sourceRootDir = sourceRootDir.takeIf { reporter.type == DiktatReporterType.SARIF }, ) } val loggingListener = object : DiktatProcessorListener { diff --git a/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/DiktatReporterFactoryImpl.kt b/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/DiktatReporterFactoryImpl.kt index 1e961caae9..16d2b9a9c2 100644 --- a/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/DiktatReporterFactoryImpl.kt +++ b/diktat-ktlint-engine/src/main/kotlin/com/saveourtool/diktat/ktlint/DiktatReporterFactoryImpl.kt @@ -3,6 +3,7 @@ package com.saveourtool.diktat.ktlint import com.saveourtool.diktat.api.DiktatReporter import com.saveourtool.diktat.api.DiktatReporterCreationArguments import com.saveourtool.diktat.api.DiktatReporterFactory +import com.saveourtool.diktat.api.DiktatReporterType import com.saveourtool.diktat.api.PlainDiktatReporterCreationArguments import com.saveourtool.diktat.ktlint.DiktatReporterImpl.Companion.wrap import com.pinterest.ktlint.cli.reporter.checkstyle.CheckStyleReporterProvider @@ -22,16 +23,13 @@ class DiktatReporterFactoryImpl : DiktatReporterFactory { /** * All reporters which __KtLint__ provides */ - private val reporterProviders = setOf( - JsonReporterProvider(), - SarifReporterProvider(), - CheckStyleReporterProvider(), - HtmlReporterProvider(), + private val reporterProviders = mapOf( + DiktatReporterType.JSON to JsonReporterProvider(), + DiktatReporterType.SARIF to SarifReporterProvider(), + DiktatReporterType.CHECKSTYLE to CheckStyleReporterProvider(), + DiktatReporterType.HTML to HtmlReporterProvider(), + DiktatReporterType.PLAIN to plainReporterProvider, ) - .associateBy { it.id } + (DiktatReporterFactory.PLAIN_ID to plainReporterProvider) - - override val ids: Set - get() = reporterProviders.keys override val colorNamesInPlain: Set get() = Color.entries.map { it.name }.toSet() @@ -39,7 +37,7 @@ class DiktatReporterFactoryImpl : DiktatReporterFactory { override fun invoke( args: DiktatReporterCreationArguments, ): DiktatReporter { - if (args.id == DiktatReporterFactory.NONE_ID) { + if (args.reporterType == DiktatReporterType.NONE) { return DiktatReporter.empty } val opts = if (args is PlainDiktatReporterCreationArguments) { @@ -53,13 +51,13 @@ class DiktatReporterFactoryImpl : DiktatReporterFactory { } args.groupByFile?.let { put("group_by_file", it) } }.mapValues { it.value.toString() } - } else if (args.id == DiktatReporterFactory.PLAIN_ID) { + } else if (args.reporterType == DiktatReporterType.PLAIN) { mapOf("color_name" to Color.DARK_GRAY.name) } else { emptyMap() } - val reporterProvider = reporterProviders[args.id] ?: throw IllegalArgumentException("Not supported reporter id by ${DiktatBaselineFactoryImpl::class.simpleName}") + val reporterProvider = reporterProviders[args.reporterType] ?: throw IllegalArgumentException("Not supported reporter id by ${DiktatBaselineFactoryImpl::class.simpleName}") if (reporterProvider is SarifReporterProvider) { args.sourceRootDir?.let { System.setProperty("user.home", it.pathString) } } diff --git a/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt b/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt index d29f7d954f..f0475f5f7d 100644 --- a/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt @@ -4,6 +4,7 @@ import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments import com.saveourtool.diktat.DiktatRunnerFactory import com.saveourtool.diktat.api.DiktatReporterCreationArguments +import com.saveourtool.diktat.api.DiktatReporterType import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl @@ -120,11 +121,11 @@ abstract class DiktatBaseMojo : AbstractMojo() { ) val sourceRootDir = mavenProject.basedir.parentFile.toPath() - val reporterId = getReporterType() + val reporterType = getReporterType() val reporterArgs = DiktatReporterCreationArguments( - id = reporterId, + reporterType = reporterType, outputStream = getReporterOutput(), - sourceRootDir = sourceRootDir.takeIf { reporterId == "sarif" }, + sourceRootDir = sourceRootDir.takeIf { reporterType == DiktatReporterType.SARIF }, ) val args = DiktatRunnerArguments( configInputStream = configFile.inputStream(), @@ -143,13 +144,13 @@ abstract class DiktatBaseMojo : AbstractMojo() { } } - private fun getReporterType(): String = if (githubActions) { - "sarif" - } else if (reporter in setOf("sarif", "plain", "json", "html")) { - reporter + private fun getReporterType(): DiktatReporterType = if (githubActions) { + DiktatReporterType.SARIF } else { - log.warn("Reporter name ${this.reporter} was not specified or is invalid. Falling to 'plain' reporter") - "plain" + DiktatReporterType.entries.firstOrNull { it.id.equals(reporter, ignoreCase = true) } ?: run { + log.warn("Reporter name ${this.reporter} was not specified or is invalid. Falling to 'plain' reporter") + DiktatReporterType.PLAIN + } } private fun getReporterOutput(): OutputStream? = if (output.isNotBlank()) { From 37f7420e8f9cd281afb95fa8264dfee301f994d2 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Tue, 21 Nov 2023 13:01:18 +0300 Subject: [PATCH 26/26] diktatFix --- .../com/saveourtool/diktat/api/DiktatReporterType.kt | 7 ++++--- .../diktat/plugin/gradle/extension/DefaultReporter.kt | 1 - .../diktat/plugin/gradle/DiktatGradlePluginTest.kt | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterType.kt b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterType.kt index 73aa8842cd..142866562a 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterType.kt +++ b/diktat-api/src/main/kotlin/com/saveourtool/diktat/api/DiktatReporterType.kt @@ -8,10 +8,11 @@ enum class DiktatReporterType( val id: String, val extension: String, ) { - PLAIN("plain", "txt"), - SARIF("sarif", "sarif"), - JSON("json", "json"), CHECKSTYLE("checkstyle", "xml"), HTML("html", "html"), + JSON("json", "json"), NONE("none", ""), + PLAIN("plain", "txt"), + SARIF("sarif", "sarif"), + ; } diff --git a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt index 95351a43e5..6f55a3d243 100644 --- a/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt +++ b/diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/extension/DefaultReporter.kt @@ -19,7 +19,6 @@ import javax.inject.Inject /** * A base interface for reporter * - * @param extension extension of generated report * @param objectFactory * @param project * @property type type of reporter diff --git a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt index 1d51c6bb78..b401c9d5ee 100644 --- a/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/com/saveourtool/diktat/plugin/gradle/DiktatGradlePluginTest.kt @@ -5,9 +5,7 @@ import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.junit.jupiter.api.fail class DiktatGradlePluginTest { private val projectBuilder = ProjectBuilder.builder()