Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6e5fee8 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊 Committed by Nishith Khanna
Browse files

mail: add incrementing versionCode and versionName

parent 5bc6920c
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,8 @@ out/
*.jks
*.jks
*.keystore
*.keystore


*/version.properties

# Signing files
# Signing files
.signing/
.signing/
*.signing.properties
*.signing.properties
+68 −2
Original line number Original line Diff line number Diff line
import java.io.FileInputStream
import java.util.Properties
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
import javax.xml.xpath.XPathFactory
@@ -13,15 +15,79 @@ if (testCoverageEnabled) {
    apply(plugin = "jacoco")
    apply(plugin = "jacoco")
}
}


val appMajor = "9"
val appMinor = "0"
val appPatch = "0"
val appVersionCode = 9

android {
android {
    namespace = "net.thunderbird.android"
    namespace = "net.thunderbird.android"


    val versionPropsFile = file("version.properties")
    val versionProps = Properties()

    if (!versionPropsFile.exists()) {
        versionProps["VERSION_CHANGE"] = "0"
        versionProps["VERSION_MAJOR"] = appMajor
        versionProps["VERSION_MINOR"] = appMinor
        versionProps["VERSION_PATCH"] = appPatch
        versionProps["VERSION_CODE"] = appVersionCode.toString()
        versionProps.store(versionPropsFile.writer(), null)
    }

    fun getVersionCode(): Int {
        if (versionPropsFile.canRead()) {
            versionProps.load(FileInputStream(versionPropsFile))
            var versionChange = Integer.valueOf(versionProps["VERSION_CHANGE"].toString()) + 1
            var versionMinor = Integer.valueOf(versionProps["VERSION_MINOR"].toString())
            var versionMajor = Integer.valueOf(versionProps["VERSION_MAJOR"].toString())
            var versionPatch = Integer.valueOf(versionProps["VERSION_PATCH"].toString())
            // Up version on each 100 cycles of builds
            if (versionChange >= 100) {
                versionPatch += 1
                versionChange = 0
            }
            if (versionPatch == 9) {
                versionMinor = versionPatch + 1
                versionPatch = 0
            }
            if (versionMinor == 9) {
                versionMajor += 1
                versionMinor = 0
            }
            val versionCode = Integer.valueOf(versionProps["VERSION_CODE"].toString())

            versionProps["VERSION_CHANGE"] = versionChange.toString()
            versionProps["VERSION_PATCH"] = versionPatch.toString()
            versionProps["VERSION_MINOR"] = versionMinor.toString()
            versionProps["VERSION_MAJOR"] = versionMajor.toString()
            versionProps["VERSION_CODE"] = (Integer.valueOf(versionCode) + 1).toString()
            versionProps.store(versionPropsFile.writer(), null)

            return versionCode
        }
        return appVersionCode
    }

    fun getVersionName(): String {
        if (versionPropsFile.canRead()) {
            versionProps.load(FileInputStream(versionPropsFile))

            val versionMajor = versionProps["VERSION_MAJOR"]
            val versionMinor = versionProps["VERSION_MINOR"]
            val versionPatch = versionProps["VERSION_PATCH"]

            return "${versionMajor}.${versionMinor}.${versionPatch}"
        }
        return "$appMajor.$appMinor.$appPatch"
    }

    defaultConfig {
    defaultConfig {
        applicationId = "foundation.e.mail"
        applicationId = "foundation.e.mail"
        testApplicationId = "foundation.e.mail.tests"
        testApplicationId = "foundation.e.mail.tests"


        versionCode = 9
        versionCode = getVersionCode()
        versionName = "10.0"
        versionName = getVersionName()


        // Keep in sync with the resource string array "supported_languages"
        // Keep in sync with the resource string array "supported_languages"
        resourceConfigurations.addAll(
        resourceConfigurations.addAll(