Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced diktat-runner #1813

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions diktat-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ plugins {
project.description = "This module builds diktat-cli to run diktat as CLI using ktlint"

dependencies {
implementation(projects.diktatApi)
implementation(projects.diktatKtlintEngine)
implementation(projects.diktatRules)
implementation(projects.diktatRunner)
implementation(libs.kotlinx.cli)
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlin.logging)
implementation(libs.slf4j.api)
implementation(libs.log4j2.core)
implementation(libs.log4j2.slf4j2)

testImplementation(projects.diktatKtlintEngine)
testImplementation(projects.diktatRules)
testImplementation(projects.diktatCommonTest)
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platform.suite)
Expand Down
12 changes: 0 additions & 12 deletions diktat-cli/src/main/kotlin/com/saveourtool/diktat/DiktatMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ package com.saveourtool.diktat
import com.saveourtool.diktat.api.DiktatProcessorListener
import com.saveourtool.diktat.cli.DiktatMode
import com.saveourtool.diktat.cli.DiktatProperties
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 io.github.oshai.kotlinlogging.KotlinLogging

Expand All @@ -31,13 +26,6 @@ private val loggingListener = object : DiktatProcessorListener {
}

fun main(args: Array<String>) {
val diktatRunnerFactory = DiktatRunnerFactory(
DiktatRuleConfigReaderImpl(),
DiktatRuleSetFactoryImpl(),
DiktatProcessorFactoryImpl(),
DiktatBaselineFactoryImpl(),
DiktatReporterFactoryImpl(),
)
val properties = DiktatProperties.parse(diktatRunnerFactory.diktatReporterFactory, args)
properties.configureLogger()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saveourtool.diktat.cli

import com.saveourtool.diktat.DiktatRunnerArguments
import com.saveourtool.diktat.ENGINE_INFO
import com.saveourtool.diktat.api.DiktatProcessorListener
import com.saveourtool.diktat.api.DiktatReporterCreationArguments
import com.saveourtool.diktat.api.DiktatReporterFactory
Expand All @@ -10,14 +11,16 @@ import com.saveourtool.diktat.common.config.rules.DIKTAT_ANALYSIS_CONF
import com.saveourtool.diktat.util.isKotlinCodeOrScript
import com.saveourtool.diktat.util.tryToPathIfExists
import com.saveourtool.diktat.util.walkByGlob

import generated.DIKTAT_VERSION
import generated.KTLINT_VERSION
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.LoggerContext
import org.slf4j.event.Level

import java.io.OutputStream
import java.nio.file.Path
import java.nio.file.Paths

import kotlin.io.path.createDirectories
import kotlin.io.path.inputStream
import kotlin.io.path.outputStream
Expand Down Expand Up @@ -169,7 +172,7 @@ data class DiktatProperties(
) {
"""
Diktat: $DIKTAT_VERSION
Ktlint: $KTLINT_VERSION
$ENGINE_INFO
""".trimIndent()
}
parser.addOptionAndShowTextWithExit(
Expand Down

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ plugins {

dependencies {
implementation(kotlin("gradle-plugin-api"))

implementation(projects.diktatRules)
implementation(projects.diktatKtlintEngine)
implementation(projects.diktatRunner)
// merge sarif reports
implementation(libs.sarif4k.jvm)
implementation(libs.kotlinx.serialization.json)
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(projects.diktatKtlintEngine)
testImplementation(libs.ktlint.cli.reporter.core)
testImplementation(libs.ktlint.cli.reporter.json)
testImplementation(libs.ktlint.cli.reporter.plain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
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.ktlint.DiktatBaselineFactoryImpl
import com.saveourtool.diktat.ktlint.DiktatProcessorFactoryImpl
import com.saveourtool.diktat.ktlint.DiktatReporterFactoryImpl
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
import com.saveourtool.diktat.plugin.gradle.extension.Reporters
import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl
import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl

import generated.DIKTAT_VERSION
import generated.KTLINT_VERSION
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.ConfigurableFileCollection
Expand Down Expand Up @@ -110,18 +106,6 @@
internal val shouldRun: Boolean by lazy {
!actualInputs.isEmpty
}
private val diktatReporterFactory by lazy {
DiktatReporterFactoryImpl()
}
private val diktatRunnerFactory by lazy {
DiktatRunnerFactory(
diktatRuleConfigReader = DiktatRuleConfigReaderImpl(),
diktatRuleSetFactory = DiktatRuleSetFactoryImpl(),
diktatProcessorFactory = DiktatProcessorFactoryImpl(),
diktatBaselineFactory = DiktatBaselineFactoryImpl(),
diktatReporterFactory = diktatReporterFactory,
)
}
private val diktatRunnerArguments by lazy {
val sourceRootDir by lazy {
project.rootProject.projectDir.toPath()
Expand Down Expand Up @@ -177,7 +161,7 @@
@TaskAction
fun run() {
if (extension.debug) {
project.logger.lifecycle("Running diktat $DIKTAT_VERSION with ktlint $KTLINT_VERSION")
project.logger.lifecycle("Running diktat $DIKTAT_VERSION with $ENGINE_INFO")

Check warning on line 164 in diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt

View check run for this annotation

Codecov / codecov/patch

diktat-gradle-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/gradle/tasks/DiktatTaskBase.kt#L164

Added line #L164 was not covered by tests
}
if (!shouldRun) {
/*
Expand Down
3 changes: 1 addition & 2 deletions diktat-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ dependencies {
compileOnly(libs.maven.core)

implementation(libs.kotlin.stdlib.jdk8)
implementation(projects.diktatRules)
implementation(projects.diktatKtlintEngine)
implementation(projects.diktatRunner)

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.vintage.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@ package com.saveourtool.diktat.plugin.maven

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
import com.saveourtool.diktat.ruleset.rules.DiktatRuleConfigReaderImpl
import com.saveourtool.diktat.ruleset.rules.DiktatRuleSetFactoryImpl
import com.saveourtool.diktat.diktatRunnerFactory

import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugin.Mojo
Expand Down Expand Up @@ -57,18 +52,6 @@ abstract class DiktatBaseMojo : AbstractMojo() {
*/
@Parameter(property = "diktat.baseline")
var baseline: File? = null
private val diktatReporterFactory by lazy {
DiktatReporterFactoryImpl()
}
private val diktatRunnerFactory by lazy {
DiktatRunnerFactory(
diktatRuleConfigReader = DiktatRuleConfigReaderImpl(),
diktatRuleSetFactory = DiktatRuleSetFactoryImpl(),
diktatProcessorFactory = DiktatProcessorFactoryImpl(),
diktatBaselineFactory = DiktatBaselineFactoryImpl(),
diktatReporterFactory = diktatReporterFactory,
)
}

/**
* Path to diktat yml config file. Can be either absolute or relative to project's root directory.
Expand Down
15 changes: 15 additions & 0 deletions diktat-runner/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@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")
}

project.description = "This module contains runner for diktat"

dependencies {
api(projects.diktatApi)
api(projects.diktatCommon)
implementation(projects.diktatKtlintEngine)
implementation(projects.diktatRules)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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

/**
Fixed Show fixed Hide fixed
* Info about engine
*/
const val ENGINE_INFO: String = "Ktlint: $KTLINT_VERSION"

/**
* @return initialized [DiktatRunnerFactory]
*/
val diktatRunnerFactory: DiktatRunnerFactory = DiktatRunnerFactory(
DiktatRuleConfigReaderImpl(),
DiktatRuleSetFactoryImpl(),
DiktatProcessorFactoryImpl(),
DiktatBaselineFactoryImpl(),
DiktatReporterFactoryImpl(),
)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ include("diktat-rules")
include("diktat-ruleset")
include("diktat-dev-ksp")
include("diktat-cli")
include("diktat-runner")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Expand Down
Loading