mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-03 23:22:29 +08:00
Fix private dependencies resolving; fix #2108
This commit is contained in:
parent
f69fdb7ac1
commit
1110a6f3fa
@ -0,0 +1 @@
|
|||||||
|
net.mamoe.consoleit.issue2108:private-module:1.0.0
|
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019-2022 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/dev/LICENSE
|
||||||
|
*/
|
||||||
|
package issue2108
|
||||||
|
|
||||||
|
public object PrivateModule {
|
||||||
|
public fun stack(): Throwable = Throwable("Stack trace")
|
||||||
|
}
|
@ -24,6 +24,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api(project(":mirai-console.integration-test"))
|
api(project(":mirai-console.integration-test"))
|
||||||
api(parent!!.project("module-modb"))
|
api(parent!!.project("module-modb"))
|
||||||
|
api(parent!!.project("module-private-issue2108"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.getByName("jar", Jar::class) {
|
tasks.getByName("jar", Jar::class) {
|
||||||
|
@ -11,6 +11,7 @@ package pdepdep2054sec
|
|||||||
|
|
||||||
import issue2054.modulea.ModuleA
|
import issue2054.modulea.ModuleA
|
||||||
import issue2054.moduleb.ModuleB
|
import issue2054.moduleb.ModuleB
|
||||||
|
import issue2108.PrivateModule
|
||||||
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
|
||||||
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
|
||||||
import net.mamoe.mirai.utils.info
|
import net.mamoe.mirai.utils.info
|
||||||
@ -26,10 +27,21 @@ public object PDepDependOnDepSec : KotlinPlugin(
|
|||||||
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
|
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
|
||||||
listOf("net.mamoe.consoleit.issue2054:modb:1.0.0")
|
listOf("net.mamoe.consoleit.issue2054:modb:1.0.0")
|
||||||
)
|
)
|
||||||
|
jvmPluginClasspath.downloadAndAddToPath(
|
||||||
|
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
|
||||||
|
listOf("net.mamoe.consoleit.issue2108:private-module:1.0.0")
|
||||||
|
)
|
||||||
|
|
||||||
assertSame(ModuleA, ModuleB.getModuleA)
|
assertSame(ModuleA, ModuleB.getModuleA)
|
||||||
logger.info { "issue 2054" }
|
logger.info { "issue 2054" }
|
||||||
|
|
||||||
ModuleB.act { ModuleA.act { logger.info(Throwable("Stack trace")) } }
|
ModuleB.act { ModuleA.act { logger.info(Throwable("Stack trace")) } }
|
||||||
|
|
||||||
|
logger.info("issue 2108", PrivateModule.stack())
|
||||||
|
assertSame(
|
||||||
|
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
|
||||||
|
PrivateModule.javaClass.classLoader,
|
||||||
|
"Failed to load private module from " + jvmPluginClasspath.pluginIndependentLibrariesClassLoader
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,9 @@ public object PDepDependOnDep : KotlinPlugin(
|
|||||||
jvmPluginClasspath.pluginSharedLibrariesClassLoader,
|
jvmPluginClasspath.pluginSharedLibrariesClassLoader,
|
||||||
listOf("net.mamoe.consoleit.issue2054:moda:1.0.0")
|
listOf("net.mamoe.consoleit.issue2054:moda:1.0.0")
|
||||||
)
|
)
|
||||||
|
jvmPluginClasspath.downloadAndAddToPath(
|
||||||
|
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
|
||||||
|
listOf("net.mamoe.consoleit.issue2108:private-module:1.0.0")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,6 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
|
|||||||
dependency: String
|
dependency: String
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (dependency in sharedClLoadedDependencies) return true
|
if (dependency in sharedClLoadedDependencies) return true
|
||||||
if (dependency in privateClLoadedDependencies) return true
|
|
||||||
return dependencies.any { it.containsSharedDependency(dependency) }
|
return dependencies.any { it.containsSharedDependency(dependency) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +287,11 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
|
|||||||
if (dependencies.isEmpty()) return
|
if (dependencies.isEmpty()) return
|
||||||
val results = ctx.downloader.resolveDependencies(
|
val results = ctx.downloader.resolveDependencies(
|
||||||
dependencies, ctx.sharedLibrariesFilter,
|
dependencies, ctx.sharedLibrariesFilter,
|
||||||
DependencyFilter { node, _ ->
|
DependencyFilter filter@{ node, _ ->
|
||||||
return@DependencyFilter !containsSharedDependency(node.artifact.depId())
|
val depid = node.artifact.depId()
|
||||||
|
if (containsSharedDependency(depid)) return@filter false
|
||||||
|
if (depid in privateClLoadedDependencies) return@filter false
|
||||||
|
return@filter true
|
||||||
})
|
})
|
||||||
val files = results.artifactResults.mapNotNull { result ->
|
val files = results.artifactResults.mapNotNull { result ->
|
||||||
result.artifact?.let { it to it.file }
|
result.artifact?.let { it to it.file }
|
||||||
|
Loading…
Reference in New Issue
Block a user