Skip to content

Commit

Permalink
Allow to setupe gradle properties
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Mar 8, 2024
1 parent 239ca84 commit 107ff27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Expand Up @@ -45,22 +45,25 @@ class DetektReportMergeSpec {
)
}

val gradleRunner = DslGradleRunner(projectLayout, builder.gradleBuildName, buildFileContent)
val gradleRunner = DslGradleRunner(
projectLayout,
builder.gradleBuildName,
buildFileContent,
gradleProperties = mapOf("detekt.use.worker.api" to "false"),
)
gradleRunner.setupProject()
gradleRunner.runTasksAndExpectFailure("detekt", "sarifReportMerge", "--continue") { result ->
assertThat(result.output).contains("FAILURE: Build completed with 2 failures.")
assertThat(result.output).containsIgnoringWhitespaces(
"""
Execution failed for task ':child1:detekt'.
> A failure occurred while executing io.gitlab.arturbosch.detekt.invoke.DetektWorkAction
> Analysis failed with 2 issues.
> Analysis failed with 2 issues.
""".trimIndent()
)
assertThat(result.output).containsIgnoringWhitespaces(
"""
Execution failed for task ':child2:detekt'.
> A failure occurred while executing io.gitlab.arturbosch.detekt.invoke.DetektWorkAction
> Analysis failed with 4 issues.
> Analysis failed with 4 issues.
""".trimIndent()
)
assertThat(projectFile("build/reports/detekt/detekt.sarif")).doesNotExist()
Expand Down Expand Up @@ -110,22 +113,25 @@ class DetektReportMergeSpec {
)
}

val gradleRunner = DslGradleRunner(projectLayout, builder.gradleBuildName, buildFileContent)
val gradleRunner = DslGradleRunner(
projectLayout,
builder.gradleBuildName,
buildFileContent,
gradleProperties = mapOf("detekt.use.worker.api" to "false"),
)
gradleRunner.setupProject()
gradleRunner.runTasksAndExpectFailure("detekt", "xmlReportMerge", "--continue") { result ->
assertThat(result.output).contains("FAILURE: Build completed with 2 failures.")
assertThat(result.output).containsIgnoringWhitespaces(
"""
Execution failed for task ':child1:detekt'.
> A failure occurred while executing io.gitlab.arturbosch.detekt.invoke.DetektWorkAction
> Analysis failed with 2 issues.
> Analysis failed with 2 issues.
""".trimIndent()
)
assertThat(result.output).containsIgnoringWhitespaces(
"""
Execution failed for task ':child2:detekt'.
> A failure occurred while executing io.gitlab.arturbosch.detekt.invoke.DetektWorkAction
> Analysis failed with 4 issues.
> Analysis failed with 4 issues.
""".trimIndent()
)
assertThat(projectFile("build/reports/detekt/detekt.xml")).doesNotExist()
Expand Down
Expand Up @@ -22,6 +22,7 @@ constructor(
val gradleVersionOrNone: String? = null,
val dryRun: Boolean = false,
val jvmArgs: String = "-Xmx2g -XX:MaxMetaspaceSize=1g",
gradleProperties: Map<String, String> = emptyMap(),
val projectScript: Project.() -> Unit = {}
) {

Expand All @@ -34,6 +35,9 @@ constructor(
include(${projectLayout.submodules.joinToString(",") { "\"${it.name}\"" }})
""".trimIndent()

private val propertiesContent = gradleProperties.toList()
.joinToString(separator = "\n") { (key, value) -> "$key=$value" }

@Language("xml")
private val baselineContent = """
<some>
Expand Down Expand Up @@ -65,6 +69,7 @@ constructor(
fun setupProject() {
writeProjectFile(buildFileName, mainBuildFileContent)
writeProjectFile(SETTINGS_FILENAME, settingsContent)
writeProjectFile(PROPERTIES_FILENAME, propertiesContent)
configFileOrNone?.let { writeProjectFile(it, configFileContent) }
baselineFiles.forEach { file -> writeProjectFile(file, baselineContent) }
projectLayout.srcDirs.forEachIndexed { srcDirIdx, sourceDir ->
Expand Down Expand Up @@ -170,7 +175,8 @@ constructor(
}

companion object {
const val SETTINGS_FILENAME = "settings.gradle"
private const val SETTINGS_FILENAME = "settings.gradle"
private const val PROPERTIES_FILENAME = "gradle.properties"
private const val DETEKT_TASK = "detekt"
}
}

0 comments on commit 107ff27

Please sign in to comment.