mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 10:30:13 +08:00
dynamic load libs
This commit is contained in:
parent
daffe2c9d6
commit
35659f750c
@ -14,13 +14,12 @@ object ConsoleUpdator{
|
|||||||
private object Links:HashMap<String,Map<String,String>>() {
|
private object Links:HashMap<String,Map<String,String>>() {
|
||||||
init {
|
init {
|
||||||
put(CONSOLE_PURE, mapOf(
|
put(CONSOLE_PURE, mapOf(
|
||||||
"version" to "/net/mamoe/mirai-console/",
|
"version" to "/net/mamoe/mirai-console/"
|
||||||
"jcenter" to "https://jcenter.bintray.com/net/mamoe/mirai-console/{version}/:mirai-console-{version}.jar",
|
|
||||||
"aliyun" to "https://maven.aliyun.com/nexus/content/repositories/jcenter/net/mamoe/mirai-console/{version}/mirai-console-{version}.jar"
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var consoleType = CONSOLE_PURE
|
var consoleType = CONSOLE_PURE
|
||||||
|
|
||||||
fun getFile():File?{
|
fun getFile():File?{
|
||||||
@ -102,7 +101,8 @@ object ConsoleUpdator{
|
|||||||
Http.downloadMavenArchive("net/mamoe",getProjectName(),version)
|
Http.downloadMavenArchive("net/mamoe",getProjectName(),version)
|
||||||
.saveToContent("${getProjectName()}-$version.jar")
|
.saveToContent("${getProjectName()}-$version.jar")
|
||||||
}
|
}
|
||||||
|
LibManager.clearLibs()
|
||||||
|
LibManager.addDependencyRequest("net/mamoe",getProjectName(),version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,19 +108,6 @@ object CoreUpdator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
|
||||||
private object Links {
|
|
||||||
internal const val libJcenter =
|
|
||||||
"https://jcenter.bintray.com/net/mamoe/mirai-core-qqandroid-jvm/{version}/:mirai-core-qqandroid-jvm-{version}.jar"
|
|
||||||
internal const val libAliyun =
|
|
||||||
"https://maven.aliyun.com/nexus/content/repositories/jcenter/net/mamoe/mirai-core-qqandroid-jvm/{version}/mirai-core-qqandroid-jvm-{version}.jar"
|
|
||||||
|
|
||||||
internal const val coreJcenter =
|
|
||||||
"https://jcenter.bintray.com/net/mamoe/mirai-core-jvm/{version}/:mirai-core-jvm-{version}.jar"
|
|
||||||
internal const val coreAliyun =
|
|
||||||
"https://maven.aliyun.com/nexus/content/repositories/jcenter/net/mamoe/mirai-core-jvm/{version}/mirai-core-jvm-{version}.jar"
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun downloadCoreAndLib(version: String) {
|
private suspend fun downloadCoreAndLib(version: String) {
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
launch {
|
launch {
|
||||||
@ -136,9 +123,16 @@ object CoreUpdator {
|
|||||||
.saveToContent("mirai-core-jvm-$version.jar")
|
.saveToContent("mirai-core-jvm-$version.jar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
launch {
|
||||||
|
LibManager.clearLibs()
|
||||||
|
LibManager.addDependencyRequest("net/mamoe","mirai-core-jvm",version)
|
||||||
|
LibManager.addDependencyRequest("net/mamoe","mirai-core-qqandroid-jvm",version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun loadCoreAndLib() {
|
private fun loadCoreAndLib() {
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,7 @@ package net.mamoe.mirai.console.wrapper
|
|||||||
|
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.cio.CIO
|
import io.ktor.client.engine.cio.CIO
|
||||||
|
import io.ktor.client.features.ClientRequestException
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.statement.HttpResponse
|
import io.ktor.client.statement.HttpResponse
|
||||||
import io.ktor.utils.io.ByteReadChannel
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
@ -43,7 +44,26 @@ suspend inline fun HttpClient.downloadRequest(url: String): ByteReadChannel {
|
|||||||
|
|
||||||
private val jcenterPath = "https://jcenter.bintray.com/{group}/{project}/{version}/:{project}-{version}.{extension}"
|
private val jcenterPath = "https://jcenter.bintray.com/{group}/{project}/{version}/:{project}-{version}.{extension}"
|
||||||
private val aliyunPath = "https://maven.aliyun.com/nexus/content/repositories/jcenter/{group}/{project}/{version}/{project}-{version}.{extension}"
|
private val aliyunPath = "https://maven.aliyun.com/nexus/content/repositories/jcenter/{group}/{project}/{version}/{project}-{version}.{extension}"
|
||||||
|
private fun String.buildPath(
|
||||||
|
groupName: String,
|
||||||
|
projectName: String,
|
||||||
|
version: String,
|
||||||
|
extension: String
|
||||||
|
):String{
|
||||||
|
return this
|
||||||
|
.replace(
|
||||||
|
"{group}",groupName
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"{project}",projectName
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"{extension}",extension
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"{version}",version
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun HttpClient.downloadMaven(
|
suspend fun HttpClient.downloadMaven(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
@ -53,35 +73,11 @@ suspend fun HttpClient.downloadMaven(
|
|||||||
):ByteReadChannel{
|
):ByteReadChannel{
|
||||||
return kotlin.runCatching {
|
return kotlin.runCatching {
|
||||||
downloadRequest(
|
downloadRequest(
|
||||||
aliyunPath
|
aliyunPath.buildPath(groupName,projectName,version,extension)
|
||||||
.replace(
|
|
||||||
"{group}",groupName
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{project}",projectName
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{extension}",extension
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{version}",version
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
downloadRequest(
|
downloadRequest(
|
||||||
jcenterPath
|
aliyunPath.buildPath(groupName,projectName,version,extension)
|
||||||
.replace(
|
|
||||||
"{group}",groupName
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{project}",projectName
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{extension}",extension
|
|
||||||
)
|
|
||||||
.replace(
|
|
||||||
"{version}",version
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,6 +98,29 @@ suspend inline fun HttpClient.downloadMavenPom(
|
|||||||
return downloadMaven(groupName,projectName,version,"pom")
|
return downloadMaven(groupName,projectName,version,"pom")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun HttpClient.downloadMavenPomAsString(
|
||||||
|
groupName: String,
|
||||||
|
projectName: String,
|
||||||
|
version: String
|
||||||
|
):String{
|
||||||
|
return kotlin.runCatching {
|
||||||
|
Http.get<String>(
|
||||||
|
aliyunPath.buildPath(groupName,projectName,version,"pom")
|
||||||
|
)
|
||||||
|
}.getOrElse {
|
||||||
|
try {
|
||||||
|
Http.get(
|
||||||
|
aliyunPath.buildPath(groupName, projectName, version, "pom")
|
||||||
|
)
|
||||||
|
}catch (e:Exception){
|
||||||
|
if(e.message?.contains("404 Not Found") == true) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.mamoe.mirai.console.wrapper
|
package net.mamoe.mirai.console.wrapper
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
object LibManager{
|
object LibManager{
|
||||||
|
|
||||||
@ -12,6 +13,12 @@ object LibManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开关
|
||||||
|
* 当前版本不写dynamic加载lib
|
||||||
|
*/
|
||||||
|
val dynamic = false;
|
||||||
|
|
||||||
fun clearLibs(){
|
fun clearLibs(){
|
||||||
libPath.listFiles()?.forEach {
|
libPath.listFiles()?.forEach {
|
||||||
it.delete()
|
it.delete()
|
||||||
@ -24,36 +31,88 @@ object LibManager{
|
|||||||
* 全部完成后使用 @link downloadIfNeeded()开始下载
|
* 全部完成后使用 @link downloadIfNeeded()开始下载
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 由Pom content提供必要依赖
|
|
||||||
* LibManager会检查所有dependency的dependency
|
|
||||||
*/
|
|
||||||
internal fun addDependencyByPom(pomContent:String){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 由Pom Path提供必要依赖
|
* 由Pom Path提供必要依赖
|
||||||
* LibManager会进行下载和递归处理
|
* LibManager会进行下载和递归处理
|
||||||
*/
|
*/
|
||||||
fun addDependencyRequest(link:String){
|
suspend fun addDependencyRequest(
|
||||||
val stream = kotlin.runCatching {
|
group: String,
|
||||||
val jcenterPath = "https://jcenter.bintray.com/{group}/{project}/{version}/:{project}-{version}.pom"
|
project: String,
|
||||||
val aliyunPath = "https://maven.aliyun.com/nexus/content/repositories/jcenter/{group}/{project}/{version}/{project}-{version}.pom"
|
version: String
|
||||||
|
){
|
||||||
|
if(!dynamic){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pom:String? = null
|
||||||
|
if(project.contains("maven") && project.contains("plugin")){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(project.contains("toplink-essentials") || project.contains("ejb") ||project.contains("glassfish-embedded-all") || project.contains("maven-bundle-plugin") || project.contains("jetty") || project.contains("plexus-component-annotations") || project.contains("slf4j") || project.contains("sisu-inject-plexus") || project.contains("maven-remote-resources-plugin") || project.contains("easymock") || project.contains("junit") || project.contains("log4j") || project.contains("doxia-logging-api") || project.contains("maven-enforcer-plugin") || project.contains("maven-plugin") || project.contains("maven-artifact") || project.contains("maven-core") || project.contains("cglib") || project.contains("spring-core")){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tryNTimesOrQuit(3, "Failed to find dependency for $project") {
|
||||||
|
pom = Http.downloadMavenPomAsString(
|
||||||
|
group, project, version
|
||||||
|
)
|
||||||
|
}
|
||||||
|
addDependency(group,project,version)
|
||||||
|
if(pom == null){
|
||||||
|
println("Failed to load dependency POM")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pom!!.replace("\n","").split("</dependency>").forEach {
|
||||||
|
if(it.contains("<dependency>")) {
|
||||||
|
val dependencyInfo = it.replace("<dependency>","")
|
||||||
|
if(dependencyInfo.contains("<groupId>") && dependencyInfo.contains("<artifactId>") && dependencyInfo.contains("<version>")) {
|
||||||
|
val groupName =
|
||||||
|
dependencyInfo.substringAfter("<groupId>").substringBefore("</groupId>").replace(".", "/")
|
||||||
|
.removeSuffix("/")
|
||||||
|
val projectName = dependencyInfo.substringAfter("<artifactId>").substringBefore("</artifactId>")
|
||||||
|
val versionName = dependencyInfo.substringAfter("<version>").substringBefore("</version>")
|
||||||
|
if (!versionName.contains("{")) {
|
||||||
|
if (addDependency(groupName, projectName, versionName)) {
|
||||||
|
addDependencyRequest(groupName, projectName, versionName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 普通的增加一个dependency
|
* 普通的增加一个dependency
|
||||||
*/
|
*/
|
||||||
fun addDependency(){
|
private val dependency = HashSet<String>()
|
||||||
|
fun addDependency(
|
||||||
|
group: String,
|
||||||
|
project: String,
|
||||||
|
version: String
|
||||||
|
):Boolean{
|
||||||
|
if(!dynamic){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(project.contains("maven") && project.contains("plugin")){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if(project.contains("toplink-essentials") ||project.contains("ejb") || project.contains("glassfish-embedded-all") || project.contains("maven-bundle-plugin") || project.contains("jetty") || project.contains("slf4j") || project.contains("sisu-inject-plexus") || project.contains("maven-remote-resources-plugin") || project.contains("easymock") || project.contains("junit") || project.contains("log4j") || project.contains("doxia-logging-api") || project.contains("maven-enforcer-plugin") || project.contains("maven-plugin") || project.contains("maven-artifact") || project.contains("maven-core") || project.contains("cglib") || project.contains("spring-core")){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val id = "${group
|
||||||
|
.replace(".","/")
|
||||||
|
.removeSuffix("/")
|
||||||
|
}-$project:$version"
|
||||||
|
if(dependency.contains(id)){
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
println(id)
|
||||||
|
dependency.add(id)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun downloadIfNeeded(){
|
suspend fun downloadIfNeeded(){
|
||||||
|
this.dependency.forEach {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -46,6 +46,10 @@ object WrapperMain {
|
|||||||
ConsoleUpdator.versionCheck(type)
|
ConsoleUpdator.versionCheck(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println("Dependency needed:")
|
||||||
|
runBlocking {
|
||||||
|
LibManager.downloadIfNeeded()
|
||||||
|
}
|
||||||
println("Version check complete, starting Mirai")
|
println("Version check complete, starting Mirai")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user