diff --git a/detekt-config.yml b/detekt-config.yml index 0e1f5fbdb4..f75c59e824 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -810,4 +810,4 @@ style: WildcardImport: active: true excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] - excludeImports: ['org.cqfn.diktat.ruleset.utils.*', 'java.util.*', 'kotlinx.android.synthetic.*'] \ No newline at end of file + excludeImports: ['org.cqfn.diktat.ruleset.utils.*', 'java.util.*', 'kotlinx.android.synthetic.*', 'kotlinx.serialization'] \ No newline at end of file diff --git a/diktat-analysis.yml b/diktat-analysis.yml index 2184ee1949..fb7cc63766 100644 --- a/diktat-analysis.yml +++ b/diktat-analysis.yml @@ -271,7 +271,6 @@ - name: STRING_TEMPLATE_CURLY_BRACES enabled: true configuration: {} - typeReferenceLength: '25' # max length of type reference # Variables with `val` modifier - are immutable (read-only). Usage of such variables instead of `var` variables increases # robustness and readability of code, because `var` variables can be reassigned several times in the business logic. # This rule prohibits usage of `var`s as local variables - the only exception is accumulators and counters diff --git a/diktat-common/pom.xml b/diktat-common/pom.xml index 126cd2b129..1ef63e4720 100644 --- a/diktat-common/pom.xml +++ b/diktat-common/pom.xml @@ -18,24 +18,14 @@ kotlin-stdlib-jdk8 - com.fasterxml.jackson.core - jackson-core + org.jetbrains.kotlinx + kotlinx-serialization-json-jvm + ${kotlinx.serialization.version} - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.module - jackson-module-kotlin + com.charleskorn.kaml + kaml + 0.24.0 commons-cli @@ -88,6 +78,18 @@ + + + kotlinx-serialization + + + + + org.jetbrains.kotlin + kotlin-maven-serialization + ${kotlin.version} + + diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/cli/CliArgument.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/cli/CliArgument.kt index a31c2c7465..14ab36b09b 100644 --- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/cli/CliArgument.kt +++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/cli/CliArgument.kt @@ -1,27 +1,22 @@ package org.cqfn.diktat.common.cli -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.annotation.JsonProperty import org.apache.commons.cli.Option +import kotlinx.serialization.* /** * This class is used to serialize/deserialize json representation * that is used to store command line arguments */ -@JsonIgnoreProperties(ignoreUnknown = true) -class CliArgument @JsonCreator internal constructor( +@Serializable +data class CliArgument ( // short argument representation like -h - @param:JsonProperty("shortName") private val shortName: String, - @param:JsonProperty("helpDescr") private val helpDescr: String, + private val shortName: String, + private val helpDescr: String, // long argument representation like --help - @param:JsonProperty("longName") private val longName: String, + private val longName: String, // indicates if option should have explicit argument - @param:JsonProperty("hasArgs") private val hasArgs: Boolean, - @param:JsonProperty("isRequired") private val isRequired: Boolean) { - override fun toString(): String = "(shortName: " + shortName + ", helpDescr: " + helpDescr + ", longName: " + - longName + ", hasArgs: " + hasArgs + ", isRequired: " + isRequired + ")" - + private val hasArgs: Boolean, + private val isRequired: Boolean) { /** * Converts parameters received from json to [Option] * diff --git a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt index 9290cd4d4e..f648215a11 100644 --- a/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt +++ b/diktat-common/src/main/kotlin/org/cqfn/diktat/common/config/rules/RulesConfigReader.kt @@ -4,11 +4,10 @@ package org.cqfn.diktat.common.config.rules -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import com.fasterxml.jackson.module.kotlin.KotlinModule -import com.fasterxml.jackson.module.kotlin.readValue +import com.charleskorn.kaml.Yaml +import com.charleskorn.kaml.YamlConfiguration +import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString import java.io.BufferedReader import java.io.File import org.cqfn.diktat.common.config.reader.JsonResourceConfigReader @@ -30,7 +29,7 @@ interface Rule { /** * Configuration of individual [Rule] */ -@JsonIgnoreProperties(ignoreUnknown = true) +@Serializable data class RulesConfig( val name: String, val enabled: Boolean = true, @@ -47,6 +46,8 @@ object EmptyConfiguration : RuleConfiguration(mapOf()) * class returns the list of configurations that we have read from a yml: diktat-analysis.yml */ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResourceConfigReader>() { + private val yamlSerializer by lazy { Yaml(configuration = YamlConfiguration(strictMode = true)) } + /** * Parse resource file into list of [RulesConfig] * @@ -54,10 +55,8 @@ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResour * @return list of [RulesConfig] */ override fun parseResource(fileStream: BufferedReader): List { - val mapper = ObjectMapper(YAMLFactory()) - mapper.registerModule(KotlinModule()) return fileStream.use { stream -> - mapper.readValue(stream) + yamlSerializer.decodeFromString(stream.readLines().joinToString(separator = "\n")) } } @@ -87,7 +86,9 @@ open class RulesConfigReader(override val classLoader: ClassLoader) : JsonResour /** * @return common configuration from list of all rules configuration */ -fun List.getCommonConfiguration() = lazy { CommonConfiguration(getCommonConfig()?.configuration) } +fun List.getCommonConfiguration() = lazy { + CommonConfiguration(getCommonConfig()?.configuration) +} /** * class returns the list of common configurations that we have read from a configuration map diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index 20c2770099..31e11a7f20 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -128,31 +128,6 @@ org.cqfn.diktat.ruleset.generation.GenerationKt - - org.apache.maven.plugins - maven-compiler-plugin - - - test/** - - - - - compile - compile - - compile - - - - testCompile - test-compile - - testCompile - - - - diff --git a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt index aecdffa66e..704a7bab54 100644 --- a/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt +++ b/diktat-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/RulesConfigYamlTest.kt @@ -1,6 +1,7 @@ package org.cqfn.diktat.ruleset.utils -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.charleskorn.kaml.Yaml +import kotlinx.serialization.encodeToString import org.cqfn.diktat.common.config.rules.RulesConfig import org.cqfn.diktat.common.config.rules.RulesConfigReader import org.cqfn.diktat.common.config.rules.getRuleConfig @@ -35,15 +36,14 @@ class RulesConfigYamlTest { allRulesFromCode.forEach { rule -> val foundRule = allRulesFromConfig.getRuleConfig(rule) val ymlCodeSnippet = RulesConfig(rule.ruleName(), true, mapOf()) - val jacksonMapper = jacksonObjectMapper() - val ruleYaml = jacksonMapper.writeValueAsString(ymlCodeSnippet) + val ruleYaml = Yaml.default.encodeToString(ymlCodeSnippet) Assertions.assertTrue(foundRule != null) { """ Cannot find warning ${rule.ruleName()} in $filePath. You can fix it by adding the following code below to $filePath: $ruleYaml - """ + """.trimIndent() } } diff --git a/diktat-test-framework/pom.xml b/diktat-test-framework/pom.xml index 97978590e3..7840fcf3c4 100644 --- a/diktat-test-framework/pom.xml +++ b/diktat-test-framework/pom.xml @@ -22,22 +22,6 @@ org.jetbrains.kotlin kotlin-stdlib-jdk8 - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.module - jackson-module-kotlin - commons-cli commons-cli @@ -88,6 +72,9 @@ src/main/kotlin src/main/resources + + kotlinx-serialization + @@ -104,6 +91,13 @@ + + + org.jetbrains.kotlin + kotlin-maven-serialization + ${kotlin.version} + + org.apache.maven.plugins diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt index c4ead682ac..a573b5a1aa 100644 --- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt +++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestArgumentsReader.kt @@ -1,7 +1,7 @@ package org.cqfn.diktat.test.framework.config -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper -import com.fasterxml.jackson.module.kotlin.readValue +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json import java.io.BufferedReader import java.io.IOException import java.util.stream.Collectors @@ -90,7 +90,7 @@ class TestArgumentsReader( @Throws(IOException::class) override fun parseResource(fileStream: BufferedReader): List { val jsonValue = fileStream.lines().collect(Collectors.joining()) - return jacksonObjectMapper().readValue(jsonValue) + return Json.decodeFromString>(jsonValue) } companion object { diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfig.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfig.kt index 4fb098ecb3..a01765f4f2 100644 --- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfig.kt +++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfig.kt @@ -1,27 +1,26 @@ package org.cqfn.diktat.test.framework.config -import com.fasterxml.jackson.annotation.JsonCreator -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.annotation.JsonProperty +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable /** * This class is used to serialize/deserialize json representation * that is used to store command line arguments */ -@JsonIgnoreProperties(ignoreUnknown = true) +@Serializable @Suppress("ForbiddenComment") -class TestConfig @JsonCreator internal constructor( +class TestConfig internal constructor( // command line execution command, use shell like "cmd", "bash" or other - @param:JsonProperty("executionCommand") val executionCommand: String, + val executionCommand: String, // expected result file can be a full path or a relative path to a resource - @param:JsonProperty("expectedResultFile") val expectedResultFile: String, + val expectedResultFile: String, // testFile can be a full path or a relative path to a resource - @param:JsonProperty("testFile") val testFile: String, + val testFile: String, // executionType that controls processing of the test (like COMPARE, MIXED, CHECK_WARN, e.t.c) - @param:JsonProperty("executionType") val executionType: ExecutionType, - @param:JsonProperty("profile") val testProfile: TestProfile, + val executionType: ExecutionType, + @SerialName("profile") val testProfile: TestProfile, // option that controls if changes and automatic fix should be done directly in file - @param:JsonProperty("inPlace", defaultValue = "false") val inPlace: Boolean + val inPlace: Boolean = false ) { /** * test name - it is not included in config content, but is injected on runtime by setter diff --git a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfigReader.kt b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfigReader.kt index 8e5d5ed492..74deef4773 100644 --- a/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfigReader.kt +++ b/diktat-test-framework/src/main/kotlin/org/cqfn/diktat/test/framework/config/TestConfigReader.kt @@ -1,6 +1,7 @@ package org.cqfn.diktat.test.framework.config -import com.fasterxml.jackson.databind.ObjectMapper +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json import java.io.BufferedReader import java.io.IOException import java.util.stream.Collectors @@ -11,7 +12,7 @@ class TestConfigReader(configFilePath: String, override val classLoader: ClassLo @Throws(IOException::class) override fun parseResource(fileStream: BufferedReader): TestConfig { - val jsonValue = fileStream.lines().collect(Collectors.joining()) - return ObjectMapper().readValue(jsonValue, TestConfig::class.java) + val jsonValue: String = fileStream.lines().collect(Collectors.joining()) + return Json.decodeFromString(jsonValue) } } diff --git a/pom.xml b/pom.xml index 5a306a8dbc..0f6978379c 100644 --- a/pom.xml +++ b/pom.xml @@ -44,10 +44,10 @@ UTF-8 1.4.10 true + 1.0.0 0.39.0 5.7.0 29.0-jre - 2.11.3 1.7.30 1.4 0.1.2 @@ -85,7 +85,7 @@ ${kotlin.version} - + org.jetbrains.kotlin kotlin-reflect ${kotlin.version} @@ -105,31 +105,6 @@ guava ${guava.version} - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.module - jackson-module-kotlin - ${jackson.version} - commons-cli commons-cli