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

Fix for NSFE when mvn test run from /diktat-rules #1366

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
</executions>
<configuration>
<mainClass>org.cqfn.diktat.ruleset.generation.GenerationKt</mainClass>
<arguments>
<argument>${project.build.sourceDirectory}</argument>
<argument>${project.basedir}/src/test/resources</argument>
</arguments>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
require(args.size == 2) {
"Only to arguments are expected"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Only to arguments are expected"
"Only two arguments are expected: <source root> <test resource root>"

Maybe something like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap, fixed in #1367

}
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 {
Expand All @@ -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 ->
Expand Down