Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin 1.4 dependency upgrade and language features #5947

Merged
merged 29 commits into from Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6478137
Testing with kotlin 1.4
yschimke Apr 12, 2020
eac6232
Merge branch 'master' into kotlin_1_4
yschimke May 13, 2020
e699aff
Fix
yschimke May 13, 2020
ecbcf8e
M2 dev builds
yschimke May 14, 2020
ef4e0ba
Allow for domain name trailing dot in PublicSuffixDatabase (#6111)
yschimke Jun 4, 2020
a3ab5d2
Dependency upgrades (#6114)
yschimke Jun 4, 2020
4051d94
Update build.gradle
yschimke Jun 4, 2020
0eed1c3
Merge branch 'master' into kotlin_1_4
yschimke Jun 4, 2020
a612393
Merge branch 'kotlin_1_4' of https://github.com/yschimke/okhttp into …
yschimke Jun 4, 2020
9aa4564
1.4 M2
yschimke Jun 4, 2020
360d508
Merge branch 'master' into kotlin_1_4
yschimke Jul 7, 2020
9ce8ca3
Fix
yschimke Jul 7, 2020
248f800
Cleanup
yschimke Jul 7, 2020
aa04573
Kotlin 1.4 RC
yschimke Jul 24, 2020
051fe84
Merge branch 'master' into kotlin_1_4
yschimke Jul 24, 2020
cee4faf
More fixes
yschimke Aug 1, 2020
c8a28e1
Merge branch 'master' into kotlin_1_4
yschimke Aug 1, 2020
a3955bb
Merge branch 'master' into kotlin_1_4
yschimke Aug 15, 2020
56622fa
Kotlin 1.4.0
yschimke Aug 15, 2020
0e343e2
Readd plugins
yschimke Aug 15, 2020
0fc3be0
Merge branch 'master' into kotlin_1_4
yschimke Aug 22, 2020
557666a
Review comments
yschimke Aug 22, 2020
d4b74c1
Review comments
yschimke Aug 22, 2020
dddb149
Review comments
yschimke Aug 22, 2020
b5dbe93
Merge branch 'master' into kotlin_1_4
yschimke Sep 6, 2020
f1f28f9
Bump to okio 2.8.0
yschimke Sep 6, 2020
ef0346c
Merge branch 'kotlin_1_4' of https://github.com/yschimke/okhttp into …
yschimke Sep 6, 2020
ef1229d
Review comments
yschimke Sep 6, 2020
59b8b9f
Review comments
yschimke Sep 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 33 additions & 27 deletions build.gradle
@@ -1,4 +1,4 @@
import net.ltgt.gradle.errorprone.CheckSeverity
//import net.ltgt.gradle.errorprone.CheckSeverity

buildscript {
ext.versions = [
Expand All @@ -15,10 +15,10 @@ buildscript {
'jnrUnixsocket': '0.28',
'jsoup': '1.13.1',
'junit': '4.13',
'kotlin': '1.3.72',
'kotlin': '1.4.0',
'moshi': '1.9.2',
'okio': '2.7.0',
'ktlint': '0.36.0',
'ktlint': '0.37.0',
yschimke marked this conversation as resolved.
Show resolved Hide resolved
'picocli': '4.2.0',
'openjsse': '1.1.0'
]
Expand All @@ -39,32 +39,35 @@ buildscript {
'jsoup': "org.jsoup:jsoup:${versions.jsoup}",
'jsr305': "com.google.code.findbugs:jsr305:${versions.findbugs}",
'junit': "junit:junit:${versions.junit}",
'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}",
'kotlinStdlib': "org.jetbrains.kotlin:kotlin-stdlib:1.4.0",
'moshi': "com.squareup.moshi:moshi:${versions.moshi}",
'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}",
'okio': "com.squareup.okio:okio:${versions.okio}",
'openjsse': "org.openjsse:openjsse:${versions.openjsse}"
]

dependencies {
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1"
classpath 'com.diffplug.spotless:spotless-plugin-gradle:3.27.1'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:3.6.4'
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}

repositories {
mavenCentral()
gradlePluginPortal()
google()
maven {
url = "https://dl.bintray.com/kotlin/kotlin-dev/"
}
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}
}

plugins {
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'me.champeau.gradle.japicmp' version '0.2.9'
id "com.diffplug.spotless" version "5.1.1"
yschimke marked this conversation as resolved.
Show resolved Hide resolved
id("net.ltgt.errorprone") version "1.2.1"
}

/** Returns the artifact ID for the project, or null if it is not published. */
Expand Down Expand Up @@ -97,6 +100,9 @@ allprojects {
url 'https://dl.bintray.com/kotlin/dokka'
}
google()
maven {
url = "https://dl.bintray.com/kotlin/kotlin-dev/"
}
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}

task downloadDependencies() {
Expand All @@ -112,14 +118,12 @@ subprojects { project ->
if (project.name == 'android-test') return
if (project.name == 'okhttp-bom') return

apply plugin: "kotlin"
yschimke marked this conversation as resolved.
Show resolved Hide resolved
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.jetbrains.kotlin.platform.jvm'
apply plugin: 'checkstyle'
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'com.diffplug.gradle.spotless'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand Down Expand Up @@ -152,16 +156,18 @@ subprojects { project ->
signature 'org.codehaus.mojo.signature:java18:1.0@signature'
}

spotless {
kotlin {
target "**/*.kt"
ktlint(versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size': '2'])
}
}
// spotless {
// kotlin {
// target "**/*.kt"
// ktlint(versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size': '2'])
// }
// }
yschimke marked this conversation as resolved.
Show resolved Hide resolved

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.4"
languageVersion = "1.4"
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -205,20 +211,20 @@ subprojects { project ->
}
}

dependencies {
//noinspection GradleDynamicVersion
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
}
// dependencies {
yschimke marked this conversation as resolved.
Show resolved Hide resolved
// //noinspection GradleDynamicVersion
// errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
// errorprone 'com.google.errorprone:error_prone_core:2.4.0'
// }
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

options.errorprone {
check("MissingFail", CheckSeverity.ERROR)
check("MissingOverride", CheckSeverity.ERROR)
enabled = JavaVersion.current() < JavaVersion.VERSION_12
}
// options.errorprone {
// check("MissingFail", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
yschimke marked this conversation as resolved.
Show resolved Hide resolved
// check("MissingOverride", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
// enabled = JavaVersion.current() < JavaVersion.VERSION_12
// }
}

dokka {
Expand Down
6 changes: 1 addition & 5 deletions okcurl/src/main/kotlin/okhttp3/curl/Main.kt
Expand Up @@ -168,11 +168,7 @@ class Main : Runnable {
builder.hostnameVerifier(createInsecureHostnameVerifier())
}
if (verbose) {
val logger = object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
println(message)
}
}
val logger = HttpLoggingInterceptor.Logger(::println)
builder.eventListenerFactory(LoggingEventListener.Factory(logger))
}
return builder.build()
Expand Down
Expand Up @@ -104,7 +104,7 @@ class HttpLoggingInterceptor @JvmOverloads constructor(
BODY
}

interface Logger {
fun interface Logger {
fun log(message: String)

companion object {
Expand Down
Expand Up @@ -107,6 +107,8 @@ private void setLevel(Level level) {
try {
applicationInterceptor.setLevel(null);
fail();
} catch (NullPointerException expected) {
// Kotlin 1.4
} catch (IllegalArgumentException expected) {
}
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
2 changes: 1 addition & 1 deletion okhttp-sse/src/main/kotlin/okhttp3/sse/EventSource.kt
Expand Up @@ -27,7 +27,7 @@ interface EventSource {
*/
fun cancel()

interface Factory {
fun interface Factory {
/**
* Creates a new event source and immediately returns it. Creating an event source initiates an
* asynchronous process to connect the socket. Once that succeeds or fails, `listener` will be
Expand Down
21 changes: 9 additions & 12 deletions okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt
Expand Up @@ -16,25 +16,22 @@
package okhttp3.sse

import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.internal.sse.RealEventSource

object EventSources {
@JvmStatic
fun createFactory(client: OkHttpClient): EventSource.Factory {
return object : EventSource.Factory {
override fun newEventSource(request: Request, listener: EventSourceListener): EventSource {
val actualRequest =
if (request.header("Accept") == null) {
request.newBuilder().addHeader("Accept", "text/event-stream").build()
} else {
request
}

return RealEventSource(actualRequest, listener).apply {
connect(client)
return EventSource.Factory { request, listener ->
yschimke marked this conversation as resolved.
Show resolved Hide resolved
val actualRequest =
if (request.header("Accept") == null) {
request.newBuilder().addHeader("Accept", "text/event-stream").build()
} else {
request
}

RealEventSource(actualRequest, listener).apply {
connect(client)
}
}
}
Expand Down
Expand Up @@ -92,14 +92,11 @@ class OkHttpClientTestRule : TestRule {
Logger.getLogger("javax.net.ssl").fn()
}

fun wrap(eventListener: EventListener) = object : EventListener.Factory {
override fun create(call: Call) = ClientRuleEventListener(eventListener) { addEvent(it) }
}
fun wrap(eventListener: EventListener) =
EventListener.Factory { ClientRuleEventListener(eventListener, ::addEvent) }

fun wrap(eventListenerFactory: EventListener.Factory) = object : EventListener.Factory {
override fun create(call: Call) =
ClientRuleEventListener(eventListenerFactory.create(call)) { addEvent(it) }
}
fun wrap(eventListenerFactory: EventListener.Factory) =
EventListener.Factory { call -> ClientRuleEventListener(eventListenerFactory.create(call), ::addEvent) }

/**
* Returns an OkHttpClient for tests to use as a starting point.
Expand All @@ -115,9 +112,8 @@ class OkHttpClientTestRule : TestRule {
if (client == null) {
client = OkHttpClient.Builder()
.dns(SINGLE_INET_ADDRESS_DNS) // Prevent unexpected fallback addresses.
.eventListenerFactory(object : EventListener.Factory {
override fun create(call: Call) = ClientRuleEventListener { addEvent(it) }
})
.eventListenerFactory(
EventListener.Factory { ClientRuleEventListener(logger = ::addEvent) })
.build()
testClient = client
}
Expand Down
Expand Up @@ -129,7 +129,7 @@ open class RecordingEventListener : EventListener() {
for (lock in forbiddenLocks) {
assertThat(Thread.holdsLock(lock))
.overridingErrorMessage(lock.toString())
.isFalse()
.isFalse
yschimke marked this conversation as resolved.
Show resolved Hide resolved
}

val startEvent = e.closes(-1L)
Expand Down
2 changes: 2 additions & 0 deletions okhttp/build.gradle
Expand Up @@ -108,6 +108,8 @@ task japicmp(type: me.champeau.gradle.japicmp.JapicmpTask, dependsOn: 'jar') {
'okhttp3.OkHttpClient#socketFactory()',
'okhttp3.OkHttpClient#sslSocketFactory()',
'okhttp3.OkHttpClient#writeTimeoutMillis()',
'okhttp3.OkHttpClient#writeTimeoutMillis()',
'okhttp3.Request$Builder#delete()',
]
}
check.dependsOn(japicmp)
2 changes: 1 addition & 1 deletion okhttp/src/main/kotlin/okhttp3/Authenticator.kt
Expand Up @@ -112,7 +112,7 @@ import okhttp3.internal.authenticator.JavaNetAuthenticator
*
* [1]: https://tools.ietf.org/html/rfc2817
*/
interface Authenticator {
fun interface Authenticator {
/**
* Returns a request that includes a credential to satisfy an authentication challenge in
* [response]. Returns null if the challenge cannot be satisfied.
Expand Down
13 changes: 6 additions & 7 deletions okhttp/src/main/kotlin/okhttp3/Cache.kt
Expand Up @@ -386,12 +386,12 @@ class Cache internal constructor(

@Synchronized fun requestCount(): Int = requestCount

private inner class RealCacheRequest internal constructor(
private inner class RealCacheRequest(
private val editor: DiskLruCache.Editor
) : CacheRequest {
private val cacheOut: Sink = editor.newSink(ENTRY_BODY)
private val body: Sink
internal var done = false
var done = false

init {
this.body = object : ForwardingSink(cacheOut) {
Expand Down Expand Up @@ -489,8 +489,7 @@ class Cache internal constructor(
* each on their own line. A length of -1 is used to encode a null array. The last line is
* optional. If present, it contains the TLS version.
*/
@Throws(IOException::class)
internal constructor(rawSource: Source) {
@Throws(IOException::class) constructor(rawSource: Source) {
try {
val source = rawSource.buffer()
url = source.readUtf8LineStrict()
Expand Down Expand Up @@ -542,7 +541,7 @@ class Cache internal constructor(
}
}

internal constructor(response: Response) {
constructor(response: Response) {
this.url = response.request.url.toString()
this.varyHeaders = response.varyHeaders()
this.requestMethod = response.request.method
Expand Down Expand Up @@ -665,8 +664,8 @@ class Cache internal constructor(
}
}

private class CacheResponseBody internal constructor(
internal val snapshot: DiskLruCache.Snapshot,
private class CacheResponseBody(
val snapshot: DiskLruCache.Snapshot,
private val contentType: String?,
private val contentLength: String?
) : ResponseBody() {
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/kotlin/okhttp3/Call.kt
Expand Up @@ -93,7 +93,7 @@ interface Call : Cloneable {
*/
public override fun clone(): Call

interface Factory {
fun interface Factory {
fun newCall(request: Request): Call
}
}
2 changes: 1 addition & 1 deletion okhttp/src/main/kotlin/okhttp3/EventListener.kt
Expand Up @@ -457,7 +457,7 @@ abstract class EventListener {
open fun cacheConditionalHit(call: Call, cachedResponse: Response) {
}

interface Factory {
fun interface Factory {
/**
* Creates an instance of the [EventListener] for a particular [Call]. The returned
* [EventListener] instance will be used during the lifecycle of [call].
Expand Down
4 changes: 2 additions & 2 deletions okhttp/src/main/kotlin/okhttp3/Handshake.kt
Expand Up @@ -52,7 +52,7 @@ class Handshake internal constructor(
try {
peerCertificatesFn()
} catch (spue: SSLPeerUnverifiedException) {
listOf<Certificate>()
listOf()
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class Handshake internal constructor(
val peerCertificatesCopy = try {
peerCertificates.toImmutableList()
} catch (_: SSLPeerUnverifiedException) {
listOf<Certificate>()
listOf()
}

return Handshake(tlsVersion, cipherSuite,
Expand Down
6 changes: 2 additions & 4 deletions okhttp/src/main/kotlin/okhttp3/Interceptor.kt
Expand Up @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit
* responses coming back in. Typically interceptors add, remove, or transform headers on the request
* or response.
*/
interface Interceptor {
fun interface Interceptor {
@Throws(IOException::class)
fun intercept(chain: Chain): Response

Expand All @@ -39,9 +39,7 @@ interface Interceptor {
* ```
*/
inline operator fun invoke(crossinline block: (chain: Chain) -> Response): Interceptor =
object : Interceptor {
override fun intercept(chain: Chain) = block(chain)
}
Interceptor { block(it) }
}

interface Chain {
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/kotlin/okhttp3/WebSocket.kt
Expand Up @@ -109,7 +109,7 @@ interface WebSocket {
*/
fun cancel()

interface Factory {
fun interface Factory {
/**
* Creates a new web socket and immediately returns it. Creating a web socket initiates an
* asynchronous process to connect the socket. Once that succeeds or fails, `listener` will be
Expand Down