Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Kotlin and Gradle updates #160

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Kotlin version, clear up warnings from update
  • Loading branch information
stevenzeck committed Jun 25, 2021
commit eca0c3fd920f563e88537eb63c9c88b5cce826ca
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.31'
ext.kotlin_version = '1.5.20'

repositories {
google()
Expand Down
6 changes: 3 additions & 3 deletions r2-shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ dependencies {
implementation "nl.komponents.kovenant:kovenant-functional:3.3.0"
implementation "nl.komponents.kovenant:kovenant-jvm:3.3.0"
implementation "nl.komponents.kovenant:kovenant:3.3.0"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.31"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
implementation "org.jetbrains.kotlin:kotlin-reflect:1.5.20"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-native-mt"
implementation "org.jsoup:jsoup:1.13.1"

testImplementation "androidx.test.ext:junit-ktx:1.1.2"
testImplementation "androidx.test:core-ktx:1.3.0"
testImplementation "junit:junit:4.13.2"
testImplementation "net.sf.kxml:kxml2:2.3.0"
testImplementation 'org.assertj:assertj-core:3.19.0'
testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.4.31"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:1.5.20"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.4.2"
// Latest version of org.json is incompatible with the one bundled in Android, breaking the tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class XmlParser(val isNamespaceAware: Boolean = true, val isCaseSensitive: Boole

private fun buildElement(attributes: AttributeMap, children: MutableList<Node>, lang: String): ElementNode {
val rawName = parser.name
val name = if (isCaseSensitive) rawName else rawName.toLowerCase(Locale.getDefault())
val name = if (isCaseSensitive) rawName else rawName.lowercase(Locale.getDefault())
return ElementNode(name, parser.namespace, lang, attributes, children)
}

private fun buildAttribute(index: Int): Attribute {
with(parser) {
val rawName = getAttributeName(index)
val name = if (isCaseSensitive) rawName else rawName.toLowerCase(Locale.getDefault())
val name = if (isCaseSensitive) rawName else rawName.lowercase(Locale.getDefault())
return Attribute(name, getAttributeNamespace(index), getAttributeValue(index))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ data class Metadata(
return ReadingProgression.LTR
}

var language = languages.first().toLowerCase(Locale.ROOT)
var language = languages.first().lowercase(Locale.ROOT)

if (language == "zh-hant" || language == "zh-tw") {
return ReadingProgression.RTL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package org.readium.r2.shared.publication

import android.net.Uri
import androidx.annotation.StringRes
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.json.JSONObject
Expand Down Expand Up @@ -164,6 +165,7 @@ class Publication(
/**
* Closes any opened resource associated with the [Publication], including services.
*/
@DelicateCoroutinesApi
fun close() = GlobalScope.launch {
try {
fetcher.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum class ReadingProgression(val value: String) : Parcelable {

override fun get(key: String?): ReadingProgression? =
// For backward compatibility, we allow uppercase keys.
keys.firstOrNull { it == key?.toLowerCase(Locale.ROOT) }
keys.firstOrNull { it == key?.lowercase(Locale.ROOT) }
?.let { map[it] }

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private sealed class RouteHandler {
}
}

fun String.toBooleanOrNull(): Boolean? = when (this.toLowerCase(Locale.getDefault())) {
fun String.toBooleanOrNull(): Boolean? = when (this.lowercase(Locale.getDefault())) {
"true" -> true
"false" -> false
else -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ internal inline fun <T> benchmark(title: String, enabled: Boolean = true, closur
val duration = measureTime {
result = closure()
}
Timber.d("""Benchmark "$title" took %.4f seconds """.format(duration.inSeconds))
Timber.d("""Benchmark "$title" took %.4f seconds """.format(duration.inWholeSeconds))
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ class DefaultHttpClient constructor(

val readTimeout = readTimeout ?: this@DefaultHttpClient.readTimeout
if (readTimeout != null) {
connection.readTimeout = readTimeout.toLongMilliseconds().toInt()
connection.readTimeout = readTimeout.inWholeMilliseconds.toInt()
}

val connectTimeout = connectTimeout ?: this@DefaultHttpClient.connectTimeout
if (connectTimeout != null) {
connection.connectTimeout = connectTimeout.toLongMilliseconds().toInt()
connection.connectTimeout = connectTimeout.inWholeMilliseconds.toInt()
}
connection.allowUserInteraction = allowUserInteraction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ data class HttpResponse(
*/
fun valuesForHeader(name: String): List<String> {
@Suppress("NAME_SHADOWING")
val name = name.toLowerCase(Locale.ROOT)
val name = name.lowercase(Locale.ROOT)
return headers
.filterKeys { it.toLowerCase(Locale.ROOT) == name }
.filterKeys { it.lowercase(Locale.ROOT) == name }
.values
.flatten()
}
Expand All @@ -132,8 +132,8 @@ data class HttpResponse(
* Indicates whether this server supports byte range requests.
*/
val acceptsByteRanges: Boolean get() {
return valueForHeader("Accept-Ranges")?.toLowerCase(Locale.ROOT) == "bytes"
|| valueForHeader("Content-Range")?.toLowerCase(Locale.ROOT)?.startsWith("bytes") == true
return valueForHeader("Accept-Ranges")?.lowercase(Locale.ROOT) == "bytes"
|| valueForHeader("Content-Range")?.lowercase(Locale.ROOT)?.startsWith("bytes") == true
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class MediaType(
}

// > Both top-level type and subtype names are case-insensitive.
this.type = types[0].toLowerCase(Locale.ROOT)
this.subtype = types[1].toLowerCase(Locale.ROOT)
this.type = types[0].lowercase(Locale.ROOT)
this.subtype = types[1].lowercase(Locale.ROOT)

// > Parameter names are case-insensitive and no meaning is attached to the order in which
// > they appear.
val parameters = components.drop(1)
.map { it.split("=") }
.filter { it.size == 2 }
.associate { Pair(it[0].toLowerCase(Locale.ROOT), it[1]) }
.associate { Pair(it[0].lowercase(Locale.ROOT), it[1]) }
.toMutableMap()

// For now, we only support case-insensitive `charset`.
Expand All @@ -90,7 +90,7 @@ class MediaType(
parameters["charset"]?.let {
parameters["charset"] =
(try { Charset.forName(it).name() } catch (e: Exception) { it })
.toUpperCase(Locale.ROOT)
.uppercase(Locale.ROOT)
}

this.parameters = parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kotlinx.coroutines.withContext
import org.json.JSONObject
import org.readium.r2.shared.extensions.tryOrNull
import org.readium.r2.shared.publication.*
import org.readium.r2.shared.util.archive.Archive
import java.io.File
import java.net.URLConnection
import java.util.*
Expand Down Expand Up @@ -44,7 +43,7 @@ object Sniffers {
return MediaType.HTML
}
// [contentAsXml] will fail if the HTML is not a proper XML document, hence the doctype check.
if (context.contentAsXml()?.name?.toLowerCase(Locale.ROOT) == "html" || context.contentAsString()?.trimStart()?.startsWith("<!DOCTYPE html>") == true) {
if (context.contentAsXml()?.name?.lowercase(Locale.ROOT) == "html" || context.contentAsString()?.trimStart()?.startsWith("<!DOCTYPE html>") == true) {
return MediaType.HTML
}
return null
Expand Down Expand Up @@ -294,7 +293,7 @@ object Sniffers {
suspend fun archiveContainsOnlyExtensions(fileExtensions: List<String>): Boolean =
context.archiveEntriesAllSatisfy { entry ->
val file = File(entry.path)
isIgnored(file) || fileExtensions.contains(file.extension.toLowerCase(Locale.ROOT))
isIgnored(file) || fileExtensions.contains(file.extension.lowercase(Locale.ROOT))
}

if (archiveContainsOnlyExtensions(CBZ_EXTENSIONS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SnifferContext internal constructor(

/** File extension hints. */
val fileExtensions: List<String> = fileExtensions
.map { it.toLowerCase(Locale.ROOT) }
.map { it.lowercase(Locale.ROOT) }

// Metadata

Expand All @@ -54,7 +54,7 @@ class SnifferContext internal constructor(
/** Returns whether this context has any of the given file extensions, ignoring case. */
fun hasFileExtension(vararg fileExtensions: String): Boolean {
for (fileExtension in fileExtensions) {
if (this.fileExtensions.contains(fileExtension.toLowerCase(Locale.ROOT))) {
if (this.fileExtensions.contains(fileExtension.lowercase(Locale.ROOT))) {
return true
}
}
Expand Down