<commit_before>package io.gitlab.arturbosch.detekt.cli

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.YamlConfig
import io.gitlab.arturbosch.detekt.core.Detekt
import io.gitlab.arturbosch.detekt.core.PathFilter
import java.nio.file.Path
import java.nio.file.Paths
import kotlin.system.measureTimeMillis

/**
 * @author <NAME>
 */
object Runner {

	fun runWith(main: Main) {
		val pathFilters = with(Main) { main.filters.letIf { split(";").map(::PathFilter) } }
		val rules = with(Main) { main.rules.letIf { split(";").map { Paths.get(it) } } }
		val config = loadConfiguration(main.config, main)
		measureTimeMillis {
			val detektion = Detekt(main.project, config, rules, pathFilters, main.parallel).run()
			Output(detektion, main).report()
			SmellBorder(config, main).check(detektion)
		}.let { println("\ndetekt run within $it ms") }
	}

	private fun loadConfiguration(configPath: Path?, main: Main): Config {
		return if (configPath != null) YamlConfig.load(configPath)
		else if (main.formatting) object : Config {
			override fun subConfig(key: String): Config {
				return this
			}

			override fun <T : Any> valueOrDefault(key: String, default: () -> T): T {
				@Suppress("UNCHECKED_CAST")<commit_msg>Always measure running time of detekt - Closes#81<commit_after>package io.gitlab.arturbosch.detekt.cli

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.YamlConfig
import io.gitlab.arturbosch.detekt.core.Detekt
import io.gitlab.arturbosch.detekt.core.PathFilter
import java.nio.file.Path
import java.nio.file.Paths

/**
 * @author <NAME>
 */
object Runner {

	fun runWith(main: Main) {
		val pathFilters = with(Main) { main.filters.letIf { split(";").map(::PathFilter) } }
		val rules = with(Main) { main.rules.letIf { split(";").map { Paths.get(it) } } }
		val config = loadConfiguration(main.config, main)

		val start = System.currentTimeMillis()
		val detektion = Detekt(main.project, config, rules, pathFilters, main.parallel).run()
		Output(detektion, main).report()
		val end = System.currentTimeMillis() - start
		println("\ndetekt run within $end ms")

		SmellBorder(config, main).check(detektion)
	}

	private fun loadConfiguration(configPath: Path?, main: Main): Config {
		return if (configPath != null) YamlConfig.load(configPath)
		else if (main.formatting) object : Config {
			override fun subConfig(key: String): Config {
				return this
			}

			override fun <T : Any> valueOrDefault(key: String, default: () -> T): T {
				@Suppress("UNCHECKED_CAST")
{'fraction_non_alphanumeric': 0.13766132186155652, 'fraction_numerical': 0.0007821666014861165, 'mean_word_length': 4.54880694143167, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3957006', 'n_tokens_mistral': 918, 'n_tokens_neox': 886, 'n_words': 188}