Skip to content

Commit

Permalink
Testing with kotlin 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed May 3, 2020
1 parent 80bee1a commit 6478137
Show file tree
Hide file tree
Showing 34 changed files with 121 additions and 84 deletions.
36 changes: 22 additions & 14 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,7 +15,7 @@ buildscript {
'jnrUnixsocket': '0.28',
'jsoup': '1.13.1',
'junit': '4.13',
'kotlin': '1.3.71',
'kotlin': '1.4-M1',
'moshi': '1.9.2',
'okio': '2.6.0',
'ktlint': '0.36.0',
Expand All @@ -39,7 +39,7 @@ 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-M1",
'moshi': "com.squareup.moshi:moshi:${versions.moshi}",
'moshiKotlin': "com.squareup.moshi:moshi-kotlin-codegen:${versions.moshi}",
'okio': "com.squareup.okio:okio:${versions.okio}",
Expand All @@ -48,7 +48,7 @@ buildscript {

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-M1"
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'
Expand All @@ -58,6 +58,9 @@ buildscript {
mavenCentral()
gradlePluginPortal()
google()
maven {
url = "https://dl.bintray.com/kotlin/kotlin-eap/"
}
}
}

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-eap/"
}
}

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

apply plugin: "kotlin"
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'
// TODO raise issue
// apply plugin: 'net.ltgt.errorprone'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'com.diffplug.gradle.spotless'
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -205,20 +213,20 @@ subprojects { project ->
}
}

dependencies {
// dependencies {
//noinspection GradleDynamicVersion
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
}
// errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'
// errorprone 'com.google.errorprone:error_prone_core:2.3.4'
// }
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", CheckSeverity.ERROR)
// check("MissingOverride", 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 @@ -161,11 +161,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,17 +104,13 @@ class HttpLoggingInterceptor @JvmOverloads constructor(
BODY
}

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

companion object {
/** A [Logger] defaults output appropriate for the current platform. */
@JvmField
val DEFAULT: Logger = object : Logger {
override fun log(message: String) {
Platform.get().log(message)
}
}
val DEFAULT: Logger = Logger { Platform.get().log(it) }
}
}

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) {
}
}
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
9 changes: 3 additions & 6 deletions okhttp-sse/src/main/kotlin/okhttp3/sse/EventSources.kt
Expand Up @@ -16,18 +16,15 @@
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 {
return RealEventSource(request, listener).apply {
connect(client)
}
return EventSource.Factory { request, listener ->
RealEventSource(request, listener).apply {
connect(client)
}
}
}
Expand Down
Expand Up @@ -39,14 +39,11 @@ class OkHttpClientTestRule : TestRule {
private var uncaughtException: Throwable? = null
var logger: Logger? = null

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 @@ -62,9 +59,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 @@ -125,7 +125,7 @@ open class RecordingEventListener : EventListener() {
for (lock in forbiddenLocks) {
assertThat(Thread.holdsLock(lock))
.overridingErrorMessage(lock.toString())
.isFalse()
.isFalse
}

val startEvent = e.closes(-1L)
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/kotlin/okhttp3/Authenticator.kt
Expand Up @@ -96,7 +96,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
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 @@ -422,7 +422,7 @@ abstract class EventListener {
) {
}

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
15 changes: 6 additions & 9 deletions okhttp/src/main/kotlin/okhttp3/internal/Util.kt
Expand Up @@ -29,7 +29,6 @@ import java.nio.charset.Charset
import java.nio.charset.StandardCharsets.UTF_16BE
import java.nio.charset.StandardCharsets.UTF_16LE
import java.nio.charset.StandardCharsets.UTF_8
import java.util.Arrays
import java.util.Collections
import java.util.Comparator
import java.util.LinkedHashMap
Expand Down Expand Up @@ -299,9 +298,7 @@ fun HttpUrl.canReuseConnectionFor(other: HttpUrl): Boolean = host == other.host
port == other.port &&
scheme == other.scheme

fun EventListener.asFactory() = object : EventListener.Factory {
override fun create(call: Call): EventListener = this@asFactory
}
fun EventListener.asFactory() = EventListener.Factory { this }

infix fun Byte.and(mask: Int): Int = toInt() and mask
infix fun Short.and(mask: Int): Int = toInt() and mask
Expand Down Expand Up @@ -377,18 +374,18 @@ fun Socket.peerName(): String {
* @param source the source used to read bytes from the socket.
*/
fun Socket.isHealthy(source: BufferedSource): Boolean {
try {
return try {
val readTimeout = soTimeout
try {
soTimeout = 1
return !source.exhausted()
!source.exhausted()
} finally {
soTimeout = readTimeout
}
} catch (_: SocketTimeoutException) {
return true // Read timed out; socket is good.
true // Read timed out; socket is good.
} catch (_: IOException) {
return false // Couldn't read; socket is closed.
false // Couldn't read; socket is closed.
}
}

Expand Down Expand Up @@ -472,7 +469,7 @@ fun <T> List<T>.toImmutableList(): List<T> {
/** Returns an immutable list containing [elements]. */
@SafeVarargs
fun <T> immutableListOf(vararg elements: T): List<T> {
return Collections.unmodifiableList(Arrays.asList(*elements.clone()))
return Collections.unmodifiableList(listOf(*elements.clone()))
}

/** Returns an immutable copy of this. */
Expand Down
Expand Up @@ -737,10 +737,10 @@ class Http2Connection internal constructor(builder: Builder) : Closeable {
synchronized(writer) {
synchronized(this@Http2Connection) {
val previousPeerSettings = peerSettings
if (clearPrevious) {
newPeerSettings = settings
newPeerSettings = if (clearPrevious) {
settings
} else {
newPeerSettings = Settings().apply {
Settings().apply {
merge(previousPeerSettings)
merge(settings)
}
Expand Down
Expand Up @@ -74,7 +74,7 @@ class Http2Reader(
}
} else {
// The server reads the CONNECTION_PREFACE byte string.
val connectionPreface = source.readByteString(Http2.CONNECTION_PREFACE.size.toLong())
val connectionPreface = source.readByteString(CONNECTION_PREFACE.size.toLong())
if (logger.isLoggable(FINE)) logger.fine(format("<< CONNECTION ${connectionPreface.hex()}"))
if (CONNECTION_PREFACE != connectionPreface) {
throw IOException("Expected a connection header but was ${connectionPreface.utf8()}")
Expand Down
Expand Up @@ -48,7 +48,7 @@ class BouncyCastlePlatform private constructor() : Platform() {
return trustManagers[0] as X509TrustManager
}

public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? =
override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? =
throw UnsupportedOperationException(
"clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with BouncyCastle")

Expand Down
Expand Up @@ -53,7 +53,7 @@ open class Jdk9Platform : Platform() {
}
}

public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? {
override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? {
// Not supported due to access checks on JDK 9+:
// java.lang.reflect.InaccessibleObjectException: Unable to make member of class
// sun.security.ssl.SSLSocketFactoryImpl accessible: module java.base does not export
Expand Down
Expand Up @@ -50,7 +50,7 @@ class OpenJSSEPlatform private constructor() : Platform() {
return trustManagers[0] as X509TrustManager
}

public override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? =
override fun trustManager(sslSocketFactory: SSLSocketFactory): X509TrustManager? =
throw UnsupportedOperationException(
"clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with OpenJSSE")

Expand Down

0 comments on commit 6478137

Please sign in to comment.