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 {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.kotlin:kotlin-serialization:1.4-M1"
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.
}
}

View File

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

View File

@ -1,21 +1,2 @@
# style guide
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 {
id("kotlinx-serialization")
id("org.openjfx.javafxplugin") version "0.0.8"
id("kotlin")
id("java")
id("com.jfrog.bintray")
`maven-publish`
}
javafx {
@ -13,14 +18,37 @@ javafx {
apply(plugin = "com.github.johnrengelman.shadow")
version = Versions.Mirai.console
/*
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
manifest {
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 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"
val miraiVersion: String by rootProject.ext
val miraiVersion = Versions.Mirai.core
dependencies {
implementation("net.mamoe:mirai-core-jvm:$miraiVersion")
@ -54,3 +82,39 @@ dependencies {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
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() {
super.init()
MiraiConsole.start(find<MiraiGraphicalUIController>())
MiraiConsole.start(find<MiraiGraphicalUIController>(),MiraiConsoleGraphicalLoader.coreVersion,MiraiConsoleGraphicalLoader.consoleVersion)
}
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"
val miraiVersion: String by rootProject.ext
val miraiVersion = Versions.Mirai.core
dependencies {
implementation("net.mamoe:mirai-core-jvm:$miraiVersion")

View File

@ -21,6 +21,11 @@ internal object ConsoleUpdater {
"version" to "/net/mamoe/mirai-console/"
)
)
put(
CONSOLE_GRAPHICAL, mapOf(
"version" to "/net/mamoe/mirai-console-graphical/"
)
)
}
}
@ -33,7 +38,14 @@ internal object ConsoleUpdater {
if (file.name.contains("mirai-console")) {
when (consoleType) {
CONSOLE_PURE -> {
return file
if(!file.name.contains("graphical")) {
return file
}
}
CONSOLE_GRAPHICAL -> {
if(file.name.contains("graphical")) {
return file
}
}
}
}
@ -57,7 +69,7 @@ internal object ConsoleUpdater {
)
*/
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) {
"mirai-console"
} 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")
this.getProtocolLib()?.delete()
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"))
}

View File

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

View File

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

View File

@ -1,4 +1,5 @@
import java.util.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
@ -28,10 +29,16 @@ dependencies {
implementation(group = "com.alibaba", name = "fastjson", version = "1.2.62")
implementation(group = "org.yaml", name = "snakeyaml", version = "1.25")
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 = miraiConsoleVersion
version = Versions.Mirai.console
description = "Console with plugin support for mirai"
bintray {
@ -74,7 +81,7 @@ publishing {
groupId = rootProject.group.toString()
artifactId = "mirai-console"
version = miraiConsoleVersion
version = version
pom.withXml {
val root = asNode()
@ -87,4 +94,16 @@ publishing {
artifact(sourcesJar.get())
}
}
}
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.utils.MiraiConsoleUI
import net.mamoe.mirai.utils.SimpleLogger.LogPriority
import net.mamoe.mirai.utils.cryptor.ECDH
import net.mamoe.mirai.utils.io.encodeToString
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@ -83,13 +82,6 @@ object MiraiConsole {
logger("Mirai为开源项目请自觉遵守开源项目协议")
logger("Powered by Mamoe Technologies and contributors")
/* 加载ECDH */
try {
ECDH()
} catch (ignored: Exception) {
}
//Security.removeProvider("BC")
/* 依次启用功能 */
DefaultCommands()
PluginManager.loadPlugins()

View File

@ -16,6 +16,8 @@ pluginManagement {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
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/' }
}
}