diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9fb2544a..7b463016 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,7 +15,7 @@ android { applicationId = "org.jellyfin.mobile" minSdkVersion(21) targetSdkVersion(30) - versionName = "2.0.0-rc2" + versionName = "2.0.0-rc.2" versionCode = getVersionCode(versionName) setProperty("archivesBaseName", "jellyfin-android-v$versionName") testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/buildSrc/src/main/kotlin/VersionUtils.kt b/buildSrc/src/main/kotlin/VersionUtils.kt index 202695c2..dfaa8c6c 100644 --- a/buildSrc/src/main/kotlin/VersionUtils.kt +++ b/buildSrc/src/main/kotlin/VersionUtils.kt @@ -1,29 +1,48 @@ /** - * Get the versionCode for a given semver + * Get the version code for a given semantic version. + * Does not validate the input and thus will throw an exception when parts are missing. + * + * The pre-release part ("-rc.1", "-beta.1" etc.) defaults to 99 * * Sample output: - * 0.0.0 -> 0 - * 1.1.1 -> 10101 - * 0.7.0 -> 700 - * 99.99.99 -> 999999 - * - * @return the versionCode, or null if value is invalid. + * MA.MI.PA-PR -> MAMIPAPR + * 0.0.0 -> 99 + * 1.1.1 -> 1010199 + * 0.7.0 -> 70099 + * 99.99.99 -> 99999999 + * 2.0.0-rc.3 -> 2000003 + * 2.0.0 -> 2000099 + * 99.99.99-rc.1 -> 99999901 */ fun getVersionCode(versionName: String): Int? { - val parts = versionName - .substringBefore('-') + // Split to core and pre release parts with a default for pre release (null) + val (versionCore, versionPreRelease) = + when (val index = versionName.indexOf('-')) { + // No pre-release part included + -1 -> versionName to null + // Pre-release part included + else -> versionName.substring(0, index) to + versionName.substring(index + 1, versionName.length) + } + + // Parse core part + val (major, minor, patch) = versionCore .splitToSequence('.') .mapNotNull(String::toIntOrNull) .take(3) .toList() - // Not a valid semver - if (parts.size != 3) return null + // Parse pre release part (ignore type, only get the number) + val buildVersion = versionPreRelease + ?.substringAfter('.') + ?.let(String::toIntOrNull) + // Build code var code = 0 - code += parts[0] * 10000 // Major (0-99) - code += parts[1] * 100 // Minor (0-99) - code += parts[2] // Patch (0-99) + code += major * 1000000 // Major (0-99) + code += minor * 10000 // Minor (0-99) + code += patch * 100 // Patch (0-99) + code += buildVersion ?: 99 // Pre release (0-99) return code -} \ No newline at end of file +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 1cdbae80..8129c838 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,5 @@ include(":app") -rootProject.name = "Jellyfin" - pluginManagement { val kotlinVersion: String by settings resolutionStrategy { @@ -10,4 +8,4 @@ pluginManagement { useVersion(kotlinVersion) } } -} \ No newline at end of file +}