From 0156f211c336268118d1e8e41cb5899d72a4f6c8 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 30 Nov 2023 11:05:17 +0300 Subject: [PATCH] reverted moving DiktatRunner 2 --- .../kotlin/com/saveourtool/diktat/DiktatRunner.kt | 2 ++ .../com/saveourtool/diktat/DiktatRunnerArguments.kt | 1 + .../main/kotlin/com/saveourtool/diktat/DiktatMain.kt | 5 +++-- .../diktat/plugin/gradle/tasks/DiktatCheckTask.kt | 3 ++- .../diktat/plugin/gradle/tasks/DiktatFixTask.kt | 3 ++- .../diktat/plugin/gradle/tasks/DiktatTaskBase.kt | 12 ++++++++++++ .../diktat/plugin/maven/DiktatBaseMojo.kt | 1 - .../kotlin/com/saveourtool/diktat/DiktatFactories.kt | 11 +++++++++++ 8 files changed, 33 insertions(+), 5 deletions(-) diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt b/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt index 9378851f5e..8a1605b809 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt +++ b/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt @@ -7,6 +7,7 @@ import java.nio.file.Path import java.util.concurrent.atomic.AtomicInteger import kotlin.io.path.readText import kotlin.io.path.writeText + private typealias RunAction = (DiktatProcessor, DiktatProcessorListener) -> Unit /** @@ -61,6 +62,7 @@ data class DiktatRunner( } listener.afterAll() } + /** * Run `diktat check` for all [DiktatRunnerArguments.files]. * diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt b/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt index b8a25c676c..fb8db04854 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt +++ b/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt @@ -1,4 +1,5 @@ package com.saveourtool.diktat + import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments import java.io.InputStream diff --git a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt index 494f899474..e0be27e5b1 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt @@ -38,9 +38,10 @@ fun main(args: Array) { loggingListener = loggingListener, ) + val diktatRunner = diktatRunnerFactory(diktatRunnerArguments) when (properties.mode) { - DiktatMode.CHECK -> DiktatRunner.checkAll(diktatRunnerArguments) - DiktatMode.FIX -> DiktatRunner.fixAll(diktatRunnerArguments) { updatedFile -> + DiktatMode.CHECK -> diktatRunner.checkAll(diktatRunnerArguments) + DiktatMode.FIX -> diktatRunner.fixAll(diktatRunnerArguments) { updatedFile -> log.warn { "Original and formatted content differ, writing to ${updatedFile.absolutePathString()}..." } 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 2bc9be556e..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 @@ -24,8 +24,9 @@ abstract class DiktatCheckTask @Inject constructor( objectFactory ) { override fun doRun( + runner: DiktatRunner, args: DiktatRunnerArguments - ): Int = DiktatRunner.checkAll(args) + ): Int = runner.checkAll(args) 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 9ca51fee2a..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 @@ -24,8 +24,9 @@ abstract class DiktatFixTask @Inject constructor( objectFactory ) { override fun doRun( + runner: DiktatRunner, args: DiktatRunnerArguments - ): Int = DiktatRunner.fixAll(args) { updatedFile -> + ): Int = runner.fixAll(args) { updatedFile -> project.logger.info("Original and formatted content differ, writing to ${updatedFile.fileName}...") } 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 67f24436ea..a3ed0c197a 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 @@ -2,10 +2,12 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments +import com.saveourtool.diktat.DiktatRunnerFactory import com.saveourtool.diktat.ENGINE_INFO import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments import com.saveourtool.diktat.api.DiktatReporterType +import com.saveourtool.diktat.diktatRunnerFactory import com.saveourtool.diktat.plugin.gradle.DiktatExtension import com.saveourtool.diktat.plugin.gradle.extension.DefaultReporter import com.saveourtool.diktat.plugin.gradle.extension.PlainReporter @@ -139,6 +141,14 @@ abstract class DiktatTaskBase( ) } + /** + * [DiktatRunner] created based on a default [DiktatRunnerFactory] + */ + @get:Internal + val diktatRunner by lazy { + diktatRunnerFactory(diktatRunnerArguments) + } + init { group = LifecycleBasePlugin.VERIFICATION_GROUP } @@ -167,6 +177,7 @@ abstract class DiktatTaskBase( private fun doRun() { val errorCounter = doRun( + runner = diktatRunner, args = diktatRunnerArguments ) if (errorCounter > 0 && !ignoreFailures) { @@ -182,6 +193,7 @@ abstract class DiktatTaskBase( * @return count of errors */ abstract fun doRun( + runner: DiktatRunner, args: DiktatRunnerArguments ): Int 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 9dc75390db..ae2cf519d3 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 @@ -2,7 +2,6 @@ package com.saveourtool.diktat.plugin.maven import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments -import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.diktatRunnerFactory import com.saveourtool.diktat.plugin.maven.reporters.GitHubActionsReporter import com.saveourtool.diktat.plugin.maven.reporters.PlainReporter diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt index d27a00f46f..90bee667f6 100644 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt @@ -44,3 +44,14 @@ val diktatBaselineFactory: DiktatBaselineFactory = DiktatBaselineFactoryImpl() * @return initialized [DiktatReporterFactory] */ val diktatReporterFactory: DiktatReporterFactory = DiktatReporterFactoryImpl() + +/** + * @return initialized [DiktatRunnerFactory] + */ +val diktatRunnerFactory: DiktatRunnerFactory = DiktatRunnerFactory( + diktatRuleConfigReader, + diktatRuleSetFactory, + diktatProcessorFactory, + diktatBaselineFactory, + diktatReporterFactory, +)