Merge remote-tracking branch 'origin/master'

This commit is contained in:
ryoii 2020-03-29 20:21:14 +08:00
commit b92e3ae64a
14 changed files with 197 additions and 93 deletions

View File

@ -11,8 +11,8 @@ buildscript {
dependencies { dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0' classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-serialization:1.4-M1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4-M1"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' // don't use any other. classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' // don't use any other.
} }
} }

View File

@ -11,9 +11,10 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope
object Versions { object Versions {
object Mirai { object Mirai {
const val core = "0.30.0" const val core = "0.31.0"
const val console = "0.3.6" const val console = "0.3.7"
const val consoleWrapper = "0.1.3" const val consoleGraphical = "0.0.2"
const val consoleWrapper = "0.2.0"
} }
object Kotlin { object Kotlin {

View File

@ -1,21 +1,2 @@
# style guide # style guide
kotlin.code.style=official kotlin.code.style=official
# config
miraiVersion=0.30.0
miraiConsoleVersion=0.3.7
miraiConsoleWrapperVersion=0.1.4
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
# kotlin
kotlinVersion=1.4-M1
# kotlin libraries
serializationVersion=0.20.0-1.4-M1
coroutinesVersion=1.3.5-1.4-M1
atomicFuVersion=0.14.2-1.4-M1
kotlinXIoVersion=0.1.16
coroutinesIoVersion=0.1.16
# utility
ktorVersion=1.3.2-1.4-M1
klockVersion=1.7.0
# gradle plugin
protobufJavaVersion=3.10.0

View File

@ -1,8 +1,13 @@
import Versions.Publishing.bintray
import java.util.*
plugins { plugins {
id("kotlinx-serialization") id("kotlinx-serialization")
id("org.openjfx.javafxplugin") version "0.0.8" id("org.openjfx.javafxplugin") version "0.0.8"
id("kotlin") id("kotlin")
id("java") id("java")
id("com.jfrog.bintray")
`maven-publish`
} }
javafx { javafx {
@ -13,14 +18,37 @@ javafx {
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.github.johnrengelman.shadow")
version = Versions.Mirai.console
/*
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() { tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
manifest { manifest {
attributes["Main-Class"] = "net.mamoe.mirai.console.graphical.MiraiGraphicalLoader" attributes["Main-Class"] = "net.mamoe.mirai.console.graphical.MiraiGraphicalLoader"
} }
} }
*/
version = Versions.Mirai.console
description = "Console Graphical Version with plugin support for mirai"
bintray {
val keyProps = Properties()
val keyFile = file("../keys.properties")
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
user = keyProps.getProperty("bintrayUser")
key = keyProps.getProperty("bintrayKey")
setPublications("mavenJava")
setConfigurations("archives")
pkg.apply {
repo = "mirai"
name = "mirai-console-graphical"
setLicenses("AGPLv3")
publicDownloadNumbers = true
vcsUrl = "https://github.com/mamoe/mirai"
}
}
val kotlinVersion: String by rootProject.ext val kotlinVersion: String by rootProject.ext
val atomicFuVersion: String by rootProject.ext val atomicFuVersion: String by rootProject.ext
@ -37,7 +65,7 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
val miraiVersion: String by rootProject.ext val miraiVersion = Versions.Mirai.core
dependencies { dependencies {
implementation("net.mamoe:mirai-core-jvm:$miraiVersion") implementation("net.mamoe:mirai-core-jvm:$miraiVersion")
@ -54,3 +82,39 @@ dependencies {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "1.8" kotlinOptions.jvmTarget = "1.8"
} }
@Suppress("DEPRECATION")
val sourcesJar by tasks.registering(Jar::class) {
classifier = "sources"
from(sourceSets.main.get().allSource)
}
publishing {
/*
repositories {
maven {
// change to point to your repo, e.g. http://my.org/repo
url = uri("$buildDir/repo")
}
}*/
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])
groupId = rootProject.group.toString()
artifactId = "mirai-console-graphical"
version = Versions.Mirai.consoleGraphical
pom.withXml {
val root = asNode()
root.appendNode("description", description)
root.appendNode("name", project.name)
root.appendNode("url", "https://github.com/mamoe/mirai")
root.children().last()
}
artifact(sourcesJar.get())
}
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.console.graphical
import net.mamoe.mirai.console.pure.MiraiConsoleUIPure
import net.mamoe.mirai.console.MiraiConsole
import tornadofx.launch
import kotlin.concurrent.thread
class MiraiConsoleGraphicalLoader {
companion object {
internal lateinit var coreVersion :String
internal lateinit var consoleVersion: String
@JvmStatic
fun load(
coreVersion: String,
consoleVersion: String
) {
this.coreVersion = coreVersion
this.consoleVersion = consoleVersion
Runtime.getRuntime().addShutdownHook(thread(start = false) {
MiraiConsole.stop()
})
launch<MiraiGraphicalUI>()
}
}
}

View File

@ -27,8 +27,7 @@ class MiraiGraphicalUI : App(Decorator::class, PrimaryStyleSheet::class) {
override fun init() { override fun init() {
super.init() super.init()
MiraiConsole.start(find<MiraiGraphicalUIController>(),MiraiConsoleGraphicalLoader.coreVersion,MiraiConsoleGraphicalLoader.consoleVersion)
MiraiConsole.start(find<MiraiGraphicalUIController>())
} }
override fun stop() { override fun stop() {

View File

@ -31,7 +31,7 @@ fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$v
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
val miraiVersion: String by rootProject.ext val miraiVersion = Versions.Mirai.core
dependencies { dependencies {
implementation("net.mamoe:mirai-core-jvm:$miraiVersion") implementation("net.mamoe:mirai-core-jvm:$miraiVersion")

View File

@ -21,6 +21,11 @@ internal object ConsoleUpdater {
"version" to "/net/mamoe/mirai-console/" "version" to "/net/mamoe/mirai-console/"
) )
) )
put(
CONSOLE_GRAPHICAL, mapOf(
"version" to "/net/mamoe/mirai-console-graphical/"
)
)
} }
} }
@ -33,9 +38,16 @@ internal object ConsoleUpdater {
if (file.name.contains("mirai-console")) { if (file.name.contains("mirai-console")) {
when (consoleType) { when (consoleType) {
CONSOLE_PURE -> { CONSOLE_PURE -> {
if(!file.name.contains("graphical")) {
return file return file
} }
} }
CONSOLE_GRAPHICAL -> {
if(file.name.contains("graphical")) {
return file
}
}
}
} }
} }
} }
@ -57,7 +69,7 @@ internal object ConsoleUpdater {
) )
*/ */
MiraiDownloader.addTask( MiraiDownloader.addTask(
"https://pan.jasonczc.cn/?/mirai/${getProjectName()}/${getProjectName()}-$newest.pdf", getContent("${getProjectName()}-$newest.jar") "https://pan.jasonczc.cn/?/mirai/${getProjectName()}/${getProjectName()}-$newest.mp4", getContent("${getProjectName()}-$newest.jar")
) )
} }
} }
@ -103,7 +115,7 @@ internal object ConsoleUpdater {
return if (consoleType == CONSOLE_PURE) { return if (consoleType == CONSOLE_PURE) {
"mirai-console" "mirai-console"
} else { } else {
"mirai-console-$consoleType" "mirai-console-${consoleType.toLowerCase()}"
} }
} }

