diff --git a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt index 0c21a4d566..249936dfc4 100644 --- a/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt +++ b/diktat-gradle-plugin/src/main/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskBase.kt @@ -27,6 +27,8 @@ import org.gradle.api.tasks.util.PatternSet import org.gradle.util.GradleVersion import java.io.File +import java.nio.file.Files +import java.nio.file.Paths import javax.inject.Inject /** @@ -162,7 +164,11 @@ open class DiktatJavaExecTaskBase @Inject constructor( val outFlag = when { // githubActions should have higher priority than a custom input - diktatExtension.githubActions -> ",output=${project.projectDir}/${project.name}" + diktatExtension.githubActions -> { + val reportDir = Files.createDirectories(Paths.get("${project.buildDir}/reports/diktat")) + outputs.dir(reportDir) + ",output=${reportDir.resolve("diktat.sarif")}" + } diktatExtension.output.isNotEmpty() -> ",output=${diktatExtension.output}" else -> "" } @@ -186,7 +192,7 @@ open class DiktatJavaExecTaskBase @Inject constructor( // githubActions should have higher priority than a custom input if (diktatExtension.githubActions) { // need to set user.home specially for ktlint, so it will be able to put a relative path URI in SARIF - System.setProperty("user.home", project.projectDir.toString()) + systemProperty("user.home", project.projectDir.toString()) reporterFlag = "--reporter=sarif" } diff --git a/diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt b/diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt index 146c4d68e7..1d6069d870 100644 --- a/diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt +++ b/diktat-gradle-plugin/src/test/kotlin/org/cqfn/diktat/plugin/gradle/DiktatJavaExecTaskTest.kt @@ -110,6 +110,32 @@ class DiktatJavaExecTaskTest { } } + @Test + fun `check command line in githubActions mode`() { + val path = project.file("${project.buildDir}/reports/diktat/diktat.sarif") + assertCommandLineEquals( + listOf(null, "--reporter=sarif,output=$path") + ) { + inputs { exclude("*") } + diktatConfigFile = project.file("../diktat-analysis.yml") + githubActions = true + } + } + + @Test + fun `githubActions mode should have higher precedence over explicit reporter`() { + val path = project.file("${project.buildDir}/reports/diktat/diktat.sarif") + assertCommandLineEquals( + listOf(null, "--reporter=sarif,output=$path") + ) { + inputs { exclude("*") } + diktatConfigFile = project.file("../diktat-analysis.yml") + githubActions = true + reporter = "json" + output = "report.json" + } + } + @Test fun `check system property with multiproject build with default config`() { setupMultiProject()