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

dagger.hilt.android.plugin.util.SimpleAGPVersion.kt Maven / Gradle / Ivy

There is a newer version: 2.52
Show newest version
package dagger.hilt.android.plugin.util

import com.android.Version

/**
 * Simple Android Gradle Plugin version class since there is no public API one. b/175816217
 */
internal data class SimpleAGPVersion(
  val major: Int,
  val minor: Int,
) : Comparable {

  override fun compareTo(other: SimpleAGPVersion): Int {
    return compareValuesBy(
      this,
      other,
      compareBy(SimpleAGPVersion::major).thenBy(SimpleAGPVersion::minor)
    ) { it }
  }

  companion object {

    val ANDROID_GRADLE_PLUGIN_VERSION by lazy { parse(Version.ANDROID_GRADLE_PLUGIN_VERSION) }

    fun parse(version: String?) =
      tryParse(version) ?: error("Unable to parse AGP version: $version")

    private fun tryParse(version: String?): SimpleAGPVersion? {
      if (version == null) {
        return null
      }

      val parts = version.split('.')
      if (parts.size == 1) {
        return SimpleAGPVersion(parts[0].toInt(), 0)
      }

      return SimpleAGPVersion(parts[0].toInt(), parts[1].toInt())
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy