@@ -3,22 +3,24 @@ plugins {
33 id(" org.jetbrains.kotlin.android" )
44}
55
6- fun getCommitCount (): Int {
7- val stdout = org.apache.commons.io.output.ByteArrayOutputStream ()
8- project.exec {
9- commandLine = " git rev-list --count HEAD" .split(" " )
10- standardOutput = stdout
11- }
12- return Integer .parseInt(String (stdout.toByteArray()).trim())
6+ fun execCommand (command : String ): String? {
7+ val cmd = command.split(" " ).toTypedArray()
8+ val process = ProcessBuilder (* cmd)
9+ .redirectOutput(ProcessBuilder .Redirect .PIPE )
10+ .start()
11+ return process.inputStream.bufferedReader().readLine()?.trim()
1312}
1413
15- fun getCommitHash (): String {
16- val stdout = org.apache.commons.io.output.ByteArrayOutputStream ()
17- project.exec {
18- commandLine = " git rev-parse --short HEAD" .split(" " )
19- standardOutput = stdout
20- }
21- return String (stdout.toByteArray()).trim()
14+ val commitCount by project.extra {
15+ execCommand(" git rev-list --count HEAD" )?.toInt()
16+ ? : throw GradleException (" Unable to get number of commits. Make sure git is initialized." )
17+ }
18+
19+ val commitHash by project.extra {
20+ execCommand(" git rev-parse --short HEAD" )
21+ ? : throw GradleException (
22+ " Unable to get commit hash. Make sure git is initialized."
23+ )
2224}
2325
2426android {
@@ -29,8 +31,8 @@ android {
2931 applicationId = " it.leddaz.revancedupdater"
3032 minSdk = 26
3133 targetSdk = 35
32- versionCode = getCommitCount()
33- versionName = " 3.6.0 (" + getCommitHash() + " )"
34+ versionCode = commitCount
35+ versionName = " 3.6.0 ($commitHash )"
3436 }
3537
3638 buildTypes {
0 commit comments