From d9b06b81ae26236aca9e914930efaef322e331e4 Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Wed, 6 Jul 2022 12:33:38 +0300 Subject: [PATCH] gradle-plugin: fix docs and tests for Groovy DSL ### What's done: * Update build.gradle in examples * Add test for Groovy DSL with explicit inputs * Minor cleanup in gradle-plugin's docs --- diktat-gradle-plugin/build.gradle.kts | 9 +++---- .../DiktatGradlePluginGroovyFunctionalTest.kt | 24 ++++++++++++++----- .../org/cqfn/diktat/plugin/gradle/Utils.kt | 12 ++++++++++ .../diktat/plugin/gradle/DiktatExtension.kt | 3 +-- examples/gradle-groovy-dsl/build.gradle | 3 ++- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/diktat-gradle-plugin/build.gradle.kts b/diktat-gradle-plugin/build.gradle.kts index 218b9abf72..f45b6b7012 100644 --- a/diktat-gradle-plugin/build.gradle.kts +++ b/diktat-gradle-plugin/build.gradle.kts @@ -27,8 +27,9 @@ repositories { } // default value is needed for correct gradle loading in IDEA; actual value from maven is used during build -val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.43.0") as String -val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.1.0" +// To debug gradle plugin, please set `diktatVersion` manually to the current maven project version. +val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.46.1") as String +val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.2.1" val junitVersion = project.properties.getOrDefault("junitVersion", "5.8.1") as String val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.7") as String dependencies { @@ -107,7 +108,7 @@ val functionalTest = sourceSets.create("functionalTest") { runtimeClasspath += output + compileClasspath } tasks.getByName("functionalTest") { - dependsOn("test") + shouldRunAfter("test") testClassesDirs = functionalTest.output.classesDirs classpath = functionalTest.runtimeClasspath maxParallelForks = Runtime.getRuntime().availableProcessors() @@ -131,7 +132,7 @@ jacocoTestKit { applyTo("functionalTestRuntimeOnly", tasks.named("functionalTest")) } tasks.jacocoTestReport { - dependsOn(tasks.withType()) + shouldRunAfter(tasks.withType()) executionData( fileTree("$buildDir/jacoco").apply { include("*.exec") diff --git a/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginGroovyFunctionalTest.kt b/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginGroovyFunctionalTest.kt index 27200776e0..d883729d26 100644 --- a/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginGroovyFunctionalTest.kt +++ b/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/DiktatGradlePluginGroovyFunctionalTest.kt @@ -27,14 +27,26 @@ class DiktatGradlePluginGroovyFunctionalTest { } @Test - fun `should execute diktatCheck on default values`() { + fun `should execute diktatCheck with default values`() { val result = runDiktat(testProjectDir, shouldSucceed = false) - val diktatCheckBuildResult = result.task(":${DiktatGradlePlugin.DIKTAT_CHECK_TASK}") - requireNotNull(diktatCheckBuildResult) - Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome) - Assertions.assertTrue( - result.output.contains("[FILE_NAME_MATCH_CLASS]") + assertDiktatExecuted(result) + } + + @Test + fun `should execute diktatCheck with explicit configuration`() { + buildFile.appendText( + """${System.lineSeparator()} + diktat { + inputs { it.include("src/**/*.kt") } + reporter = "plain" + diktatConfigFile = file(rootDir.path + "/diktat-analysis.yml") + } + """.trimIndent() ) + + val result = runDiktat(testProjectDir, shouldSucceed = false) + + assertDiktatExecuted(result) } } diff --git a/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt b/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt index 246c54f705..4a0d552e28 100644 --- a/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt +++ b/diktat-gradle-plugin/src/functionalTest/kotlin/org/cqfn/diktat/plugin/gradle/Utils.kt @@ -2,7 +2,10 @@ package org.cqfn.diktat.plugin.gradle import org.gradle.buildinit.plugins.internal.modifiers.BuildInitDsl import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder +import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.TaskOutcome +import org.junit.jupiter.api.Assertions import java.io.File import java.util.concurrent.atomic.AtomicInteger @@ -71,3 +74,12 @@ private fun GradleRunner.withJaCoCo(number: Int) = apply { } } } + +fun assertDiktatExecuted(result: BuildResult) { + val diktatCheckBuildResult = result.task(":${DiktatGradlePlugin.DIKTAT_CHECK_TASK}") + requireNotNull(diktatCheckBuildResult) + Assertions.assertEquals(TaskOutcome.FAILED, diktatCheckBuildResult.outcome) + Assertions.assertTrue( + result.output.contains("[FILE_NAME_MATCH_CLASS]") + ) +} diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatExtension.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatExtension.kt index 48595df852..f2d4c5e1c9 100644 --- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatExtension.kt +++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatExtension.kt @@ -34,8 +34,7 @@ open class DiktatExtension( var reporter: String = "plain" /** - * Type of output - * Default: System.out + * Destination for reporter. If empty, will write to stdout. */ var output: String = "" diff --git a/examples/gradle-groovy-dsl/build.gradle b/examples/gradle-groovy-dsl/build.gradle index b471212824..034bb0c144 100644 --- a/examples/gradle-groovy-dsl/build.gradle +++ b/examples/gradle-groovy-dsl/build.gradle @@ -7,5 +7,6 @@ repositories { } diktat { - inputs { include ("src/**/*.kt") } + inputs { it.include ("src/**/*.kt") } + diktatConfigFile = file(rootDir.path + "/diktat-analysis.yml") }