/
ProcessingSettingsFactory.kt
78 lines (73 loc) · 2.9 KB
/
ProcessingSettingsFactory.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package io.gitlab.arturbosch.detekt.core
import io.github.detekt.test.utils.NullPrintStream
import io.github.detekt.test.utils.resourceAsPath
import io.github.detekt.tooling.api.spec.ProcessingSpec
import io.github.detekt.tooling.api.spec.ReportsSpec
import io.github.detekt.tooling.dsl.ProcessingSpecBuilder
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.core.reporting.DETEKT_OUTPUT_REPORT_PATHS_KEY
import java.io.PrintStream
import java.nio.file.Path
import java.util.concurrent.AbstractExecutorService
import java.util.concurrent.TimeUnit
/**
* Single project input path constructor.
*/
fun createProcessingSettings(
inputPath: Path? = null,
config: Config = Config.empty,
reportPaths: Collection<ReportsSpec.Report> = emptyList(),
outputChannel: PrintStream = NullPrintStream(),
init: ProcessingSpecBuilder.() -> Unit = { /* no-op */ },
): ProcessingSettings {
val spec = ProcessingSpec {
project {
inputPaths = listOfNotNull(inputPath)
}
logging {
debug = true
this.outputChannel = outputChannel
errorChannel = NullPrintStream()
}
config {
// Use an empty config in tests to be compatible with old ProcessingSettings config default.
// This was in particular done due to all console reports being active with an empty config.
// These outputs are used to assert test conditions.
configPaths = listOf(resourceAsPath("configs/empty.yml"))
}
execution {
executorService = DirectExecutor() // run in the same thread
}
init.invoke(this)
}
return ProcessingSettings(spec, config).apply {
register(DETEKT_OUTPUT_REPORT_PATHS_KEY, reportPaths)
}
}
fun createNullLoggingSpec(
init: ProcessingSpecBuilder.() -> Unit = { /* no-op */ },
): ProcessingSpec =
ProcessingSpec {
logging {
outputChannel = NullPrintStream()
errorChannel = NullPrintStream()
}
config {
// Use an empty config in tests to be compatible with old ProcessingSettings config default.
// This was in particular done due to all console reports being active with an empty config.
// These outputs are used to assert test conditions.
configPaths = listOf(resourceAsPath("configs/empty.yml"))
}
execution {
executorService = DirectExecutor() // run in the same thread
}
init.invoke(this)
}
class DirectExecutor : AbstractExecutorService() {
override fun execute(command: Runnable): Unit = command.run()
override fun shutdown() = Unit
override fun shutdownNow(): MutableList<Runnable> = mutableListOf()
override fun isShutdown(): Boolean = true
override fun isTerminated(): Boolean = true
override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean = true
}