Skip to content

Commit 08ec968

Browse files
Karlatempcssxsh
authored andcommitted
Fix private dependencies resolving; fix mamoe#2108
1 parent 3889f4e commit 08ec968

File tree

7 files changed

+36
-3
lines changed

7 files changed

+36
-3
lines changed

mirai-console/backend/integration-test/testers/plugin-dep-dependon-dep-issue-2054/module-private-issue2108/.nested-module.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
net.mamoe.consoleit.issue2108:private-module:1.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright 2019-2022 Mamoe Technologies and contributors.
3+
*
4+
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5+
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
6+
*
7+
* https://github.com/mamoe/mirai/blob/dev/LICENSE
8+
*/
9+
package issue2108
10+
11+
public object PrivateModule {
12+
public fun stack(): Throwable = Throwable("Stack trace")
13+
}

mirai-console/backend/integration-test/testers/plugin-dep-dependon-dep-issue-2054/second-plugin/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ kotlin {
2424
dependencies {
2525
api(project(":mirai-console.integration-test"))
2626
api(parent!!.project("module-modb"))
27+
api(parent!!.project("module-private-issue2108"))
2728
}
2829

2930
tasks.getByName("jar", Jar::class) {

mirai-console/backend/integration-test/testers/plugin-dep-dependon-dep-issue-2054/second-plugin/src/PDepDependOnDepSec.kt

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package pdepdep2054sec
1111

1212
import issue2054.modulea.ModuleA
1313
import issue2054.moduleb.ModuleB
14+
import issue2108.PrivateModule
1415
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
1516
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
1617
import net.mamoe.mirai.utils.info
@@ -26,10 +27,21 @@ public object PDepDependOnDepSec : KotlinPlugin(
2627
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
2728
listOf("net.mamoe.consoleit.issue2054:modb:1.0.0")
2829
)
30+
jvmPluginClasspath.downloadAndAddToPath(
31+
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
32+
listOf("net.mamoe.consoleit.issue2108:private-module:1.0.0")
33+
)
2934

3035
assertSame(ModuleA, ModuleB.getModuleA)
3136
logger.info { "issue 2054" }
3237

3338
ModuleB.act { ModuleA.act { logger.info(Throwable("Stack trace")) } }
39+
40+
logger.info("issue 2108", PrivateModule.stack())
41+
assertSame(
42+
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
43+
PrivateModule.javaClass.classLoader,
44+
"Failed to load private module from " + jvmPluginClasspath.pluginIndependentLibrariesClassLoader
45+
)
3446
}
3547
}

mirai-console/backend/integration-test/testers/plugin-dep-dependon-dep-issue-2054/src/PDepDependOnDep.kt

+4
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ public object PDepDependOnDep : KotlinPlugin(
2020
jvmPluginClasspath.pluginSharedLibrariesClassLoader,
2121
listOf("net.mamoe.consoleit.issue2054:moda:1.0.0")
2222
)
23+
jvmPluginClasspath.downloadAndAddToPath(
24+
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
25+
listOf("net.mamoe.consoleit.issue2108:private-module:1.0.0")
26+
)
2327
}
2428
}

mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
247247
dependency: String
248248
): Boolean {
249249
if (dependency in sharedClLoadedDependencies) return true
250-
if (dependency in privateClLoadedDependencies) return true
251250
return dependencies.any { it.containsSharedDependency(dependency) }
252251
}
253252

@@ -288,8 +287,11 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
288287
if (dependencies.isEmpty()) return
289288
val results = ctx.downloader.resolveDependencies(
290289
dependencies, ctx.sharedLibrariesFilter,
291-
DependencyFilter { node, _ ->
292-
return@DependencyFilter !containsSharedDependency(node.artifact.depId())
290+
DependencyFilter filter@{ node, _ ->
291+
val depid = node.artifact.depId()
292+
if (containsSharedDependency(depid)) return@filter false
293+
if (depid in privateClLoadedDependencies) return@filter false
294+
return@filter true
293295
})
294296
val files = results.artifactResults.mapNotNull { result ->
295297
result.artifact?.let { it to it.file }

0 commit comments

Comments
 (0)