mirror of
https://github.com/tursom/TursomServer.git
synced 2025-01-14 22:30:48 +08:00
update
This commit is contained in:
parent
781c5fb294
commit
1670296122
@ -10,6 +10,8 @@ include("ts-core:ts-delegation")
|
||||
include("ts-core:ts-clone")
|
||||
include("ts-core:ts-mail")
|
||||
include("ts-core:ts-coroutine")
|
||||
include("ts-core:ts-ws-client")
|
||||
include("ts-core:ts-yaml")
|
||||
include("ts-socket")
|
||||
//include("web", "aop", "database", "utils", "utils:xml", "utils:async-http", "web:netty-web")
|
||||
//include("socket", "socket:socket-async")
|
||||
|
@ -5,6 +5,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
api(project(":ts-core"))
|
||||
compileOnly(group = "io.netty", name = "netty-all", version = "4.1.43.Final")
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.utils.bytebuffer
|
||||
package cn.tursom.core.buffer.impl
|
||||
|
||||
import cn.tursom.core.buffer.ByteBuffer
|
||||
import io.netty.buffer.ByteBuf
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.utils.bytebuffer
|
||||
package cn.tursom.core.buffer
|
||||
|
||||
/**
|
||||
* support type:
|
||||
@ -10,7 +10,6 @@ package cn.tursom.utils.bytebuffer
|
||||
*/
|
||||
|
||||
import cn.tursom.core.Unsafe.unsafe
|
||||
import cn.tursom.core.buffer.ByteBuffer
|
||||
import cn.tursom.core.isStatic
|
||||
|
||||
class UnsupportedException : Exception()
|
34
ts-core/ts-ws-client/build.gradle.kts
Normal file
34
ts-core/ts-ws-client/build.gradle.kts
Normal file
@ -0,0 +1,34 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":ts-core"))
|
||||
api(project(":ts-core:ts-buffer"))
|
||||
api(project(":ts-core:ts-log"))
|
||||
api(group = "io.netty", name = "netty-all", version = "4.1.43.Final")
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks)
|
||||
|
||||
tasks.register("install") {
|
||||
finalizedBy(tasks["publishToMavenLocal"])
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
groupId = project.group.toString()
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
|
||||
from(components["java"])
|
||||
try {
|
||||
artifact(tasks["sourcesJar"])
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package cn.tursom.ws
|
||||
|
||||
import cn.tursom.core.buffer.ByteBuffer
|
||||
import cn.tursom.utils.WebSocketFrameWrapper
|
||||
import cn.tursom.utils.bytebuffer.NettyByteBuffer
|
||||
import cn.tursom.core.buffer.impl.NettyByteBuffer
|
||||
import io.netty.bootstrap.Bootstrap
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.buffer.Unpooled
|
@ -1,4 +1,4 @@
|
||||
package cn.tursom.utils
|
||||
package cn.tursom.ws
|
||||
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.buffer.Unpooled
|
@ -1,8 +1,8 @@
|
||||
package cn.tursom.ws
|
||||
|
||||
import cn.tursom.core.buffer.ByteBuffer
|
||||
import cn.tursom.core.buffer.impl.NettyByteBuffer
|
||||
import cn.tursom.core.toUTF8String
|
||||
import cn.tursom.utils.bytebuffer.NettyByteBuffer
|
||||
import io.netty.buffer.ByteBuf
|
||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame
|
||||
import io.netty.handler.codec.http.websocketx.PingWebSocketFrame
|
33
ts-core/ts-yaml/build.gradle.kts
Normal file
33
ts-core/ts-yaml/build.gradle.kts
Normal file
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":ts-core"))
|
||||
// 解析YAML
|
||||
api(group = "org.yaml", name = "snakeyaml", version = "1.28")
|
||||
}
|
||||
|
||||
@kotlin.Suppress("UNCHECKED_CAST")
|
||||
(rootProject.ext["excludeTest"] as (Project, TaskContainer) -> Unit)(project, tasks)
|
||||
|
||||
tasks.register("install") {
|
||||
finalizedBy(tasks["publishToMavenLocal"])
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
groupId = project.group.toString()
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
|
||||
from(components["java"])
|
||||
try {
|
||||
artifact(tasks["sourcesJar"])
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
106
ts-core/ts-yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt
Normal file
106
ts-core/ts-yaml/src/main/kotlin/cn/tursom/yaml/Yaml.kt
Normal file
@ -0,0 +1,106 @@
|
||||
package cn.tursom.yaml
|
||||
|
||||
import cn.tursom.core.Parser
|
||||
import cn.tursom.core.ThreadLocalSimpleDateFormat
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import java.lang.reflect.Modifier
|
||||
import java.util.*
|
||||
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
object Yaml {
|
||||
private val simpleDateFormat = ThreadLocalSimpleDateFormat()
|
||||
private val yaml = Yaml()
|
||||
|
||||
fun toYaml(obj: Any): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
toYaml(obj, stringBuilder, "")
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
private fun toYaml(obj: Any, stringBuilder: StringBuilder, indentation: String, inCollection: Boolean = false) {
|
||||
when (obj) {
|
||||
is Byte -> stringBuilder.append(obj)
|
||||
is Char -> stringBuilder.append(obj)
|
||||
is Short -> stringBuilder.append(obj)
|
||||
is Int -> stringBuilder.append(obj)
|
||||
is Long -> stringBuilder.append(obj)
|
||||
is Float -> stringBuilder.append(obj)
|
||||
is Double -> stringBuilder.append(obj)
|
||||
is Date -> stringBuilder.append(simpleDateFormat.get().format(obj))
|
||||
is String -> when {
|
||||
obj.contains('\n') -> {
|
||||
stringBuilder.append("|${if (obj.endsWith('\n')) '+' else '-'}")
|
||||
obj.split('\n').forEach {
|
||||
stringBuilder.append("$indentation$it")
|
||||
}
|
||||
}
|
||||
obj.startsWith('|') -> stringBuilder.append("\"$obj\"")
|
||||
else -> {
|
||||
stringBuilder.append(obj)
|
||||
}
|
||||
}
|
||||
is Map<*, *> -> {
|
||||
var first = true
|
||||
obj.forEach { (any, u) ->
|
||||
if (inCollection && first) {
|
||||
stringBuilder.append("${any ?: return@forEach}: ")
|
||||
first = false
|
||||
} else {
|
||||
stringBuilder.append("$indentation${any ?: return@forEach}: ")
|
||||
}
|
||||
toYaml(u ?: return@forEach, stringBuilder, "$indentation ")
|
||||
if (!stringBuilder.endsWith('\n')) {
|
||||
stringBuilder.append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
is Collection<*> -> if (obj.isEmpty()) {
|
||||
stringBuilder.append("[]")
|
||||
} else {
|
||||
var appended = 0
|
||||
obj.forEach {
|
||||
it ?: return@forEach
|
||||
stringBuilder.append("${if (appended == 0) "\n" else ""}$indentation- ")
|
||||
appended++
|
||||
toYaml(it, stringBuilder, "$indentation ", true)
|
||||
if (!stringBuilder.endsWith('\n')) {
|
||||
stringBuilder.append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
var first = true
|
||||
fun getIndentation() = if (inCollection && first) {
|
||||
first = false
|
||||
""
|
||||
} else {
|
||||
indentation
|
||||
}
|
||||
obj.javaClass.declaredFields.forEach {
|
||||
if ((it.modifiers and (Modifier.STATIC or Modifier.TRANSIENT)) != 0) return@forEach
|
||||
it.isAccessible = true
|
||||
val value = it.get(obj)
|
||||
stringBuilder.append("${getIndentation()}${it.name}: ")
|
||||
toYaml(value, stringBuilder, "${getIndentation()} ")
|
||||
if (!stringBuilder.endsWith('\n')) {
|
||||
stringBuilder.append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline fun <reified T> parse(yaml: Any) = Parser.parse(yaml, T::class.java)
|
||||
inline fun <reified T> parse(yaml: String) = parse(yaml, T::class.java)
|
||||
inline fun <reified T> parseResource(path: String) = parseResource(path, T::class.java)
|
||||
inline fun <reified T> parseResource(classLoader: ClassLoader, path: String) =
|
||||
parseResource(classLoader, path, T::class.java)
|
||||
|
||||
fun <T> parseResource(path: String, clazz: Class<T>) = parseResource(this.javaClass.classLoader, path, clazz)
|
||||
fun <T> parseResource(classLoader: ClassLoader, path: String, clazz: Class<T>) =
|
||||
Parser.parse(yaml.load(classLoader.getResourceAsStream(path)), clazz)
|
||||
|
||||
fun <T> parse(yaml: String, clazz: Class<T>) = Parser.parse(this.yaml.load(yaml), clazz)
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
dependencies {
|
||||
compile project(":")
|
||||
api project(":log")
|
||||
implementation project(":utils")
|
||||
compile group: "io.netty", name: "netty-all", version: "4.1.43.Final"
|
||||
}
|
Loading…
Reference in New Issue
Block a user