Skip to content

Commit

Permalink
reverted moving DiktatRunner 2
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Nov 30, 2023
1 parent f41d922 commit 0156f21
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -61,6 +62,7 @@ data class DiktatRunner(
}
listener.afterAll()
}

/**
* Run `diktat check` for all [DiktatRunnerArguments.files].
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.saveourtool.diktat

import com.saveourtool.diktat.api.DiktatProcessorListener
import com.saveourtool.diktat.api.DiktatReporterCreationArguments
import java.io.InputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ fun main(args: Array<String>) {
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()}..."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}...")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -167,6 +177,7 @@ abstract class DiktatTaskBase(

private fun doRun() {
val errorCounter = doRun(
runner = diktatRunner,
args = diktatRunnerArguments
)
if (errorCounter > 0 && !ignoreFailures) {
Expand All @@ -182,6 +193,7 @@ abstract class DiktatTaskBase(
* @return count of errors
*/
abstract fun doRun(
runner: DiktatRunner,
args: DiktatRunnerArguments
): Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

0 comments on commit 0156f21

Please sign in to comment.