Repository: analysis-dev/diktat (kotlin)

Issue:
gradle-plugin: problems with the new `githubActions` mode
## Expected behavior
SARIF report can be identified by `.sarif` extension

## Observed behavior
https://github.com/analysis-dev/diktat/commit/0698727bcf762ce7a765098dcf36be5cebcca6a1#diff-52618882223ec0dcf8f8568e2158fd7d1f83502da075d9658d3b5e24d92f7d0fR162
SARIF report has the same name, as the project. It makes it really hard to automatically discover these reports.

## Environment information
* diktat version: 1.0.3
* build tool (maven/gradle): gradle

Pull request:
### What's done:
* Correctly set system property
* Rename report; store reports in build directory

This pull request closes #1213

Patch:
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"
         }
 


Test patch:
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()