View File

@ -38,7 +38,7 @@ internal object CoreUpdater {
println("Updating shadowed-core from V$current -> V$newest, this is a force update") println("Updating shadowed-core from V$current -> V$newest, this is a force update")
this.getProtocolLib()?.delete() this.getProtocolLib()?.delete()
MiraiDownloader MiraiDownloader
.addTask("https://pan.jasonczc.cn/?/mirai/mirai-core-qqandroid/mirai-core-qqandroid-$newest.pdf",getContent("mirai-core-qqandroid-jvm-$newest.jar")) .addTask("https://pan.jasonczc.cn/?/mirai/mirai-core-qqandroid/mirai-core-qqandroid-$newest.mp4",getContent("mirai-core-qqandroid-jvm-$newest.jar"))
//.addTask("https://raw.githubusercontent.com/mamoe/mirai-repo/master/shadow/mirai-core-qqandroid/mirai-core-qqandroid-$newest.jar", getContent("mirai-core-qqandroid-jvm-$newest.jar")) //.addTask("https://raw.githubusercontent.com/mamoe/mirai-repo/master/shadow/mirai-core-qqandroid/mirai-core-qqandroid-$newest.jar", getContent("mirai-core-qqandroid-jvm-$newest.jar"))
} }

View File

@ -161,7 +161,6 @@ class MiraiDownloaderProgressBarInUI(): MiraiDownloadProgressBar{
} }
override fun complete() { override fun complete() {
TODO("Not yet implemented")
} }
} }

View File

