-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.gradle.kts
74 lines (71 loc) · 2.27 KB
/
ci.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import org.apache.tools.ant.taskdefs.condition.Os
import java.util.Properties
tasks.register("codeFormatAndCheck") {
doLast {
gradlew(
"clean",
"ktlintFormat",
"lintFix",
"ktlintCheck",
"lint",
"detekt"
)
}
}
tasks.register("allTest") {
doLast {
gradlew(
"clean",
"testDebugUnitTest",
"connectedAndroidTest"
)
}
}
fun gradlew(
vararg tasks: String,
addToSystemProperties: Map<String, String>? = null,
) {
exec {
executable = File(
project.rootDir,
if (Os.isFamily(Os.FAMILY_WINDOWS)) "gradlew.bat" else "gradlew"
)
.also { it.setExecutable(true) }
.absolutePath
args = mutableListOf<String>().also { mutableArgs ->
mutableArgs.addAll(tasks)
addToSystemProperties?.toList()?.map { "-D${it.first}=${it.second}" }?.let {
mutableArgs.addAll(it)
}
mutableArgs.add("--stacktrace")
}
val sdkDirPath = Properties().apply {
val propertiesFile = File(rootDir, "local.properties")
if (propertiesFile.exists()) {
load(propertiesFile.inputStream())
}
}.getProperty("sdk.dir")
if (sdkDirPath != null) {
val platformToolsDir = "$sdkDirPath${java.io.File.separator}platform-tools"
val pahtEnvironment = System.getenv("PATH").orEmpty()
if (!pahtEnvironment.contains(platformToolsDir)) {
environment = environment.toMutableMap().apply {
put("PATH", "$platformToolsDir:$pahtEnvironment")
}
}
}
if (System.getenv("JAVA_HOME") == null) {
System.getProperty("java.home")?.let { javaHome ->
environment = environment.toMutableMap().apply {
put("JAVA_HOME", javaHome)
}
}
}
if (System.getenv("ANDROID_HOME") == null) {
environment = environment.toMutableMap().apply {
put("ANDROID_HOME", "$sdkDirPath")
}
}
println("commandLine: ${this.commandLine}")
}.apply { println("ExecResult: $this") }
}