All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.karte.android.gradleplugin.AGPVersion.kt Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package io.karte.android.gradleplugin

data class AGPVersion(
    val major: Int,
    val minor: Int,
    val patch: Int
) : Comparable {

    override fun compareTo(other: AGPVersion): Int {
        if (this.major < other.major) {
            return -1
        } else if (this.major > other.major) {
            return 1
        }
        if (this.minor < other.minor) {
            return -1
        } else if (this.minor > other.minor) {
            return 1
        }
        if (this.patch < other.patch) {
            return -1
        } else if (this.patch > other.patch) {
            return 1
        }
        return 0
    }

    companion object {
        val VERSION_7_0_0 = AGPVersion(7, 0, 0)

        private val versionPattern = Regex(
            """(0|[1-9]\d*)?(?:\.)?(0|[1-9]\d*)?(?:\.)?(0|[1-9]\d*)?(?:-([\dA-z\-]+(?:\.[\dA-z\-]+)*))?(?:\+([\dA-z\-]+(?:\.[\dA-z\-]+)*))?"""
        )

        fun fromVersionString(version: String): AGPVersion {
            val result = versionPattern.matchEntire(version) ?: throw IllegalArgumentException("Invalid version string: $version")
            val values = result.groupValues
            return AGPVersion(
                values[1].toIntOrNull() ?: 0,
                values[2].toIntOrNull() ?: 0,
                values[3].toIntOrNull() ?: 0
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy