Update to Kotlin 1.4-M1

This commit is contained in:
Him188 2020-03-24 10:01:03 +08:00
parent f2bd321838
commit eb7afb6cff
9 changed files with 165 additions and 134 deletions

View File

@ -5,26 +5,22 @@ buildscript {
repositories {
mavenLocal()
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
jcenter()
// mavenCentral()
google()
// maven (url="https://dl.bintray.com/kotlin/kotlin-eap")
}
dependencies {
val kotlinVersion: String by project
val atomicFuVersion: String by project
classpath("com.android.tools.build:gradle:3.5.3")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
// classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFuVersion")
classpath("com.android.tools.build:gradle:${Versions.Android.androidGradlePlugin}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.Kotlin.atomicFU}")
}
}
plugins {
id("org.jetbrains.dokka") version "0.10.1" apply false
id("org.jetbrains.dokka") version Versions.Kotlin.dokka apply false
id("com.jfrog.bintray") version Versions.Publishing.bintray apply false
}
runCatching {
@ -43,11 +39,9 @@ allprojects {
version = getProperty("miraiVersion")
repositories {
mavenLocal()
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
jcenter()
// mavenCentral()
google()
// maven (url="https://dl.bintray.com/kotlin/kotlin-eap")
}
}

View File

@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}

View File

@ -0,0 +1,42 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
object Versions {
object Mirai {
const val version = "0.30.0"
}
object Kotlin {
const val stdlib = "1.4-M1"
const val coroutines = "1.3.5-1.4-M1"
const val atomicFU = "0.14.2-1.4-M1"
const val serialization = "0.20.0-1.4-M1"
const val ktor = "1.3.2-1.4-M1"
const val io = "0.1.16"
const val coroutinesIo = "0.1.16"
const val dokka = "0.10.1"
}
object Android {
const val androidGradlePlugin = "3.5.3"
}
object Publishing {
const val bintray = "1.8.4-jetbrains-3"
}
}
@Suppress("unused")
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
@Suppress("unused")
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"

View File

