Skip to content

Commit 95e5a69

Browse files
michaelbelclaude
andcommitted
chore: simplify versionCode git process builder in all modules
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 110d329 commit 95e5a69

5 files changed

Lines changed: 15 additions & 60 deletions

File tree

auto/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.FileInputStream
2-
import java.nio.charset.StandardCharsets
32
import java.util.Properties
43

54
plugins {
@@ -9,17 +8,9 @@ plugins {
98
}
109

1110
private val gitCommitsCount: Int by lazy {
12-
try {
13-
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true)
14-
val processBuilder = when {
15-
isWindows -> ProcessBuilder("cmd", "/c", "git", "rev-list", "--count", "HEAD")
16-
else -> ProcessBuilder("git", "rev-list", "--count", "HEAD")
17-
}
18-
processBuilder.redirectErrorStream(true)
19-
processBuilder.start().inputStream.bufferedReader(StandardCharsets.UTF_8).readLine().trim().toInt()
20-
} catch (_: Exception) {
21-
1
22-
}
11+
ProcessBuilder("git", "rev-list", "--count", "HEAD")
12+
.redirectErrorStream(true)
13+
.start().inputStream.bufferedReader().readLine().trim().toInt()
2314
}
2415

2516
kotlin {

mobile/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.FileInputStream
2-
import java.nio.charset.StandardCharsets
32
import java.util.Properties
43

54
plugins {
@@ -10,17 +9,9 @@ plugins {
109
}
1110

1211
private val gitCommitsCount: Int by lazy {
13-
try {
14-
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true)
15-
val processBuilder = when {
16-
isWindows -> ProcessBuilder("cmd", "/c", "git", "rev-list", "--count", "HEAD")
17-
else -> ProcessBuilder("git", "rev-list", "--count", "HEAD")
18-
}
19-
processBuilder.redirectErrorStream(true)
20-
processBuilder.start().inputStream.bufferedReader(StandardCharsets.UTF_8).readLine().trim().toInt()
21-
} catch (_: Exception) {
22-
1
23-
}
12+
ProcessBuilder("git", "rev-list", "--count", "HEAD")
13+
.redirectErrorStream(true)
14+
.start().inputStream.bufferedReader().readLine().trim().toInt()
2415
}
2516

2617
kotlin {

tv/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.FileInputStream
2-
import java.nio.charset.StandardCharsets
32
import java.util.Properties
43

54
plugins {
@@ -9,17 +8,9 @@ plugins {
98
}
109

1110
private val gitCommitsCount: Int by lazy {
12-
try {
13-
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true)
14-
val processBuilder = when {
15-
isWindows -> ProcessBuilder("cmd", "/c", "git", "rev-list", "--count", "HEAD")
16-
else -> ProcessBuilder("git", "rev-list", "--count", "HEAD")
17-
}
18-
processBuilder.redirectErrorStream(true)
19-
processBuilder.start().inputStream.bufferedReader(StandardCharsets.UTF_8).readLine().trim().toInt()
20-
} catch (_: Exception) {
21-
1
22-
}
11+
ProcessBuilder("git", "rev-list", "--count", "HEAD")
12+
.redirectErrorStream(true)
13+
.start().inputStream.bufferedReader().readLine().trim().toInt()
2314
}
2415

2516
kotlin {

wear/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.FileInputStream
2-
import java.nio.charset.StandardCharsets
32
import java.util.Properties
43

54
plugins {
@@ -9,17 +8,9 @@ plugins {
98
}
109

1110
private val gitCommitsCount: Int by lazy {
12-
try {
13-
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true)
14-
val processBuilder = when {
15-
isWindows -> ProcessBuilder("cmd", "/c", "git", "rev-list", "--count", "HEAD")
16-
else -> ProcessBuilder("git", "rev-list", "--count", "HEAD")
17-
}
18-
processBuilder.redirectErrorStream(true)
19-
processBuilder.start().inputStream.bufferedReader(StandardCharsets.UTF_8).readLine().trim().toInt()
20-
} catch (_: Exception) {
21-
1
22-
}
11+
ProcessBuilder("git", "rev-list", "--count", "HEAD")
12+
.redirectErrorStream(true)
13+
.start().inputStream.bufferedReader().readLine().trim().toInt()
2314
}
2415

2516
kotlin {

xr/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import java.io.FileInputStream
2-
import java.nio.charset.StandardCharsets
32
import java.util.Properties
43

54
plugins {
@@ -9,17 +8,9 @@ plugins {
98
}
109

1110
private val gitCommitsCount: Int by lazy {
12-
try {
13-
val isWindows = System.getProperty("os.name").contains("Windows", ignoreCase = true)
14-
val processBuilder = when {
15-
isWindows -> ProcessBuilder("cmd", "/c", "git", "rev-list", "--count", "HEAD")
16-
else -> ProcessBuilder("git", "rev-list", "--count", "HEAD")
17-
}
18-
processBuilder.redirectErrorStream(true)
19-
processBuilder.start().inputStream.bufferedReader(StandardCharsets.UTF_8).readLine().trim().toInt()
20-
} catch (_: Exception) {
21-
1
22-
}
11+
ProcessBuilder("git", "rev-list", "--count", "HEAD")
12+
.redirectErrorStream(true)
13+
.start().inputStream.bufferedReader().readLine().trim().toInt()
2314
}
2415

2516
kotlin {

0 commit comments

Comments
 (0)