From fc846203834b0b4bedd392ea39dd71157edeb8b6 Mon Sep 17 00:00:00 2001 From: Nariman Abdullin Date: Thu, 16 Jun 2022 12:04:53 +0300 Subject: [PATCH] Fix for NSFE when mvn test run from /diktat-rules (#1366) ### What's done: - added arguments for methods in Generation.kt --- diktat-rules/pom.xml | 4 ++++ .../diktat/ruleset/generation/Generation.kt | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/diktat-rules/pom.xml b/diktat-rules/pom.xml index d99c981099..e96be60b80 100644 --- a/diktat-rules/pom.xml +++ b/diktat-rules/pom.xml @@ -151,6 +151,10 @@ org.cqfn.diktat.ruleset.generation.GenerationKt + + ${project.build.sourceDirectory} + ${project.basedir}/src/test/resources + diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt index 7233a1e4ea..7eed5b91e0 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/generation/Generation.kt @@ -31,12 +31,15 @@ private val autoGenerationComment = | This document contains all enum properties from Warnings.kt as Strings. """.trimMargin() -fun main() { - generateWarningNames() - validateYear() +fun main(args: Array) { + require(args.size == 2) { + "Only to arguments are expected" + } + generateWarningNames(args[0]) + validateYear(args[1]) } -private fun generateWarningNames() { +private fun generateWarningNames(sourceDirectory: String) { val enumValNames = Warnings.values().map { it.name } val propertyList = enumValNames.map { @@ -59,11 +62,11 @@ private fun generateWarningNames() { .addFileComment(autoGenerationComment) .build() - kotlinFile.writeTo(Paths.get("diktat-rules/src/main/kotlin")) // fixme: need to add it to pom + kotlinFile.writeTo(Paths.get(sourceDirectory)) } -private fun validateYear() { - val folder = Paths.get("diktat-rules/src/test/resources/test/paragraph2/header") +private fun validateYear(testResourcesDirectory: String) { + val folder = Paths.get(testResourcesDirectory, "test/paragraph2/header") Files.list(folder) .filter { !it.name.contains("CopyrightDifferentYearTest.kt") } .forEach { file ->