gnodet-bot commented on code in PR #13491:
URL: https://github.com/apache/maven/pull/13491#discussion_r4288917892
##########
compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/BootstrapCoreExtensionManager.java:
##########
@@ -33,6 +33,8 @@
import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.Service;
import org.apache.maven.api.Session;
+import org.apache.maven.api.classworlds.ClassRealm;
+import org.apache.maven.api.classworlds.ClassWorld;
Review Comment:
⚠️ **Inconsistency with `MavenCli.java` (fixed in this same commit):** This
file imports the API classworlds types, while `MavenCli.java` in the same
`compat/maven-embedder` module was switched back to the plexus types in this
commit. Both are compat-layer code and should use the same approach.
Since `setParentRealm()` is intentionally excluded from the API interface,
these API imports force the ugly FQN downcast below. The fix is to revert to
plexus imports here, just as was done for `MavenCli.java`:
```suggestion
import org.codehaus.plexus.classworlds.ClassWorld;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
```
##########
compat/maven-embedder/src/main/java/org/apache/maven/cli/internal/BootstrapCoreExtensionManager.java:
##########
@@ -176,12 +176,13 @@ private CoreExtensionEntry createExtension(CoreExtension
extension, List<Artifac
Set<String> providedArtifacts = Collections.emptySet();
String classLoadingStrategy = extension.getClassLoadingStrategy();
if (STRATEGY_PARENT_FIRST.equals(classLoadingStrategy)) {
- realm.importFrom(parentRealm, "");
+ realm.importFrom(parentRealm.getClassLoader(), "");
} else if (STRATEGY_PLUGIN.equals(classLoadingStrategy)) {
coreExports.getExportedPackages().forEach((p, cl) ->
realm.importFrom(cl, p));
providedArtifacts = coreExports.getExportedArtifacts();
} else if (STRATEGY_SELF_FIRST.equals(classLoadingStrategy)) {
- realm.setParentRealm(parentRealm);
+ ((org.codehaus.plexus.classworlds.realm.ClassRealm) realm)
+
.setParentRealm((org.codehaus.plexus.classworlds.realm.ClassRealm) parentRealm);
} else {
Review Comment:
⚠️ **Consequence of API import mismatch:** This FQN downcast (and the
`getClassLoader()` workaround on the line above) exist only because the API
`ClassRealm` doesn't expose `setParentRealm()`. If the plexus types were
imported instead (as done in `MavenCli.java`), this entire block simplifies
back to:
```suggestion
realm.importFrom(parentRealm.getClassLoader(), "");
} else if (STRATEGY_PLUGIN.equals(classLoadingStrategy)) {
coreExports.getExportedPackages().forEach((p, cl) ->
realm.importFrom(cl, p));
providedArtifacts = coreExports.getExportedArtifacts();
} else if (STRATEGY_SELF_FIRST.equals(classLoadingStrategy)) {
realm.setParentRealm(parentRealm);
```
--
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]