@ -7,11 +7,6 @@ plugins {
description = "Binary and source compatibility validator for mirai-core and mirai-core-qqandroid"
val kotlinVersion: String by rootProject.ext
val coroutinesVersion: String by rootProject.ext
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
kotlin {
sourceSets {
all {
@ -23,7 +18,7 @@ kotlin {
dependencies {
api(kotlin("stdlib"))
api(project(":mirai-core-qqandroid"))
api(kotlinx("coroutines-core", coroutinesVersion))
api(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
}
}
}

View File

@ -1,16 +1,5 @@
# style guide
kotlin.code.style=official
# config
miraiVersion=0.29.1
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
# kotlin
kotlinVersion=1.3.70
# kotlin libraries
serializationVersion=0.20.0
coroutinesVersion=1.3.4
atomicFuVersion=0.14.1
kotlinXIoVersion=0.1.16
coroutinesIoVersion=0.1.16
# utility
ktorVersion=1.3.2
kotlin.parallel.tasks.in.project=true

View File

@ -3,34 +3,15 @@
plugins {
kotlin("multiplatform")
id("kotlinx-atomicfu")
id("kotlinx-serialization")
kotlin("plugin.serialization")
`maven-publish`
id("com.jfrog.bintray") version "1.8.4-jetbrains-3"
id("com.jfrog.bintray")
}
val kotlinVersion: String by rootProject.ext
val atomicFuVersion: String by rootProject.ext
val coroutinesVersion: String by rootProject.ext
val kotlinXIoVersion: String by rootProject.ext
val coroutinesIoVersion: String by rootProject.ext
val ktorVersion: String by rootProject.ext
val serializationVersion: String by rootProject.ext
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
description = "QQ protocol library"
val isAndroidSDKAvailable: Boolean by project
val miraiVersion: String by project
version = miraiVersion
kotlin {
if (isAndroidSDKAvailable) {
apply(from = rootProject.file("gradle/android.gradle"))
@ -58,30 +39,29 @@ kotlin {
sourceSets {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
dependencies {
api(project(":mirai-core"))
api(kotlin("stdlib", kotlinVersion))
api("org.jetbrains.kotlinx:atomicfu:$atomicFuVersion")
api(kotlinx("io", kotlinXIoVersion))
api(kotlinx("coroutines-io", coroutinesIoVersion))
api(kotlinx("coroutines-core", coroutinesVersion))
}
}
commonMain {
dependencies {
api(kotlinx("serialization-runtime-common", serializationVersion))
api(kotlinx("serialization-protobuf-common", serializationVersion))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(kotlinx("serialization-runtime-common", Versions.Kotlin.serialization))
api(kotlinx("serialization-protobuf-common", Versions.Kotlin.serialization))
api("org.jetbrains.kotlinx:atomicfu:${Versions.Kotlin.atomicFU}")
api(kotlinx("io", Versions.Kotlin.io))
api(kotlinx("coroutines-io", Versions.Kotlin.coroutinesIo))
api(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
}
}
commonTest {
dependencies {
api(kotlin("test-annotations-common"))
api(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation(kotlin("test-common"))
implementation(kotlin("script-runtime"))
}
}
@ -89,14 +69,14 @@ kotlin {
if (isAndroidSDKAvailable) {
val androidMain by getting {
dependencies {
api(kotlinx("serialization-protobuf", serializationVersion))
api(kotlinx("serialization-protobuf", Versions.Kotlin.serialization))
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test", kotlinVersion))
implementation(kotlin("test-junit", kotlinVersion))
implementation(kotlin("test", Versions.Kotlin.stdlib))
implementation(kotlin("test-junit", Versions.Kotlin.stdlib))
implementation(kotlin("test-annotations-common"))
implementation(kotlin("test-common"))
}
@ -106,16 +86,16 @@ kotlin {
val jvmMain by getting {
dependencies {
runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
api(kotlinx("serialization-runtime", serializationVersion))
//api(kotlinx("serialization-protobuf", serializationVersion))
api(kotlinx("serialization-runtime", Versions.Kotlin.serialization))
//api(kotlinx("serialization-protobuf", Versions.Kotlin.serialization))
}
}
val jvmTest by getting {
dependencies {
api(kotlin("test", kotlinVersion))
api(kotlin("test-junit", kotlinVersion))
implementation(kotlin("test", Versions.Kotlin.stdlib))
implementation(kotlin("test-junit", Versions.Kotlin.stdlib))
implementation("org.pcap4j:pcap4j-distribution:1.8.2")
runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
@ -124,9 +104,5 @@ kotlin {
}
}
}
//
//tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
// kotlinOptions.jvmTarget = "1.8"
//}
apply(from = rootProject.file("gradle/publish.gradle"))

View File

@ -3,35 +3,16 @@
plugins {
kotlin("multiplatform")
id("kotlinx-atomicfu")
id("kotlinx-serialization")
kotlin("plugin.serialization")
id("org.jetbrains.dokka")
`maven-publish`
id("com.jfrog.bintray") version "1.8.4-jetbrains-3"
id("com.jfrog.bintray")
}
val kotlinVersion: String by rootProject.ext
val atomicFuVersion: String by rootProject.ext
val coroutinesVersion: String by rootProject.ext
val kotlinXIoVersion: String by rootProject.ext
val coroutinesIoVersion: String by rootProject.ext
val ktorVersion: String by rootProject.ext
val serializationVersion: String by rootProject.ext
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
description = "QQ protocol library"
val isAndroidSDKAvailable: Boolean by project
val miraiVersion: String by project
version = miraiVersion
kotlin {
if (isAndroidSDKAvailable) {
apply(from = rootProject.file("gradle/android.gradle"))
@ -63,22 +44,22 @@ kotlin {
commonMain {
dependencies {
api(kotlin("stdlib", kotlinVersion))
api(kotlin("serialization", kotlinVersion))
api(kotlin("reflect", kotlinVersion))
api(kotlin("stdlib"))
api(kotlin("serialization"))
api(kotlin("reflect"))
api(kotlinx("coroutines-core-common", coroutinesVersion))
api(kotlinx("serialization-runtime-common", serializationVersion))
api(kotlinx("serialization-protobuf-common", serializationVersion))
api(kotlinx("io", kotlinXIoVersion))
api(kotlinx("coroutines-io", coroutinesIoVersion))
api(kotlinx("coroutines-core", coroutinesVersion))
api(kotlinx("coroutines-core-common", Versions.Kotlin.coroutines))
api(kotlinx("serialization-runtime-common", Versions.Kotlin.serialization))
api(kotlinx("serialization-protobuf-common", Versions.Kotlin.serialization))
api(kotlinx("io", Versions.Kotlin.io))
api(kotlinx("coroutines-io", Versions.Kotlin.coroutinesIo))
api(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
api("org.jetbrains.kotlinx:atomicfu-common:$atomicFuVersion")
api("org.jetbrains.kotlinx:atomicfu-common:${Versions.Kotlin.atomicFU}")
api(ktor("client-cio", ktorVersion))
api(ktor("client-core", ktorVersion))
api(ktor("network", ktorVersion))
api(ktor("client-cio", Versions.Kotlin.ktor))
api(ktor("client-core", Versions.Kotlin.ktor))
api(ktor("network", Versions.Kotlin.ktor))
}
}
commonTest {
@ -91,22 +72,22 @@ kotlin {
if (isAndroidSDKAvailable) {
val androidMain by getting {
dependencies {
api(kotlin("reflect", kotlinVersion))
api(kotlin("reflect"))
api(kotlinx("io-jvm", kotlinXIoVersion))
api(kotlinx("serialization-runtime", serializationVersion))
api(kotlinx("serialization-protobuf", serializationVersion))
api(kotlinx("coroutines-android", coroutinesVersion))
api(kotlinx("coroutines-io-jvm", coroutinesIoVersion))
api(kotlinx("io-jvm", Versions.Kotlin.io))
api(kotlinx("serialization-runtime", Versions.Kotlin.serialization))
api(kotlinx("serialization-protobuf", Versions.Kotlin.serialization))
api(kotlinx("coroutines-android", Versions.Kotlin.coroutines))
api(kotlinx("coroutines-io-jvm", Versions.Kotlin.coroutinesIo))
api(ktor("client-android", ktorVersion))
api(ktor("client-android", Versions.Kotlin.ktor))
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test", kotlinVersion))
implementation(kotlin("test-junit", kotlinVersion))
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation(kotlin("test-annotations-common"))
implementation(kotlin("test-common"))
}
@ -115,16 +96,16 @@ kotlin {
val jvmMain by getting {
dependencies {
//api(kotlin("stdlib-jdk8", kotlinVersion))
//api(kotlin("stdlib-jdk7", kotlinVersion))
api(kotlin("reflect", kotlinVersion))
//api(kotlin("stdlib-jdk8"))
//api(kotlin("stdlib-jdk7"))
api(kotlin("reflect"))
api(ktor("client-core-jvm", ktorVersion))
api(kotlinx("io-jvm", kotlinXIoVersion))
api(kotlinx("serialization-runtime", serializationVersion))
api(kotlinx("serialization-protobuf", serializationVersion))
api(kotlinx("coroutines-io-jvm", coroutinesIoVersion))
api(kotlinx("coroutines-core", coroutinesVersion))
api(ktor("client-core-jvm", Versions.Kotlin.ktor))
api(kotlinx("io-jvm", Versions.Kotlin.io))
api(kotlinx("serialization-runtime", Versions.Kotlin.serialization))
api(kotlinx("serialization-protobuf", Versions.Kotlin.serialization))
api(kotlinx("coroutines-io-jvm", Versions.Kotlin.coroutinesIo))
api(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
api("org.bouncycastle:bcprov-jdk15on:1.64")
runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE
@ -133,8 +114,8 @@ kotlin {
val jvmTest by getting {
dependencies {
implementation(kotlin("test", kotlinVersion))
implementation(kotlin("test-junit", kotlinVersion))
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
implementation("org.pcap4j:pcap4j-distribution:1.8.2")
runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
@ -142,10 +123,7 @@ kotlin {
}
}
}
//
//tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
// kotlinOptions.jvmTarget = "1.8"
//}
tasks {
val dokka by getting(org.jetbrains.dokka.gradle.DokkaTask::class) {
outputFormat = "html"

View File

@ -1,6 +1,10 @@
package net.mamoe.mirai.event.internal
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.utils.LockFreeLinkedList
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass
internal actual class MiraiAtomicBoolean actual constructor(initial: Boolean) {
private val delegate: AtomicBoolean = AtomicBoolean(initial)
@ -14,4 +18,25 @@ internal actual class MiraiAtomicBoolean actual constructor(initial: Boolean) {
set(value) {
delegate.set(value)
}
}
internal actual class EventListeners<E : Event> actual constructor(clazz: KClass<E>) :
LockFreeLinkedList<Listener<E>>() {
@Suppress("UNCHECKED_CAST", "UNSUPPORTED", "NO_REFLECTION_IN_CLASS_PATH")
actual val supertypes: Set<KClass<out Event>> by lazy {
val supertypes = mutableSetOf<KClass<out Event>>()
fun addSupertypes(clazz: KClass<out Event>) {
clazz.supertypes.forEach {
val classifier = it.classifier as? KClass<out Event>
if (classifier != null) {
supertypes.add(classifier)
addSupertypes(classifier)
}
}
}
addSupertypes(clazz)
supertypes
}
}

View File

@ -1,6 +1,10 @@
package net.mamoe.mirai.event.internal
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.Listener
import net.mamoe.mirai.utils.LockFreeLinkedList
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.reflect.KClass
internal actual class MiraiAtomicBoolean actual constructor(initial: Boolean) {
@ -15,4 +19,25 @@ internal actual class MiraiAtomicBoolean actual constructor(initial: Boolean) {
set(value) {
delegate.set(value)
}
}
internal actual class EventListeners<E : Event> actual constructor(clazz: KClass<E>) :
LockFreeLinkedList<Listener<E>>() {
@Suppress("UNCHECKED_CAST", "UNSUPPORTED", "NO_REFLECTION_IN_CLASS_PATH")
actual val supertypes: Set<KClass<out Event>> by lazy {
val supertypes = mutableSetOf<KClass<out Event>>()
fun addSupertypes(clazz: KClass<out Event>) {
clazz.supertypes.forEach {
val classifier = it.classifier as? KClass<out Event>
if (classifier != null) {
supertypes.add(classifier)
addSupertypes(classifier)
}
}
}
addSupertypes(clazz)
supertypes
}
}