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

Update dependency io.github.microutils:kotlin-logging-jvm to v3 #1529

Merged
merged 11 commits into from
Oct 31, 2022
14 changes: 0 additions & 14 deletions diktat-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.cqfn.diktat.common.config.reader

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KLogger
import mu.KotlinLogging
import org.slf4j.Logger

import java.io.BufferedReader
import java.io.IOException
Expand Down Expand Up @@ -61,6 +61,6 @@ abstract class JsonResourceConfigReader<T> {
/**
* A [Logger] that can be used
*/
val log: Logger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
val log: KLogger = KotlinLogging.loggerWithKtlintConfig(JsonResourceConfigReader::class)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import org.cqfn.diktat.common.utils.loggerWithKtlintConfig

import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import mu.KLogger
import mu.KotlinLogging
import org.slf4j.Logger

import java.io.BufferedReader
import java.io.File
Expand Down Expand Up @@ -111,7 +111,7 @@ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResour
/**
* A [Logger] that can be used
*/
val log: Logger = KotlinLogging.loggerWithKtlintConfig(RulesConfigReader::class)
val log: KLogger = KotlinLogging.loggerWithKtlintConfig(RulesConfigReader::class)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package org.cqfn.diktat.common.utils

import com.pinterest.ktlint.core.initKtLintKLogger
import mu.KotlinLogging
import org.slf4j.LoggerFactory
import kotlin.reflect.KClass

/**
Expand All @@ -25,4 +24,4 @@ fun KotlinLogging.loggerWithKtlintConfig(func: () -> Unit) =
* @return a logger
*/
fun KotlinLogging.loggerWithKtlintConfig(clazz: KClass<*>) =
logger(LoggerFactory.getLogger(clazz.java)).initKtLintKLogger()
logger(clazz.java.name).initKtLintKLogger()
14 changes: 0 additions & 14 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@
<groupId>io.github.microutils</groupId>
<artifactId>kotlin-logging-jvm</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.cqfn.diktat.ruleset.utils.*

import com.pinterest.ktlint.core.ast.ElementType
import com.pinterest.ktlint.core.ast.ElementType.CALL_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.DOT_QUALIFIED_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.FUNCTION_LITERAL
import com.pinterest.ktlint.core.ast.ElementType.IDENTIFIER
import com.pinterest.ktlint.core.ast.ElementType.LAMBDA_EXPRESSION
Expand Down Expand Up @@ -46,7 +47,10 @@ class EmptyBlock(configRules: List<RulesConfig>) : DiktatRule(

@Suppress("UnsafeCallOnNullableType", "TOO_LONG_FUNCTION")
private fun checkEmptyBlock(node: ASTNode, configuration: EmptyBlockStyleConfiguration) {
if (node.treeParent.isOverridden() || isAnonymousSamClass(node) || isLambdaUsedAsFunction(node)) {
if (node.treeParent.isOverridden() ||
isAnonymousSamClass(node) ||
Fixed Show fixed Hide fixed
isLambdaUsedAsFunction(node) ||
Fixed Show fixed Hide fixed
isKotlinLogging(node)) {
Fixed Show fixed Hide fixed
return
}
if (node.isBlockEmpty()) {
Expand Down Expand Up @@ -118,6 +122,13 @@ class EmptyBlock(configRules: List<RulesConfig>) : DiktatRule(
}
}

private fun isKotlinLogging(node: ASTNode): Boolean = node.findParentNodeWithSpecificType(DOT_QUALIFIED_EXPRESSION)
?.text
?.replace(" ", "")
.let {
it == "KotlinLogging.logger{}"
}

/**
* [RuleConfiguration] for empty blocks formatting
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.pinterest.ktlint.core.RuleSetProvider
import mu.KotlinLogging
import org.intellij.lang.annotations.Language

@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}

@Suppress("TYPE_ALIAS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import mu.KotlinLogging

import java.util.Locale

@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val log = KotlinLogging.loggerWithKtlintConfig {}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,19 @@ class EmptyBlockWarnTest : LintTestBase(::EmptyBlock) {
rulesConfigList = rulesConfigListEmptyBlockExist
)
}

@Test
@Tag(WarningNames.EMPTY_BLOCK_STRUCTURE_ERROR)
fun `should not trigger on KotlinLogging logger`() {
lintMethod(
"""
|import mu.KotlinLogging
|
|fun some() {
| val log = KotlinLogging.logger {}
| log.info { "test" }
|}
""".trimMargin(),
)
}
}
10 changes: 0 additions & 10 deletions diktat-ruleset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@
<artifactId>kotlin-compiler-embeddable</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
8 changes: 0 additions & 8 deletions diktat-test-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package org.cqfn.diktat.test.framework.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;

public class StreamGobbler extends Thread {
private static final Logger log = LoggerFactory.getLogger(StreamGobbler.class);
private final InputStream inputStream;
private final String streamType;
private final BiConsumer<Exception, String> exceptionHandler;
private final ArrayList<String> result;
private volatile boolean isStopped = false;

/**
* @param inputStream the InputStream to be consumed
* @param streamType the stream type (should be OUTPUT or ERROR)
* @param streamType the stream type (should be OUTPUT or ERROR)
* @param exceptionHandler the exception handler
*/
public StreamGobbler(final InputStream inputStream, final String streamType) {
public StreamGobbler(
final InputStream inputStream,
final String streamType,
final BiConsumer<Exception, String> exceptionHandler
) {
this.inputStream = inputStream;
this.streamType = streamType;
this.exceptionHandler = exceptionHandler;
this.result = new ArrayList<>();
}

Expand All @@ -43,7 +47,7 @@ synchronized public void run() {
this.result.add(line);
}
} catch (IOException ex) {
log.error("Failed to consume and display the input stream of type " + streamType + ".", ex);
exceptionHandler.accept(ex, "Failed to consume and display the input stream of type " + streamType + ".");
} finally {
this.isStopped = true;
notify();
Expand All @@ -55,7 +59,7 @@ synchronized public List<String> getContent() {
try {
wait();
} catch (InterruptedException e) {
log.error("Cannot get content of output stream", e);
exceptionHandler.accept(e, "Cannot get content of output stream");
}
}
return this.result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cqfn.diktat.test.framework.common

import org.slf4j.LoggerFactory
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KotlinLogging

import java.io.IOException

Expand All @@ -15,14 +16,18 @@ class LocalCommandExecutor internal constructor(private val command: String) {
*/
fun executeCommand(): ExecutionResult {
try {
log.info("Executing command: {}", command)
log.info { "Executing command: $command" }
val process = Runtime.getRuntime().exec(command)
process.outputStream.close()
val inputStream = process.inputStream
val outputGobbler = StreamGobbler(inputStream, "OUTPUT")
val outputGobbler = StreamGobbler(inputStream, "OUTPUT") { msg, ex ->
log.error(ex, msg)
}
outputGobbler.start()
val errorStream = process.errorStream
val errorGobbler = StreamGobbler(errorStream, "ERROR")
val errorGobbler = StreamGobbler(errorStream, "ERROR") { msg, ex ->
log.error(ex, msg)
}
errorGobbler.start()
return ExecutionResult(outputGobbler.content, errorGobbler.content)
} catch (ex: IOException) {
Expand All @@ -32,6 +37,6 @@ class LocalCommandExecutor internal constructor(private val command: String) {
}

companion object {
private val log = LoggerFactory.getLogger(LocalCommandExecutor::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig {}
Fixed Show fixed Hide fixed
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package org.cqfn.diktat.test.framework.config

import org.cqfn.diktat.common.cli.CliArgument
import org.cqfn.diktat.common.config.reader.JsonResourceConfigReader
import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KotlinLogging

import org.apache.commons.cli.CommandLine
import org.apache.commons.cli.CommandLineParser
import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Options
import org.apache.commons.cli.ParseException
import org.slf4j.LoggerFactory

import java.io.BufferedReader
import java.io.IOException
Expand Down Expand Up @@ -94,6 +95,6 @@ class TestArgumentsReader(
}

companion object {
private val log = LoggerFactory.getLogger(TestArgumentsReader::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig {}
Fixed Show fixed Hide fixed
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.cqfn.diktat.test.framework.processing

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import io.github.petertrr.diffutils.diff
import io.github.petertrr.diffutils.patch.ChangeDelta
import io.github.petertrr.diffutils.text.DiffRowGenerator
import org.slf4j.LoggerFactory
import mu.KotlinLogging

import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -96,7 +97,7 @@ class FileComparator(
}

companion object {
private val log = LoggerFactory.getLogger(FileComparator::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig {}
Fixed Show fixed Hide fixed

/**
* @param file file where to write these list to, separated with newlines.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.cqfn.diktat.test.framework.processing

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import org.cqfn.diktat.test.framework.config.TestConfig
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import mu.KLogger
import mu.KotlinLogging

/**
* [TestCompare] that uses stderr as tests output stream
*/
class TestCheckWarn : TestCompare() {
@Suppress("MISSING_KDOC_CLASS_ELEMENTS") override val log: Logger = LoggerFactory.getLogger(TestCheckWarn::class.java)
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR", "MISSING_KDOC_CLASS_ELEMENTS")
override val log: KLogger = KotlinLogging.loggerWithKtlintConfig {}

@Suppress(
"UnusedPrivateMember",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.cqfn.diktat.test.framework.processing

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import org.cqfn.diktat.common.utils.loggerWithKtlintConfig
import mu.KotlinLogging
import java.io.IOException
import java.nio.file.Path
import java.nio.file.Paths
Expand Down Expand Up @@ -115,7 +114,7 @@ class TestComparatorUnit(
}

private companion object {
private val log: Logger = LoggerFactory.getLogger(TestComparatorUnit::class.java)
private val log = KotlinLogging.loggerWithKtlintConfig {}
Fixed Show fixed Hide fixed

/**
* @param file the file whose content is to be read.
Expand Down
Loading