gnodet-bot commented on code in PR #11029:
URL: https://github.com/apache/maven/pull/11029#discussion_r4062350233
##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java:
##########
@@ -529,21 +549,41 @@ public <T> T getConfiguredMojo(Class<T> mojoInterface,
MavenSession session, Moj
// We are forcing the use of the plugin realm for all lookups that
might occur during
// the lifecycle that is part of the lookup. Here we are specifically
trying to keep
// lookups that occur in contextualize calls in line with the right
realm.
- ClassRealm oldLookupRealm = container.setLookupRealm(pluginRealm);
+ ClassRealm oldLookupRealm =
+
container.setLookupRealm((org.codehaus.plexus.classworlds.realm.ClassRealm)
pluginRealm);
+ // For modular plugins, set TCCL to the ModuleLayer's classloader
ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(pluginRealm);
+ ClassLoader effectiveLoader = getEffectiveClassLoader(pluginRealm);
+ Thread.currentThread().setContextClassLoader(effectiveLoader);
try {
- if (mojoDescriptor.isV4Api()) {
+ if (pluginDescriptor.isModular()) {
+ // Modular plugins always use the v4 Mojo loading path with
maven-di
+ return loadV4Mojo(mojoInterface, session, mojoExecution,
mojoDescriptor, pluginDescriptor, pluginRealm);
+ } else if (mojoDescriptor.isV4Api()) {
return loadV4Mojo(mojoInterface, session, mojoExecution,
mojoDescriptor, pluginDescriptor, pluginRealm);
} else {
return loadV3Mojo(mojoInterface, session, mojoExecution,
mojoDescriptor, pluginDescriptor, pluginRealm);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
- container.setLookupRealm(oldLookupRealm);
+
container.setLookupRealm((org.codehaus.plexus.classworlds.realm.ClassRealm)
oldLookupRealm);
+ }
+ }
+
+ /**
+ * Returns the effective classloader for a plugin realm.
+ * For modular plugins, returns the ModuleLayer's classloader;
+ * for classic plugins, returns the realm's own classloader.
+ */
+ private static ClassLoader getEffectiveClassLoader(ClassRealm pluginRealm)
{
+ if (pluginRealm.isModular()) {
+ ModuleLayer layer = pluginRealm.getModuleLayer();
+ // defineModulesWithOneLoader uses a single loader for all modules
in the layer
+ return layer.modules().iterator().next().getClassLoader();
Review Comment:
test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]