1 /*
2 * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5 package kotlinx.atomicfu.gradle.plugin.test.framework.runner
6
7 import java.io.File
8
buildGradleByShellnull9 internal fun GradleBuild.buildGradleByShell(
10 runIndex: Int,
11 commands: List<String>,
12 properties: List<String>
13 ): BuildResult {
14 val logFile = targetDir.resolve("build-$runIndex.log")
15
16 val gradleCommands = buildSystemCommand(targetDir, commands, properties)
17
18 val builder = ProcessBuilder(gradleCommands)
19 builder.directory(gradleWrapperDir)
20 builder.redirectErrorStream(true)
21 builder.redirectOutput(logFile)
22 val process = builder.start()
23 val exitCode = process.waitFor()
24 return BuildResult(exitCode, logFile)
25 }
26
buildSystemCommandnull27 private fun buildSystemCommand(projectDir: File, commands: List<String>, properties: List<String>): List<String> {
28 return if (isWindows)
29 listOf("cmd", "/C", "gradlew.bat", "-p", projectDir.canonicalPath) + commands + properties
30 else
31 listOf("/bin/bash", "gradlew", "-p", projectDir.canonicalPath) + commands + properties
32 }
33
34 private val isWindows: Boolean = System.getProperty("os.name")!!.contains("Windows")
35