Skip to content

Commit

Permalink
Merge pull request #558 from nielsvanvelzen/consistency-fixes
Browse files Browse the repository at this point in the history
Slightly change build files to be more consistent with Android mobile app
  • Loading branch information
thornbill authored Sep 12, 2020
2 parents 964af83 + bda73e9 commit 31e49fa
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 38 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
kotlin("android")
kotlin("android.extensions")
}

android {
compileSdkVersion(29)
// Explicitly specify ndk version for Azure
// Can be removed when version 4.1.x of the Android Gradle plugin is relased
// Can be removed when version 4.1.x of the Android Gradle plugin is released
ndkVersion = "21.3.6528147"

defaultConfig {
Expand All @@ -16,8 +16,8 @@ android {
targetSdkVersion(29)

// Release version
versionCode = getVersionCode(project.version.toString()) ?: 1
versionName = project.version.toString()
versionName = project.getVersionName()
versionCode = getVersionCode(versionName)
}

compileOptions {
Expand Down Expand Up @@ -57,7 +57,7 @@ android {

dependencies {
// Jellyfin
implementation("org.jellyfin.apiclient:android:0.7.2")
implementation("org.jellyfin.apiclient:android:0.7.4")

// Kotlin
implementation(kotlin("stdlib-jdk8"))
Expand Down
5 changes: 0 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ buildscript {
}

allprojects {
// Versioning
allprojects {
group = "org.jellyfin.apiclient"
version = getProperty("jellyfin.version")?.removePrefix("v") ?: "DEV"
}
// Dependencies
repositories {
jcenter()
Expand Down
25 changes: 0 additions & 25 deletions buildSrc/src/main/kotlin/Semver.kt

This file was deleted.

65 changes: 65 additions & 0 deletions buildSrc/src/main/kotlin/VersionUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import org.gradle.api.Project

/**
* Get the version name from the current environment or use the fallback.
* It will look for a environment variable called JELLYFIN_VERSION first.
* Next it will look for a property called "jellyfin.version" and lastly it will use the fallback.
* If the version in the environment starts with a "v" prefix it will be removed.
*
* Sample output:
* v2.0.0 -> 2.0.0
* null -> 0.0.0-dev.1 (unless different fallback set)
*/
fun Project.getVersionName(fallback: String = "0.0.0-dev.1") =
getProperty("jellyfin.version")
?.removePrefix("v")
?: fallback

/**
* 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:
* 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? {
// 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()

// Parse pre release part (ignore type, only get the number)
val buildVersion = versionPreRelease
?.substringAfter('.')
?.let(String::toIntOrNull)

// Build code
var code = 0
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
}
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import java.util.*

include(":app")

// Load properties from local.properties
val properties = java.util.Properties().apply {
val location = file("local.properties")
val properties = Properties().apply {
val location = File("local.properties")
if (location.exists())
load(location.inputStream())
}
Expand Down

0 comments on commit 31e49fa

Please sign in to comment.