@ -7,17 +7,16 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE * https://github.com/mamoe/mirai/blob/master/LICENSE
*/ */
@file:Suppress("EXPERIMENTAL_API_USAGE") @file:Suppress("EXPERIMENTAL_API_USAGE")
package net.mamoe.mirai.console.wrapper package net.mamoe.mirai.console.wrapper
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.awt.Frame
import java.awt.Panel
import java.awt.TextArea import java.awt.TextArea
import java.awt.Toolkit
import java.io.File import java.io.File
import java.lang.StringBuilder
import java.net.URLClassLoader import java.net.URLClassLoader
import java.util.* import java.util.*
import javax.swing.JFrame
import javax.swing.JPanel
val contentPath by lazy { val contentPath by lazy {
@ -31,8 +30,8 @@ val contentPath by lazy {
object WrapperMain { object WrapperMain {
internal var uiBarOutput = StringBuilder() internal var uiBarOutput = StringBuilder()
private val uilog = StringBuilder() private val uilog = StringBuilder()
internal fun uiLog(any: Any?){ internal fun uiLog(any: Any?) {
if(any!=null) { if (any != null) {
uilog.append(any) uilog.append(any)
} }
} }
@ -40,33 +39,27 @@ object WrapperMain {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
gc() gc()
if(args.contains("native") || args.contains("-native")){ if (args.contains("native") || args.contains("-native")) {
val f = JFrame("Mirai-Console Version Check")
val f = Frame("Mirai-Console Version Check") f.setSize(500, 200)
f.setLocationRelativeTo(null)
f.isResizable = false f.isResizable = false
val srcSize= Toolkit.getDefaultToolkit().screenSize
val width = 300 val p = JPanel()
val height = 200
val p = Panel()
val textArea = TextArea()
textArea.isEditable = false
p.add(textArea)
p.isVisible = true
f.setLocation((srcSize.width-width)/2, (srcSize.height-height)/2)
f.setSize(width, height)
f.add(p) f.add(p)
val textArea = TextArea()
p.add(textArea)
textArea.isEditable = false
f.isVisible = true f.isVisible = true
uiLog("正在进行版本检查\n") uiLog("正在进行版本检查\n")
var uiOpen = true var uiOpen = true
GlobalScope.launch { GlobalScope.launch {
while (isActive && uiOpen){ while (isActive && uiOpen) {
delay(16)//60 fps delay(16)//60 fps
withContext(Dispatchers.Main){ withContext(Dispatchers.Main) {
textArea.text = uilog.toString() + "\n" + uiBarOutput.toString() textArea.text = uilog.toString() + "\n" + uiBarOutput.toString()
} }
} }
@ -85,25 +78,25 @@ object WrapperMain {
} }
start(CONSOLE_GRAPHICAL) start(CONSOLE_GRAPHICAL)
}else{ } else {
preStartInNonNative() preStartInNonNative()
} }
} }
private fun preStartInNonNative(){ private fun preStartInNonNative() {
println("You are running Mirai-Console-Wrapper under " + System.getProperty("user.dir")) println("You are running Mirai-Console-Wrapper under " + System.getProperty("user.dir"))
var type = WrapperProperties.determineConsoleType(WrapperProperties.content) var type = WrapperProperties.determineConsoleType(WrapperProperties.content)
if(type!=null){ if (type != null) {
println("Starting Mirai Console $type, reset by clear /content/") println("Starting Mirai Console $type, reset by clear /content/")
}else{ } else {
println("Please select Console Type") println("Please select Console Type")
println("请选择 Console 版本") println("请选择 Console 版本")
println("=> Pure : pure console") println("=> Pure : pure console")
println("=> Graphical : [Not Supported Yet] graphical UI except unix") println("=> Graphical : graphical UI except unix")
println("=> Terminal : [Not Supported Yet] console in unix") println("=> Terminal : [Not Supported Yet] console in unix")
val scanner = Scanner(System.`in`) val scanner = Scanner(System.`in`)
while (type == null){ while (type == null) {
var input = scanner.next() var input = scanner.next()
input = input.toUpperCase()[0] + input.toLowerCase().substring(1) input = input.toUpperCase()[0] + input.toLowerCase().substring(1)
println("Selecting $input") println("Selecting $input")
@ -133,11 +126,11 @@ object WrapperMain {
start(type) start(type)
} }
private fun start(type: String){ private fun start(type: String) {
val loader = MiraiClassLoader( val loader = MiraiClassLoader(
CoreUpdater.getProtocolLib()!!, CoreUpdater.getProtocolLib()!!,
ConsoleUpdater.getFile()!!, ConsoleUpdater.getFile()!!,
this.javaClass.classLoader null
) )
loader.loadClass("net.mamoe.mirai.BotFactoryJvm") loader.loadClass("net.mamoe.mirai.BotFactoryJvm")
@ -149,26 +142,33 @@ object WrapperMain {
).getMethod("load", String::class.java, String::class.java) ).getMethod("load", String::class.java, String::class.java)
.invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion()) .invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion())
} }
CONSOLE_GRAPHICAL -> {
loader.loadClass(
"net.mamoe.mirai.console.graphical.MiraiConsoleGraphicalLoader"
).getMethod("load", String::class.java, String::class.java)
.invoke(null, CoreUpdater.getCurrentVersion(), ConsoleUpdater.getCurrentVersion())
}
} }
} }
} }
private class MiraiClassLoader( private class MiraiClassLoader(
protocol: File, protocol: File,
console: File, console: File,
parent: ClassLoader parent: ClassLoader?
): URLClassLoader(arrayOf( ) : URLClassLoader(
arrayOf(
protocol.toURI().toURL(), protocol.toURI().toURL(),
console.toURI().toURL() console.toURI().toURL()
), parent) ), parent
)
private object WrapperProperties{ private object WrapperProperties {
val contentFile by lazy{ val contentFile by lazy {
File(contentPath.absolutePath + "/.wrapper.txt").also { File(contentPath.absolutePath + "/.wrapper.txt").also {
if(!it.exists())it.createNewFile() if (!it.exists()) it.createNewFile()
} }
} }
@ -179,18 +179,18 @@ private object WrapperProperties{
fun determineConsoleType( fun determineConsoleType(
type: String type: String
):String?{ ): String? {
if(type == CONSOLE_PURE || type == CONSOLE_GRAPHICAL || type == CONSOLE_TERMINAL){ if (type == CONSOLE_PURE || type == CONSOLE_GRAPHICAL || type == CONSOLE_TERMINAL) {
return type return type
} }
return null return null
} }
} }
private fun gc(){ private fun gc() {
GlobalScope.launch{ GlobalScope.launch {
while (true) { while (true) {
delay(1000*60*5) delay(1000 * 60 * 5)
System.gc() System.gc()
} }
} }

View File

@ -1,4 +1,5 @@
import java.util.* import java.util.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") kotlin("jvm")
@ -28,10 +29,16 @@ dependencies {
implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62") implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62")
implementation(group = "org.yaml", name = "snakeyaml", version = "1.25") implementation(group = "org.yaml", name = "snakeyaml", version = "1.25")
implementation(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2") implementation(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
implementation(kotlin("stdlib-jdk8"))
testApi(ktor("client-cio", Versions.Kotlin.ktor))
testApi(ktor("client-core", Versions.Kotlin.ktor))
testApi(ktor("network", Versions.Kotlin.ktor))
testApi("org.jsoup:jsoup:1.12.1")
} }
val miraiConsoleVersion: String by project.ext version = Versions.Mirai.console
version = miraiConsoleVersion
description = "Console with plugin support for mirai" description = "Console with plugin support for mirai"
bintray { bintray {
@ -74,7 +81,7 @@ publishing {
groupId = rootProject.group.toString() groupId = rootProject.group.toString()
artifactId = "mirai-console" artifactId = "mirai-console"
version = miraiConsoleVersion version = version
pom.withXml { pom.withXml {
val root = asNode() val root = asNode()
@ -88,3 +95,15 @@ publishing {
} }
} }
} }
repositories {
maven("https://dl.bintray.com/kotlin/kotlin-eap")
mavenCentral()
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

View File

@ -18,7 +18,6 @@ import net.mamoe.mirai.console.command.DefaultCommands
import net.mamoe.mirai.console.plugins.PluginManager import net.mamoe.mirai.console.plugins.PluginManager
import net.mamoe.mirai.console.utils.MiraiConsoleUI import net.mamoe.mirai.console.utils.MiraiConsoleUI
import net.mamoe.mirai.utils.SimpleLogger.LogPriority import net.mamoe.mirai.utils.SimpleLogger.LogPriority
import net.mamoe.mirai.utils.cryptor.ECDH
import net.mamoe.mirai.utils.io.encodeToString import net.mamoe.mirai.utils.io.encodeToString
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
import java.io.PrintStream import java.io.PrintStream
@ -83,13 +82,6 @@ object MiraiConsole {
logger("Mirai为开源项目请自觉遵守开源项目协议") logger("Mirai为开源项目请自觉遵守开源项目协议")
logger("Powered by Mamoe Technologies and contributors") logger("Powered by Mamoe Technologies and contributors")
/* 加载ECDH */
try {
ECDH()
} catch (ignored: Exception) {
}
//Security.removeProvider("BC")
/* 依次启用功能 */ /* 依次启用功能 */
DefaultCommands() DefaultCommands()
PluginManager.loadPlugins() PluginManager.loadPlugins()

View File

@ -16,6 +16,8 @@ pluginManagement {
mavenCentral() mavenCentral()
maven { url "https://plugins.gradle.org/m2/" } maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" } maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url 'https://plugins.gradle.org/m2/' }
} }
} }