mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 17:00:14 +08:00
* Create java test. Fix #443 * Typo * gradle-kotlin-dsl
This commit is contained in:
parent
b71fc740ee
commit
22550cafd2
@ -66,6 +66,9 @@ allprojects {
|
||||
}
|
||||
|
||||
subprojects {
|
||||
if (this@subprojects.name == "java-test") {
|
||||
return@subprojects
|
||||
}
|
||||
afterEvaluate {
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
val kotlin =
|
||||
|
40
java-test/build.gradle.kts
Normal file
40
java-test/build.gradle.kts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
|
||||
plugins {
|
||||
java
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(project(":mirai-core"))
|
||||
|
||||
implementation(project(":mirai-serialization"))
|
||||
|
||||
testImplementation(group = "junit", name = "junit", version = "4.12")
|
||||
|
||||
implementation(kotlin("stdlib", null))
|
||||
implementation(kotlin("serialization", null))
|
||||
implementation(kotlin("reflect", null))
|
||||
|
||||
|
||||
implementation(kotlinx("serialization-runtime-common", Versions.Kotlin.serialization))
|
||||
implementation(kotlinx("serialization-protobuf-common", Versions.Kotlin.serialization))
|
||||
implementation(kotlinx("io", Versions.Kotlin.io))
|
||||
implementation(kotlinx("coroutines-io", Versions.Kotlin.coroutinesIo))
|
||||
implementation(kotlinx("coroutines-core-common", Versions.Kotlin.coroutines))
|
||||
|
||||
implementation("org.jetbrains.kotlinx:atomicfu-common:${Versions.Kotlin.atomicFU}")
|
||||
|
||||
implementation(ktor("client-cio", Versions.Kotlin.ktor))
|
||||
implementation(ktor("client-core", Versions.Kotlin.ktor))
|
||||
implementation(ktor("network", Versions.Kotlin.ktor))
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.javatest;
|
||||
|
||||
import kotlin.coroutines.CoroutineContext;
|
||||
import kotlin.coroutines.EmptyCoroutineContext;
|
||||
import kotlinx.coroutines.CoroutineScope;
|
||||
import kotlinx.coroutines.CoroutineScopeKt;
|
||||
import net.mamoe.mirai.event.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleListenerHostTest {
|
||||
@Test
|
||||
public void test() {
|
||||
final SimpleListenerHost host = new SimpleListenerHost() {
|
||||
@EventHandler
|
||||
public void testListen(
|
||||
AbstractEvent event
|
||||
) {
|
||||
System.out.println(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
};
|
||||
CoroutineScope scope = CoroutineScopeKt.CoroutineScope(EmptyCoroutineContext.INSTANCE);
|
||||
Events.registerEvents(scope, host);
|
||||
EventKt.broadcast(new AbstractEvent() {
|
||||
});
|
||||
}
|
||||
}
|
@ -331,9 +331,11 @@ private fun Method.registerEvent(
|
||||
}
|
||||
} else {
|
||||
// java methods
|
||||
|
||||
check(this.parameterCount == 1) {
|
||||
"Illegal method parameter. Only one parameter is required."
|
||||
}
|
||||
val paramType = this.parameters[0].type
|
||||
check(this.parameterCount == 1 && Event::class.java.isAssignableFrom(paramType)) {
|
||||
check(Event::class.java.isAssignableFrom(paramType)) {
|
||||
"Illegal method parameter. Required one exact Event subclass. found $paramType"
|
||||
}
|
||||
when (this.returnType) {
|
||||
@ -347,11 +349,11 @@ private fun Method.registerEvent(
|
||||
if (annotation.ignoreCancelled) {
|
||||
if ((this as? CancellableEvent)?.isCancelled != true) {
|
||||
withContext(Dispatchers.IO) {
|
||||
this@registerEvent.invoke(owner, this)
|
||||
this@registerEvent.invoke(owner, this@subscribeAlways)
|
||||
}
|
||||
}
|
||||
} else withContext(Dispatchers.IO) {
|
||||
this@registerEvent.invoke(owner, this)
|
||||
this@registerEvent.invoke(owner, this@subscribeAlways)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -365,11 +367,11 @@ private fun Method.registerEvent(
|
||||
if (annotation.ignoreCancelled) {
|
||||
if ((this as? CancellableEvent)?.isCancelled != true) {
|
||||
withContext(Dispatchers.IO) {
|
||||
this@registerEvent.invoke(owner, this) as ListeningStatus
|
||||
this@registerEvent.invoke(owner, this@subscribe) as ListeningStatus
|
||||
}
|
||||
} else ListeningStatus.LISTENING
|
||||
} else withContext(Dispatchers.IO) {
|
||||
this@registerEvent.invoke(owner, this) as ListeningStatus
|
||||
this@registerEvent.invoke(owner, this@subscribe) as ListeningStatus
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ rootProject.name = 'mirai'
|
||||
include(':mirai-core')
|
||||
include(':mirai-core-qqandroid')
|
||||
include(':mirai-serialization')
|
||||
include(':java-test')
|
||||
//include(':compatibility-validator') // THIS WILL CAUSE A DEPENDENCY RESOLUTION BUG
|
||||
//include(':java-compatibility-validator')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user