From 137b4f7bd8ad20d323bf44042c2ee442bcb2450f Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 30 Nov 2023 14:25:10 +0300 Subject: [PATCH] Added shadow for diktat-runner (#1834) - added shadow artifact for diktat-runner to resolve issue with guava in spotless --- .../com/saveourtool/diktat/DiktatMain.kt | 2 +- .../diktat/cli/DiktatProperties.kt | 2 +- .../plugin/gradle/tasks/DiktatTaskBase.kt | 2 +- .../diktat/plugin/maven/DiktatBaseMojo.kt | 1 - diktat-runner/build.gradle.kts | 30 +++++++++- .../com/saveourtool/diktat/DiktatFactories.kt | 57 +++++++++++++++++++ .../diktat/DiktatRunnerFactoryProvider.kt | 28 --------- 7 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt 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..e0be27e5b1 100644 --- a/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt +++ b/diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt @@ -26,7 +26,7 @@ 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 { 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..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 @@ -91,7 +91,7 @@ data class DiktatProperties( files = getFiles(sourceRootDir), baselineFile = null, reporterArgsList = listOf(reporterCreationArguments), - loggingListener = loggingListener + 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..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 @@ -34,8 +34,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-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..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 @@ -75,7 +75,6 @@ abstract class DiktatBaseMojo : AbstractMojo() { * @param args arguments for [DiktatRunner] * @return count of errors */ - @Suppress("TOO_MANY_PARAMETERS") abstract fun runAction( runner: DiktatRunner, args: DiktatRunnerArguments, 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/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..90bee667f6 --- /dev/null +++ b/diktat-runner/src/main/kotlin/com/saveourtool/diktat/DiktatFactories.kt @@ -0,0 +1,57 @@ +/** + * Contains only initialized factories + */ + +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-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(), -)