mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 10:30:13 +08:00
Improve service finding
- Close resource stream - Skip comments
This commit is contained in:
parent
825332abfe
commit
0fa67b7699
@ -14,7 +14,6 @@ package net.mamoe.mirai.console.internal.util
|
||||
import net.mamoe.mirai.console.internal.data.cast
|
||||
import net.mamoe.mirai.console.internal.data.createInstanceOrNull
|
||||
import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl
|
||||
import java.io.InputStream
|
||||
import java.lang.reflect.Modifier
|
||||
import java.util.*
|
||||
import kotlin.reflect.KClass
|
||||
@ -30,9 +29,13 @@ internal object PluginServiceHelper {
|
||||
|
||||
fun <T : Any> ClassLoader.findServices(vararg serviceTypes: KClass<out T>): ServiceList<T> =
|
||||
serviceTypes.flatMap { serviceType ->
|
||||
getResourceAsStream("META-INF/services/" + serviceType.qualifiedName!!)
|
||||
?.use(InputStream::readBytes)
|
||||
?.let(::String)?.lines()?.filter(String::isNotBlank).orEmpty()
|
||||
getResourceAsStream("META-INF/services/" + serviceType.qualifiedName!!)?.let { stream ->
|
||||
stream.bufferedReader().useLines { lines ->
|
||||
lines.filter(String::isNotBlank)
|
||||
.filter { it[0] != '#' }
|
||||
.toList()
|
||||
}
|
||||
}.orEmpty()
|
||||
}.let { ServiceList(this, it) }
|
||||
|
||||
fun <T : Any> ServiceList<T>.loadAllServices(): List<T> {
|
||||
|
Loading…
Reference in New Issue
Block a user