Skip to content

Commit

Permalink
KTOR-2763 Fix Warnings and Enable -Werror flag (#2496)
Browse files Browse the repository at this point in the history
* KTOR-2763 Fix warnings in ktor-io

* KTOR-2763 Fix warnings in ktor-utils

* KTOR-2763 Fix warnings in ktor-http

* KTOR-2763 Fix warnings in ktor-network

* KTOR-2763 Fix warnings in ktor-features

* KTOR-2763 Fix warnings in ktor-server

* KTOR-2763 Fix warnings in ktor-client

* KTOR-2763 Fix warnings in ktor-shared & ktor-test-dispatcher

* KTOR-2763 Update configuration
  • Loading branch information
e5l committed Oct 4, 2021
1 parent 7d6faea commit 99d172d
Show file tree
Hide file tree
Showing 467 changed files with 1,861 additions and 1,741 deletions.
43 changes: 25 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ extra["publishLocal"] = project.hasProperty("publishLocal")

val configuredVersion: String by extra

apply(from = "gradle/experimental.gradle")
apply(from = "gradle/verifier.gradle")

val experimentalAnnotations: List<String> by extra

/**
* `darwin` is subset of `posix`.
* Don't create `posix` and `darwin` sourceSets in single project.
Expand Down Expand Up @@ -146,6 +143,7 @@ allprojects {
if (nonDefaultProjectStructure.contains(project.name)) return@allprojects

apply(plugin = "kotlin-multiplatform")
apply(plugin = "kotlinx-atomicfu")

apply(from = rootProject.file("gradle/utility.gradle"))

Expand All @@ -166,30 +164,39 @@ allprojects {
maybeCreate("testOutput")
}


kotlin {
targets.all {

if (this is org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget) {
irTarget?.compilations?.all {
configureCompilation()
}

}
compilations.all {
configureCompilation()
}
}

if (!disabledExplicitApiModeProjects.contains(project.name)) {
explicitApi()
}

sourceSets.matching { !(it.name in listOf("main", "test")) }.all {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
val platform = name.dropLast(4)
sourceSets
.matching { it.name !in listOf("main", "test") }
.all {
val srcDir = if (name.endsWith("Main")) "src" else "test"
val resourcesPrefix = if (name.endsWith("Test")) "test-" else ""
val platform = name.dropLast(4)

kotlin.srcDir("$platform/$srcDir")
resources.srcDir("$platform/${resourcesPrefix}resources")
kotlin.srcDir("$platform/$srcDir")
resources.srcDir("$platform/${resourcesPrefix}resources")

languageSettings.apply {
progressiveMode = true
experimentalAnnotations.forEach { optIn(it) }

if (project.path.startsWith(":ktor-server:ktor-server")
&& project.name != "ktor-server-core"
) {
optIn("io.ktor.server.engine.EngineAPI")
languageSettings.apply {
progressiveMode = true
}
}
}
}

val skipPublish: List<String> by rootProject.extra
Expand Down
15 changes: 15 additions & 0 deletions buildSrc/src/main/kotlin/Compilations.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.*

fun KotlinCompilation<KotlinCommonOptions>.configureCompilation() {
kotlinOptions {
if (platformType == KotlinPlatformType.jvm) {
allWarningsAsErrors = true
}
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
19 changes: 16 additions & 3 deletions buildSrc/src/main/kotlin/KotlinExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import org.gradle.api.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.*
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
import org.gradle.api.*
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.*

fun Project.kotlin(block: KotlinMultiplatformExtension.() -> Unit) {
configure(block)
}

val Project.kotlin: KotlinMultiplatformExtension get() = the()

val NamedDomainObjectContainer<KotlinSourceSet>.jvmMain: NamedDomainObjectProvider<KotlinSourceSet>
get() = named<KotlinSourceSet>("jvmMain")

val NamedDomainObjectContainer<KotlinSourceSet>.jvmTest: NamedDomainObjectProvider<KotlinSourceSet>
get() = named<KotlinSourceSet>("jvmTest")

val NamedDomainObjectContainer<KotlinSourceSet>.commonMain: NamedDomainObjectProvider<KotlinSourceSet>
get() = named<KotlinSourceSet>("commonMain")

val NamedDomainObjectContainer<KotlinSourceSet>.commonTest: NamedDomainObjectProvider<KotlinSourceSet>
get() = named<KotlinSourceSet>("commonTest")
69 changes: 69 additions & 0 deletions buildSrc/src/main/kotlin/KtorBuildProperties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import KtorBuildProperties.jdk8Modules
import org.gradle.api.*

/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

private val java_version: String = System.getProperty("java.version", "8.0.0")

private val versionComponents = java_version
.split(".")
.take(2)
.filter { it.isNotBlank() }
.map { Integer.parseInt(it) }

object KtorBuildProperties {

val jettyAlpnBootVersion: String? = when (java_version) {
"1.8.0_191",
"1.8.0_192",
"1.8.0_201",
"1.8.0_202",
"1.8.0_211",
"1.8.0_212",
"1.8.0_221",
"1.8.0_222",
"1.8.0_231",
"1.8.0_232",
"1.8.0_241",
"1.8.0_242" -> "8.1.13.v20181017"
else -> null
}

@JvmStatic
val ideaActive: Boolean = System.getProperty("idea.active") == "true"

@JvmStatic
val currentJdk = if (versionComponents[0] == 1) versionComponents[1] else versionComponents[0]

val jdk8Modules = listOf(
"ktor-client-tests",

"ktor-server-core", "ktor-server-host-common", "ktor-server-servlet", "ktor-server-netty", "ktor-server-tomcat",
"ktor-server-test-host", "ktor-server-test-suites",

"ktor-websockets", "ktor-webjars", "ktor-metrics", "ktor-server-sessions", "ktor-auth", "ktor-auth-jwt",

"ktor-network-tls-certificates"
)

val jdk7Modules = listOf(
"ktor-http",
"ktor-utils",
"ktor-network-tls",
"ktor-websockets"
)

val jdk11Modules = listOf(
"ktor-client-java"
)

@JvmStatic
fun projectJdk(name: String): Int = when (name) {
in jdk8Modules -> 8
in jdk11Modules -> 11
in jdk7Modules -> 7
else -> 6
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Train.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun Project.setupTrainForSubproject() {
val serialization_version: String by extra

extra["kotlin_version"] = rootProject.properties["kotlin_snapshot_version"]
var kotlin_version: String by extra
val kotlin_version: String by extra
println("Using Kotlin $kotlin_version for project $this")
val deployVersion = properties["DeployVersion"]
if (deployVersion != null) version = deployVersion
Expand Down
11 changes: 2 additions & 9 deletions gradle/darwin.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
apply from: rootProject.file("gradle/ide.gradle")

apply plugin: "kotlinx-atomicfu"

kotlin {
targets {
if (project.ext.ideaActive) {
if (KtorBuildProperties.ideaActive) {
fromPreset(project.ext.ideaPreset, 'darwin')
} else {
fromPreset(presets.iosArm64, 'iosArm64')
Expand All @@ -20,15 +18,10 @@ kotlin {
}
}
sourceSets {
darwinMain.dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:atomicfu:$atomicfu_version"
}

darwinMain { dependsOn commonMain }
darwinTest

if (!project.ext.ideaActive) {
if (!KtorBuildProperties.ideaActive) {
configure([iosArm32Main, iosArm64Main, iosX64Main, macosX64Main, tvosArm64Main, tvosX64Main, watchosArm32Main, watchosArm64Main, watchosX86Main, watchosX64Main]) {
dependsOn darwinMain
}
Expand Down
23 changes: 1 addition & 22 deletions gradle/jvm.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@
* Copyright 2014-2020 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

apply from: rootProject.file('gradle/jdk.gradle')

def jdk = 6

if (project.name in project.ext.jdk11Modules) {
jdk = 11
} else if (project.name in project.ext.jdk8Modules) {
jdk = 8
} else if (project.name in project.ext.jdk7Modules) {
jdk = 7
}
def jdk = KtorBuildProperties.projectJdk(name)

String lookupJdk(int startingFrom) {
return (startingFrom..20)
Expand All @@ -23,19 +13,8 @@ String lookupJdk(int startingFrom) {

def jdkHome = lookupJdk(jdk)

int currentJdk = ext.currentJdk

apply plugin: "kotlinx-atomicfu"

kotlin {
jvm {
compilations.all {
if (rootProject.ext.jvm_ir_enabled) {
kotlinOptions.useIR = true
}

kotlinOptions.freeCompilerArgs += ["-XXLanguage:+InlineClasses", "-Xuse-14-inline-classes-mangling-scheme"]
}
}

task jarTest(type: Jar, dependsOn: jvmTestClasses) {
Expand Down
13 changes: 3 additions & 10 deletions gradle/posix.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
apply from: rootProject.file("gradle/ide.gradle")

apply plugin: "kotlinx-atomicfu"

def getHostName() {
def target = System.getProperty("os.name")
if (target == 'Linux') return 'linux'
Expand Down Expand Up @@ -46,7 +44,7 @@ if (host == 'windows' && skipMingw) return

kotlin {
targets {
if (project.ext.ideaActive) {
if (KtorBuildProperties.ideaActive) {
project.ext.hostname = host
fromPreset(project.ext.ideaPreset, 'posix')
project.ext.nativeTargets = [posix]
Expand Down Expand Up @@ -109,15 +107,10 @@ kotlin {
project.ext.nativeCompilations += project.ext.nativeTargets.collect { it.compilations.main }
}
sourceSets {
posixMain.dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:atomicfu:$atomicfu_version"
}

posixTest
posixMain { dependsOn commonMain }
posixTest

if (!project.ext.ideaActive) {
if (!KtorBuildProperties.ideaActive) {
configure(project.ext.nativeTargets.collect { getByName(it.name + 'Main') }) {
dependsOn posixMain
}
Expand Down
25 changes: 1 addition & 24 deletions gradle/utility.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
project.ext.ideaActive = System.getProperty('idea.active') == 'true'

kotlin {
targets {
Expand All @@ -11,7 +10,7 @@ kotlin {
project.ext.isMacosHost = macosEnabled
project.ext.isWinHost = winEnabled

if (project.ext.ideaActive) {
if (KtorBuildProperties.ideaActive) {
def ideaPreset = presets.linuxX64
if (macosEnabled) ideaPreset = presets.macosX64
if (winEnabled) ideaPreset = presets.mingwX64
Expand All @@ -20,25 +19,3 @@ kotlin {
}
}
}

def java_version = System.properties["java.version"]

switch (java_version) {
case '1.8.0_191':
case '1.8.0_192':
case '1.8.0_201':
case '1.8.0_202':
case '1.8.0_211':
case '1.8.0_212':
case '1.8.0_221':
case '1.8.0_222':
case '1.8.0_231':
case '1.8.0_232':
case '1.8.0_241':
case '1.8.0_242':
project.ext.jetty_alpn_boot_version = "8.1.13.v20181017"
break
default:
project.ext.jetty_alpn_boot_version = null
break
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.ktor.client.request.*
import io.ktor.client.utils.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.util.*
import io.ktor.util.date.*
import io.ktor.utils.io.*
import io.ktor.utils.io.jvm.javaio.*
Expand All @@ -26,6 +27,7 @@ private val METHODS_WITHOUT_BODY = listOf(HttpMethod.Get, HttpMethod.Head)
/**
* Android client engine
*/
@OptIn(InternalAPI::class)
public class AndroidClientEngine(override val config: AndroidEngineConfig) : HttpClientEngineBase("ktor-android") {

override val dispatcher: CoroutineDispatcher by lazy {
Expand Down Expand Up @@ -85,14 +87,14 @@ public class AndroidClientEngine(override val config: AndroidEngineConfig) : Htt
outgoingContent.writeTo(outputStream, callContext)
}

return connection.timeoutAwareConnection(data) { connection ->
val responseCode = connection.responseCode
val responseMessage = connection.responseMessage
return connection.timeoutAwareConnection(data) { current ->
val responseCode = current.responseCode
val responseMessage = current.responseMessage
val statusCode = responseMessage?.let { HttpStatusCode(responseCode, it) }
?: HttpStatusCode.fromValue(responseCode)

val content: ByteReadChannel = connection.content(callContext, data)
val headerFields: Map<String, List<String>> = connection.headerFields
val content: ByteReadChannel = current.content(callContext, data)
val headerFields: Map<String, List<String>> = current.headerFields
.mapKeys { it.key?.lowercase(Locale.getDefault()) ?: "" }
.filter { it.key.isNotBlank() }

Expand All @@ -110,6 +112,8 @@ public class AndroidClientEngine(override val config: AndroidEngineConfig) : Htt
}
}

@OptIn(DelicateCoroutinesApi::class)
@Suppress("BlockingMethodInNonBlockingContext")
internal suspend fun OutgoingContent.writeTo(
stream: OutputStream,
callContext: CoroutineContext
Expand Down
Loading

0 comments on commit 99d172d

Please sign in to comment.