From b4039ad79663495f8b524960979fdf96372fc1c9 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 13:01:45 +0300 Subject: [PATCH 1/6] Split DiktatRunnerArguments to DiktatRunnerFactoryArguments and DiktatRunnerArguments ### What's done: - added DiktatFactories --- .../com/saveourtool/diktat/DiktatMain.kt | 4 +- .../diktat/cli/DiktatProperties.kt | 12 ++-- .../plugin/gradle/tasks/DiktatTaskBase.kt | 17 ++++-- .../diktat/plugin/maven/DiktatBaseMojo.kt | 10 +++- .../com/saveourtool/diktat/DiktatFactories.kt | 57 +++++++++++++++++++ .../com/saveourtool/diktat/DiktatRunner.kt | 0 .../diktat/DiktatRunnerArguments.kt | 15 +++++ .../saveourtool/diktat/DiktatRunnerFactory.kt | 16 ++---- .../diktat/DiktatRunnerFactoryArguments.kt | 15 +---- .../diktat/DiktatRunnerFactoryProvider.kt | 28 --------- 10 files changed, 106 insertions(+), 68 deletions(-) create mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt rename {diktat-api => diktat-runner}/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt (100%) create mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt rename {diktat-api => diktat-runner}/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt (76%) rename diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt => diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt (58%) delete mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryProvider.kt 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 5bbae68f30..d906de8ddb 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt @@ -33,12 +33,12 @@ fun main(args: Array) { "Loading diktatRuleSet using config ${properties.config}" } val currentFolder = Paths.get(".").toAbsolutePath().normalize() - val diktatRunnerArguments = properties.toRunnerArguments( + val (diktatRunnerCreationArguments, diktatRunnerArguments) = properties.toRunnerArguments( sourceRootDir = currentFolder, loggingListener = loggingListener, ) - val diktatRunner = diktatRunnerFactory(diktatRunnerArguments) + val diktatRunner = diktatRunnerFactory(diktatRunnerCreationArguments) when (properties.mode) { DiktatMode.CHECK -> diktatRunner.checkAll(diktatRunnerArguments) DiktatMode.FIX -> diktatRunner.fixAll(diktatRunnerArguments) { updatedFile -> diff --git a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt index 1344cb368b..c5ef235a03 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt @@ -1,6 +1,7 @@ package com.saveourtool.diktat.cli import com.saveourtool.diktat.DiktatRunnerArguments +import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.ENGINE_INFO import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments @@ -72,12 +73,12 @@ data class DiktatProperties( /** * @param sourceRootDir * @param loggingListener - * @return [DiktatRunnerArguments] created from [DiktatProperties] + * @return [DiktatRunnerFactoryArguments] created from [DiktatProperties] */ fun toRunnerArguments( sourceRootDir: Path, loggingListener: DiktatProcessorListener, - ): DiktatRunnerArguments { + ): Pair { val reporterCreationArguments = DiktatReporterCreationArguments( reporterType = reporterType, outputStream = getReporterOutput(), @@ -85,13 +86,14 @@ data class DiktatProperties( colorNameInPlain = colorNameInPlain, sourceRootDir = sourceRootDir, ) - return DiktatRunnerArguments( + return DiktatRunnerFactoryArguments( configInputStream = Paths.get(config).inputStream(), sourceRootDir = sourceRootDir, - files = getFiles(sourceRootDir), baselineFile = null, reporterArgsList = listOf(reporterCreationArguments), - loggingListener = loggingListener + ) to DiktatRunnerArguments( + files = getFiles(sourceRootDir), + loggingListener = loggingListener, ) } 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 19339a169b..2aa5352384 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,6 +2,7 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments +import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.DiktatRunnerFactory import com.saveourtool.diktat.ENGINE_INFO import com.saveourtool.diktat.api.DiktatProcessorListener @@ -106,7 +107,7 @@ abstract class DiktatTaskBase( internal val shouldRun: Boolean by lazy { !actualInputs.isEmpty } - private val diktatRunnerArguments by lazy { + private val diktatRunnerFactoryArguments by lazy { val sourceRootDir by lazy { project.rootProject.projectDir.toPath() } @@ -122,6 +123,14 @@ abstract class DiktatTaskBase( sourceRootDir = sourceRootDir.takeIf { reporter.type == DiktatReporterType.SARIF }, ) } + DiktatRunnerFactoryArguments( + configInputStream = configFile.get().asFile.inputStream(), + sourceRootDir = sourceRootDir, + baselineFile = baselineFile.map { it.asFile.toPath() }.orNull, + reporterArgsList = reporterCreationArgumentsList, + ) + } + private val diktatRunnerArguments by lazy { val loggingListener = object : DiktatProcessorListener { override fun beforeAll(files: Collection) { project.logger.info("Analyzing {} files with diktat in project {}", files.size, project.name) @@ -132,11 +141,7 @@ abstract class DiktatTaskBase( } } DiktatRunnerArguments( - configInputStream = configFile.get().asFile.inputStream(), - sourceRootDir = sourceRootDir, files = actualInputs.files.map { it.toPath() }, - baselineFile = baselineFile.map { it.asFile.toPath() }.orNull, - reporterArgsList = reporterCreationArgumentsList, loggingListener = loggingListener, ) } @@ -146,7 +151,7 @@ abstract class DiktatTaskBase( */ @get:Internal val diktatRunner by lazy { - diktatRunnerFactory(diktatRunnerArguments) + diktatRunnerFactory(diktatRunnerFactoryArguments) } init { 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 1dc1678eca..323e264aac 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,6 +2,7 @@ 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 @@ -104,14 +105,17 @@ abstract class DiktatBaseMojo : AbstractMojo() { } val reporterArgsList = reporters.map { it.toCreationArguments(mavenProject, sourceRootDir) } - val args = DiktatRunnerArguments( + val factoryArgs = DiktatRunnerFactoryArguments( configInputStream = configFile.inputStream(), sourceRootDir = sourceRootDir, - files = files(), baselineFile = baseline?.toPath(), reporterArgsList = reporterArgsList, ) - val diktatRunner = diktatRunnerFactory(args) + val diktatRunner = diktatRunnerFactory(factoryArgs) + val args = DiktatRunnerArguments( + + files = files(), + ) val errorCounter = runAction( runner = diktatRunner, args = args, diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt new file mode 100644 index 0000000000..e00d1f25a1 --- /dev/null +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt @@ -0,0 +1,57 @@ +/** + * Contains only initialized [com.saveourtool.diktat.DiktatRunnerFactory] + */ + +package com.saveourtool.diktat + +import com.saveourtool.diktat.api.DiktatBaselineFactory +import com.saveourtool.diktat.api.DiktatReporterFactory +import com.saveourtool.diktat.api.DiktatRuleConfigReader +import com.saveourtool.diktat.api.DiktatRuleSetFactory +import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl +import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl +import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl +import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl +import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl +import generated.KTLINT_VERSION + +/** + * Info about engine + */ +const val ENGINE_INFO: String = "Ktlint: $KTLINT_VERSION" + +/** + * @return initialized [DiktatRuleConfigReader] + */ +val diktatRuleConfigReader: DiktatRuleConfigReader = DiktatRuleConfigReaderImpl() + +/** + * @return initialized [DiktatRuleSetFactory] + */ +val diktatRuleSetFactory: DiktatRuleSetFactory = DiktatRuleSetFactoryImpl() + +/** + * @return initialized [DiktatProcessorFactory] + */ +val diktatProcessorFactory: DiktatProcessorFactory = DiktatProcessorFactoryImpl() + +/** + * @return initialized [DiktatBaselineFactory] + */ +val diktatBaselineFactory: DiktatBaselineFactory = DiktatBaselineFactoryImpl() + +/** + * @return initialized [DiktatReporterFactory] + */ +val diktatReporterFactory: DiktatReporterFactory = DiktatReporterFactoryImpl() + +/** + * @return initialized [DiktatRunnerFactory] + */ +val diktatRunnerFactory: DiktatRunnerFactory = DiktatRunnerFactory( + diktatRuleConfigReader, + diktatRuleSetFactory, + diktatProcessorFactory, + diktatBaselineFactory, + diktatReporterFactory, +) diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt similarity index 100% rename from diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt rename to diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt new file mode 100644 index 0000000000..f05ac7bb88 --- /dev/null +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt @@ -0,0 +1,15 @@ +package com.saveourtool.diktat + +import com.saveourtool.diktat.api.DiktatProcessorListener +import java.nio.file.Path + +/** + * Arguments for [DiktatRunner] + * + * @property files a collection of files which needs to be fixed + * @property loggingListener listener to log diktat runner phases, [DiktatProcessorListener.empty] by default + */ +data class DiktatRunnerArguments( + val files: Collection, + val loggingListener: DiktatProcessorListener = DiktatProcessorListener.empty, +) diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt similarity index 76% rename from diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt rename to diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt index 85c917fdf2..7e90c96b6c 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt @@ -1,15 +1,7 @@ package com.saveourtool.diktat -import com.saveourtool.diktat.api.DiktatBaseline +import com.saveourtool.diktat.api.* import com.saveourtool.diktat.api.DiktatBaseline.Companion.skipKnownErrors -import com.saveourtool.diktat.api.DiktatBaselineFactory -import com.saveourtool.diktat.api.DiktatProcessorListener -import com.saveourtool.diktat.api.DiktatReporter -import com.saveourtool.diktat.api.DiktatReporterFactory -import com.saveourtool.diktat.api.DiktatRuleConfig -import com.saveourtool.diktat.api.DiktatRuleConfigReader -import com.saveourtool.diktat.api.DiktatRuleSet -import com.saveourtool.diktat.api.DiktatRuleSetFactory import java.nio.file.Path /** @@ -27,12 +19,12 @@ class DiktatRunnerFactory( private val diktatProcessorFactory: DiktatProcessorFactory, private val diktatBaselineFactory: DiktatBaselineFactory, val diktatReporterFactory: DiktatReporterFactory, -) : Function1 { +) : Function1 { /** * @param args * @return an instance of [DiktatRunner] created using [args] */ - override fun invoke(args: DiktatRunnerArguments): DiktatRunner { + override fun invoke(args: DiktatRunnerFactoryArguments): DiktatRunner { val diktatRuleConfigs = diktatRuleConfigReader(args.configInputStream) val diktatRuleSet = diktatRuleSetFactory(diktatRuleConfigs) val processor = diktatProcessorFactory(diktatRuleSet) @@ -40,7 +32,7 @@ class DiktatRunnerFactory( val reporter = args.reporterArgsList .map { diktatReporterFactory(it) } - .let { DiktatReporter.union(it) } + .let { DiktatProcessorListener.union(it) } return DiktatRunner( diktatProcessor = processor, diff --git a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt similarity index 58% rename from diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt rename to diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt index fb8db04854..cf575b3a8b 100644 --- a/diktat-api/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt @@ -1,42 +1,33 @@ package com.saveourtool.diktat -import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments import java.io.InputStream import java.nio.file.Path import kotlin.io.path.inputStream /** - * Arguments for [DiktatRunner] + * Arguments for [DiktatRunnerFactory] to create [DiktatRunner] * * @property configInputStream an input stream with config to load Diktat's rules - * @property sourceRootDir a common root dir for all provided [files] - * @property files a collection of files which needs to be fixed + * @property sourceRootDir a common root dir for all provided [DiktatRunnerArguments.files] * @property baselineFile an optional path to file with baseline * @property reporterArgsList list of arguments to create reporters to report result - * @property loggingListener listener to log diktat runner phases, [DiktatProcessorListener.empty] by default */ -data class DiktatRunnerArguments( +data class DiktatRunnerFactoryArguments( val configInputStream: InputStream, val sourceRootDir: Path?, - val files: Collection, val baselineFile: Path?, val reporterArgsList: List = emptyList(), - val loggingListener: DiktatProcessorListener = DiktatProcessorListener.empty, ) { constructor( configFile: Path, sourceRootDir: Path?, - files: Collection, baselineFile: Path?, reporterArgsList: List = emptyList(), - loggingListener: DiktatProcessorListener = DiktatProcessorListener.empty, ) : this( configFile.inputStream(), sourceRootDir, - files, baselineFile, reporterArgsList, - loggingListener, ) } diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryProvider.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryProvider.kt deleted file mode 100644 index ef5de0640c..0000000000 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryProvider.kt +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Contains only initialized [com.saveourtool.diktat.DiktatRunnerFactory] - */ - -package com.saveourtool.diktat - -import com.saveourtool.diktat.ktlint.DiktatBaselineFactoryImpl -import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl -import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl -import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl -import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl -import generated.KTLINT_VERSION - -/** - * Info about engine - */ -const val ENGINE_INFO: String = "Ktlint: $KTLINT_VERSION" - -/** - * @return initialized [DiktatRunnerFactory] - */ -val diktatRunnerFactory: DiktatRunnerFactory = DiktatRunnerFactory( - DiktatRuleConfigReaderImpl(), - DiktatRuleSetFactoryImpl(), - DiktatProcessorFactoryImpl(), - DiktatBaselineFactoryImpl(), - DiktatReporterFactoryImpl(), -) From 7eeea51e13c62bb5b27d72e656b540facda45799 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 14:27:45 +0300 Subject: [PATCH 2/6] downgrade guava --- .../diktat/plugin/gradle/tasks/DiktatTaskBase.kt | 4 ++-- .../kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt | 9 ++++++++- gradle/libs.versions.toml | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) 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 2aa5352384..cfce068715 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,8 +2,8 @@ package com.saveourtool.diktat.plugin.gradle.tasks import com.saveourtool.diktat.DiktatRunner import com.saveourtool.diktat.DiktatRunnerArguments -import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.DiktatRunnerFactory +import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.ENGINE_INFO import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments @@ -35,8 +35,8 @@ 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.Files import java.nio.file.Path /** diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt index 7e90c96b6c..a83e4b63b2 100644 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt @@ -1,7 +1,14 @@ package com.saveourtool.diktat -import com.saveourtool.diktat.api.* +import com.saveourtool.diktat.api.DiktatBaseline import com.saveourtool.diktat.api.DiktatBaseline.Companion.skipKnownErrors +import com.saveourtool.diktat.api.DiktatBaselineFactory +import com.saveourtool.diktat.api.DiktatProcessorListener +import com.saveourtool.diktat.api.DiktatReporter +import com.saveourtool.diktat.api.DiktatReporterFactory +import com.saveourtool.diktat.api.DiktatRuleConfigReader +import com.saveourtool.diktat.api.DiktatRuleSetFactory + import java.nio.file.Path /** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1830cd4cd9..d7c5de2718 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ serialization = "1.6.0" ktlint = "1.0.1" junit = "5.10.1" junit-platfrom = "1.10.1" -guava = "32.1.3-jre" +guava = "32.0.1-jre" commons-cli = "1.6.0" commons-io = "2.15.0" detekt = "1.23.3" From 26b6fb8ba5c91759e05549382d95dd12ee4129da Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 16:12:33 +0300 Subject: [PATCH 3/6] upgrade guava back + added shadow jar for diktat-runner --- diktat-runner/build.gradle.kts | 30 +++++++++++++++++++++++++++++- gradle/libs.versions.toml | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/diktat-runner/build.gradle.kts b/diktat-runner/build.gradle.kts index c147193886..270233ad43 100644 --- a/diktat-runner/build.gradle.kts +++ b/diktat-runner/build.gradle.kts @@ -1,8 +1,14 @@ +import com.saveourtool.diktat.buildutils.configurePublications +import com.saveourtool.diktat.buildutils.configurePublishing +import com.github.jengelman.gradle.plugins.shadow.ShadowExtension +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + @Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797 plugins { id("com.saveourtool.diktat.buildutils.kotlin-jvm-configuration") id("com.saveourtool.diktat.buildutils.code-quality-convention") - id("com.saveourtool.diktat.buildutils.publishing-default-configuration") + id("com.saveourtool.diktat.buildutils.publishing-configuration") + alias(libs.plugins.shadow) } project.description = "This module contains runner for diktat" @@ -13,3 +19,25 @@ dependencies { implementation(projects.diktatKtlintEngine) implementation(projects.diktatRules) } + +tasks.named("shadowJar") { + archiveClassifier.set("shadow") + duplicatesStrategy = DuplicatesStrategy.FAIL +} + +publishing { + publications { + create("maven") { + from(components["java"]) + } + // it creates a publication for shadowJar + create("shadow") { + // https://github.com/johnrengelman/shadow/issues/417#issuecomment-830668442 + project.extensions.configure { + component(this@create) + } + } + } +} +configurePublications() +configurePublishing() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d7c5de2718..1830cd4cd9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ serialization = "1.6.0" ktlint = "1.0.1" junit = "5.10.1" junit-platfrom = "1.10.1" -guava = "32.0.1-jre" +guava = "32.1.3-jre" commons-cli = "1.6.0" commons-io = "2.15.0" detekt = "1.23.3" From eadbff2d863f1049d42b5ed3ed410a060fc913e5 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 18:37:52 +0300 Subject: [PATCH 4/6] WIP --- .../plugin/gradle/tasks/DiktatCheckTask.kt | 3 +- .../plugin/gradle/tasks/DiktatFixTask.kt | 3 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 27 ++------ .../diktat/ruleset/utils/StringCaseUtils.kt | 1 + .../com/saveourtool/diktat/DiktatFactories.kt | 11 ---- .../com/saveourtool/diktat/DiktatRunner.kt | 63 ++++++++++++------- .../diktat/DiktatRunnerArguments.kt | 10 +++ .../saveourtool/diktat/DiktatRunnerFactory.kt | 62 ------------------ .../diktat/DiktatRunnerFactoryArguments.kt | 33 ---------- 9 files changed, 58 insertions(+), 155 deletions(-) delete mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt delete mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt 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 0bd16a3cc3..2bc9be556e 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,9 +24,8 @@ abstract class DiktatCheckTask @Inject constructor( objectFactory ) { override fun doRun( - runner: DiktatRunner, args: DiktatRunnerArguments - ): Int = runner.checkAll(args) + ): Int = DiktatRunner.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 eeee80a933..9ca51fee2a 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,9 +24,8 @@ abstract class DiktatFixTask @Inject constructor( objectFactory ) { override fun doRun( - runner: DiktatRunner, args: DiktatRunnerArguments - ): Int = runner.fixAll(args) { updatedFile -> + ): Int = DiktatRunner.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 cfce068715..67f24436ea 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,13 +2,10 @@ 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.DiktatRunnerFactoryArguments 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 @@ -107,7 +104,7 @@ abstract class DiktatTaskBase( internal val shouldRun: Boolean by lazy { !actualInputs.isEmpty } - private val diktatRunnerFactoryArguments by lazy { + private val diktatRunnerArguments by lazy { val sourceRootDir by lazy { project.rootProject.projectDir.toPath() } @@ -123,14 +120,6 @@ abstract class DiktatTaskBase( sourceRootDir = sourceRootDir.takeIf { reporter.type == DiktatReporterType.SARIF }, ) } - DiktatRunnerFactoryArguments( - configInputStream = configFile.get().asFile.inputStream(), - sourceRootDir = sourceRootDir, - baselineFile = baselineFile.map { it.asFile.toPath() }.orNull, - reporterArgsList = reporterCreationArgumentsList, - ) - } - private val diktatRunnerArguments by lazy { val loggingListener = object : DiktatProcessorListener { override fun beforeAll(files: Collection) { project.logger.info("Analyzing {} files with diktat in project {}", files.size, project.name) @@ -141,19 +130,15 @@ abstract class DiktatTaskBase( } } DiktatRunnerArguments( + configInputStream = configFile.get().asFile.inputStream(), + sourceRootDir = sourceRootDir, files = actualInputs.files.map { it.toPath() }, + baselineFile = baselineFile.map { it.asFile.toPath() }.orNull, + reporterArgsList = reporterCreationArgumentsList, loggingListener = loggingListener, ) } - /** - * [DiktatRunner] created based on a default [DiktatRunnerFactory] - */ - @get:Internal - val diktatRunner by lazy { - diktatRunnerFactory(diktatRunnerFactoryArguments) - } - init { group = LifecycleBasePlugin.VERIFICATION_GROUP } @@ -182,7 +167,6 @@ abstract class DiktatTaskBase( private fun doRun() { val errorCounter = doRun( - runner = diktatRunner, args = diktatRunnerArguments ) if (errorCounter > 0 && !ignoreFailures) { @@ -198,7 +182,6 @@ abstract class DiktatTaskBase( * @return count of errors */ abstract fun doRun( - runner: DiktatRunner, args: DiktatRunnerArguments ): Int diff --git a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt index a6502527ff..e5f67cebab 100644 --- a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt +++ b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt @@ -90,6 +90,7 @@ fun String.toUpperSnakeCase(): String { fun String.toLowerCamelCase(): String { // PascalCase -> PASCAL_CASE if (this.isPascalCase()) { + return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this) } // lower -> LOWER 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 e00d1f25a1..211fa2e373 100644 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt @@ -44,14 +44,3 @@ val diktatBaselineFactory: DiktatBaselineFactory = DiktatBaselineFactoryImpl() * @return initialized [DiktatReporterFactory] */ val diktatReporterFactory: DiktatReporterFactory = DiktatReporterFactoryImpl() - -/** - * @return initialized [DiktatRunnerFactory] - */ -val diktatRunnerFactory: DiktatRunnerFactory = DiktatRunnerFactory( - diktatRuleConfigReader, - diktatRuleSetFactory, - diktatProcessorFactory, - diktatBaselineFactory, - diktatReporterFactory, -) diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt index 8a1605b809..44588fff00 100644 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunner.kt @@ -1,5 +1,7 @@ package com.saveourtool.diktat +import com.saveourtool.diktat.api.DiktatBaseline +import com.saveourtool.diktat.api.DiktatBaseline.Companion.skipKnownErrors import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatProcessorListener.Companion.countErrorsAsProcessorListener import com.saveourtool.diktat.api.DiktatReporter @@ -12,30 +14,8 @@ private typealias RunAction = (DiktatProcessor, DiktatProcessorListener) -> Unit /** * A runner for diktat on bunch of files using baseline and reporter - * - * @param diktatProcessor - * @property diktatReporter */ -data class DiktatRunner( - private val diktatProcessor: DiktatProcessor, - val diktatReporter: DiktatReporter, -) { - private fun doRun( - args: DiktatRunnerArguments, - runAction: RunAction, - ): Int { - val errorCounter = AtomicInteger() - runAction( - diktatProcessor, - DiktatProcessorListener( - args.loggingListener, - diktatReporter, - errorCounter.countErrorsAsProcessorListener() - ), - ) - return errorCounter.get() - } - +object DiktatRunner { /** * Run `diktat fix` for all [DiktatRunnerArguments.files]. * @@ -82,4 +62,41 @@ data class DiktatRunner( } listener.afterAll() } + private fun doRun( + args: DiktatRunnerArguments, + runAction: RunAction, + ): Int { + val diktatRuleConfigs = diktatRuleConfigReader(args.configInputStream) + val diktatRuleSet = diktatRuleSetFactory(diktatRuleConfigs) + val processor = diktatProcessorFactory(diktatRuleSet) + val (baseline, baselineGenerator) = resolveBaseline(args.baselineFile, args.sourceRootDir) + + val reporter = args.reporterArgsList + .map { diktatReporterFactory(it) } + .let { DiktatReporter.union(it) } + + val errorCounter = AtomicInteger() + runAction( + processor, + DiktatProcessorListener( + args.loggingListener, + DiktatReporter(reporter.skipKnownErrors(baseline), baselineGenerator), + errorCounter.countErrorsAsProcessorListener() + ), + ) + return errorCounter.get() + } + + private fun resolveBaseline( + baselineFile: Path?, + sourceRootDir: Path?, + ): Pair = baselineFile + ?.let { diktatBaselineFactory.tryToLoad(it, sourceRootDir) } + ?.let { it to DiktatProcessorListener.empty } + ?: run { + val baselineGenerator = baselineFile?.let { + diktatBaselineFactory.generator(it, sourceRootDir) + } ?: DiktatProcessorListener.empty + DiktatBaseline.empty to baselineGenerator + } } diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt index f05ac7bb88..5204a098db 100644 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerArguments.kt @@ -1,15 +1,25 @@ package com.saveourtool.diktat import com.saveourtool.diktat.api.DiktatProcessorListener +import com.saveourtool.diktat.api.DiktatReporterCreationArguments +import java.io.InputStream import java.nio.file.Path /** * Arguments for [DiktatRunner] * + * @property configInputStream an input stream with config to load Diktat's rules + * @property sourceRootDir a common root dir for all provided [DiktatRunnerArguments.files] * @property files a collection of files which needs to be fixed + * @property baselineFile an optional path to file with baseline + * @property reporterArgsList list of arguments to create reporters to report result * @property loggingListener listener to log diktat runner phases, [DiktatProcessorListener.empty] by default */ data class DiktatRunnerArguments( + val configInputStream: InputStream, + val sourceRootDir: Path?, val files: Collection, + val baselineFile: Path?, + val reporterArgsList: List = emptyList(), val loggingListener: DiktatProcessorListener = DiktatProcessorListener.empty, ) diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt deleted file mode 100644 index a83e4b63b2..0000000000 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactory.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.saveourtool.diktat - -import com.saveourtool.diktat.api.DiktatBaseline -import com.saveourtool.diktat.api.DiktatBaseline.Companion.skipKnownErrors -import com.saveourtool.diktat.api.DiktatBaselineFactory -import com.saveourtool.diktat.api.DiktatProcessorListener -import com.saveourtool.diktat.api.DiktatReporter -import com.saveourtool.diktat.api.DiktatReporterFactory -import com.saveourtool.diktat.api.DiktatRuleConfigReader -import com.saveourtool.diktat.api.DiktatRuleSetFactory - -import java.nio.file.Path - -/** - * A factory to create [DiktatRunner] - * - * @param diktatRuleConfigReader a reader for [DiktatRuleConfig] - * @param diktatRuleSetFactory a factory for [DiktatRuleSet] - * @param diktatProcessorFactory a factory for [DiktatProcessor] - * @param diktatBaselineFactory a factory for [DiktatBaseline] - * @property diktatReporterFactory a factory for [DiktatReporter] - */ -class DiktatRunnerFactory( - private val diktatRuleConfigReader: DiktatRuleConfigReader, - private val diktatRuleSetFactory: DiktatRuleSetFactory, - private val diktatProcessorFactory: DiktatProcessorFactory, - private val diktatBaselineFactory: DiktatBaselineFactory, - val diktatReporterFactory: DiktatReporterFactory, -) : Function1 { - /** - * @param args - * @return an instance of [DiktatRunner] created using [args] - */ - override fun invoke(args: DiktatRunnerFactoryArguments): DiktatRunner { - val diktatRuleConfigs = diktatRuleConfigReader(args.configInputStream) - val diktatRuleSet = diktatRuleSetFactory(diktatRuleConfigs) - val processor = diktatProcessorFactory(diktatRuleSet) - val (baseline, baselineGenerator) = resolveBaseline(args.baselineFile, args.sourceRootDir) - - val reporter = args.reporterArgsList - .map { diktatReporterFactory(it) } - .let { DiktatProcessorListener.union(it) } - - return DiktatRunner( - diktatProcessor = processor, - diktatReporter = DiktatReporter(reporter.skipKnownErrors(baseline), baselineGenerator), - ) - } - - private fun resolveBaseline( - baselineFile: Path?, - sourceRootDir: Path?, - ): Pair = baselineFile - ?.let { diktatBaselineFactory.tryToLoad(it, sourceRootDir) } - ?.let { it to DiktatProcessorListener.empty } - ?: run { - val baselineGenerator = baselineFile?.let { - diktatBaselineFactory.generator(it, sourceRootDir) - } ?: DiktatProcessorListener.empty - DiktatBaseline.empty to baselineGenerator - } -} diff --git a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt deleted file mode 100644 index cf575b3a8b..0000000000 --- a/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatRunnerFactoryArguments.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.saveourtool.diktat - -import com.saveourtool.diktat.api.DiktatReporterCreationArguments -import java.io.InputStream -import java.nio.file.Path -import kotlin.io.path.inputStream - -/** - * Arguments for [DiktatRunnerFactory] to create [DiktatRunner] - * - * @property configInputStream an input stream with config to load Diktat's rules - * @property sourceRootDir a common root dir for all provided [DiktatRunnerArguments.files] - * @property baselineFile an optional path to file with baseline - * @property reporterArgsList list of arguments to create reporters to report result - */ -data class DiktatRunnerFactoryArguments( - val configInputStream: InputStream, - val sourceRootDir: Path?, - val baselineFile: Path?, - val reporterArgsList: List = emptyList(), -) { - constructor( - configFile: Path, - sourceRootDir: Path?, - baselineFile: Path?, - reporterArgsList: List = emptyList(), - ) : this( - configFile.inputStream(), - sourceRootDir, - baselineFile, - reporterArgsList, - ) -} From 22bd44266c9755a13c8b78094c0bb6b37cd375f0 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 18:59:03 +0300 Subject: [PATCH 5/6] supported in maven --- .../saveourtool/diktat/plugin/maven/DiktatBaseMojo.kt | 11 ++--------- .../com/saveourtool/diktat/plugin/maven/DiktatMojo.kt | 6 ++---- .../diktat/ruleset/utils/StringCaseUtils.kt | 1 - 3 files changed, 4 insertions(+), 14 deletions(-) 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 323e264aac..8917a3dce9 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 @@ -72,13 +72,11 @@ abstract class DiktatBaseMojo : AbstractMojo() { lateinit var excludes: List /** - * @param runner instance of [DiktatRunner] used in analysis * @param args arguments for [DiktatRunner] * @return count of errors */ @Suppress("TOO_MANY_PARAMETERS") abstract fun runAction( - runner: DiktatRunner, args: DiktatRunnerArguments, ): Int @@ -105,19 +103,14 @@ abstract class DiktatBaseMojo : AbstractMojo() { } val reporterArgsList = reporters.map { it.toCreationArguments(mavenProject, sourceRootDir) } - val factoryArgs = DiktatRunnerFactoryArguments( + val args = DiktatRunnerArguments( configInputStream = configFile.inputStream(), sourceRootDir = sourceRootDir, + files = files(), baselineFile = baseline?.toPath(), reporterArgsList = reporterArgsList, ) - val diktatRunner = diktatRunnerFactory(factoryArgs) - val args = DiktatRunnerArguments( - - files = files(), - ) val errorCounter = runAction( - runner = diktatRunner, args = args, ) if (errorCounter > 0) { diff --git a/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatMojo.kt b/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatMojo.kt index 5f1ce4a428..fd213c5d4e 100644 --- a/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatMojo.kt +++ b/diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/DiktatMojo.kt @@ -16,9 +16,8 @@ import org.apache.maven.plugins.annotations.Mojo @Suppress("unused") class DiktatCheckMojo : DiktatBaseMojo() { override fun runAction( - runner: DiktatRunner, args: DiktatRunnerArguments, - ): Int = runner.checkAll(args) + ): Int = DiktatRunner.checkAll(args) } /** @@ -29,9 +28,8 @@ class DiktatCheckMojo : DiktatBaseMojo() { @Suppress("unused") class DiktatFixMojo : DiktatBaseMojo() { override fun runAction( - runner: DiktatRunner, args: DiktatRunnerArguments, - ): Int = runner.fixAll(args) { updatedFile -> + ): Int = DiktatRunner.fixAll(args) { updatedFile -> log.info("Original and formatted content differ, writing to ${updatedFile.fileName}...") } } diff --git a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt index e5f67cebab..a6502527ff 100644 --- a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt +++ b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/utils/StringCaseUtils.kt @@ -90,7 +90,6 @@ fun String.toUpperSnakeCase(): String { fun String.toLowerCamelCase(): String { // PascalCase -> PASCAL_CASE if (this.isPascalCase()) { - return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, this) } // lower -> LOWER From c75ff9da75d954837b4439e8a01d37599c23197c Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Wed, 29 Nov 2023 19:00:44 +0300 Subject: [PATCH 6/6] supported in cli --- .../main/kotlin/com/saveourtool/diktat/DiktatMain.kt | 9 ++++----- .../com/saveourtool/diktat/cli/DiktatProperties.kt | 10 ++++------ 2 files changed, 8 insertions(+), 11 deletions(-) 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 d906de8ddb..494f899474 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt @@ -26,22 +26,21 @@ private val loggingListener = object : DiktatProcessorListener { } fun main(args: Array) { - val properties = DiktatProperties.parse(diktatRunnerFactory.diktatReporterFactory, args) + val properties = DiktatProperties.parse(diktatReporterFactory, args) properties.configureLogger() log.debug { "Loading diktatRuleSet using config ${properties.config}" } val currentFolder = Paths.get(".").toAbsolutePath().normalize() - val (diktatRunnerCreationArguments, diktatRunnerArguments) = properties.toRunnerArguments( + val diktatRunnerArguments = properties.toRunnerArguments( sourceRootDir = currentFolder, loggingListener = loggingListener, ) - val diktatRunner = diktatRunnerFactory(diktatRunnerCreationArguments) 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-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt index c5ef235a03..ab6863f333 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/cli/DiktatProperties.kt @@ -1,7 +1,6 @@ package com.saveourtool.diktat.cli import com.saveourtool.diktat.DiktatRunnerArguments -import com.saveourtool.diktat.DiktatRunnerFactoryArguments import com.saveourtool.diktat.ENGINE_INFO import com.saveourtool.diktat.api.DiktatProcessorListener import com.saveourtool.diktat.api.DiktatReporterCreationArguments @@ -73,12 +72,12 @@ data class DiktatProperties( /** * @param sourceRootDir * @param loggingListener - * @return [DiktatRunnerFactoryArguments] created from [DiktatProperties] + * @return [DiktatRunnerArguments] created from [DiktatProperties] */ fun toRunnerArguments( sourceRootDir: Path, loggingListener: DiktatProcessorListener, - ): Pair { + ): DiktatRunnerArguments { val reporterCreationArguments = DiktatReporterCreationArguments( reporterType = reporterType, outputStream = getReporterOutput(), @@ -86,13 +85,12 @@ data class DiktatProperties( colorNameInPlain = colorNameInPlain, sourceRootDir = sourceRootDir, ) - return DiktatRunnerFactoryArguments( + return DiktatRunnerArguments( configInputStream = Paths.get(config).inputStream(), sourceRootDir = sourceRootDir, + files = getFiles(sourceRootDir), baselineFile = null, reporterArgsList = listOf(reporterCreationArguments), - ) to DiktatRunnerArguments( - files = getFiles(sourceRootDir), loggingListener = loggingListener, ) }