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

gradle-plugin: fix behavior in githubActions mode #1229

Merged
merged 3 commits into from
Mar 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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 -> ""
}
Expand All @@ -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())
Copy link
Member

Choose a reason for hiding this comment

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

in maven plugin this works fine?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this change doesn't affect maven plugin

reporterFlag = "--reporter=sarif"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down