Repository navigation
feat: internalize plexus-classworlds (fixes #11028) - #13490
Conversation
gnodet-bot
left a comment
There was a problem hiding this comment.
Three issues worth fixing: a missing artifact export that will cause ClassCastException at runtime in plugins, a JUL handler leak when Maven runs embedded (regression from the removed restoreRootLoggerHandlers()), and two behavioral changes bundled into the compat layer that should not be there.
The internalization itself is sound — the API module is clean, the implementation bridge is correct, and the cast proliferation in MavenCli is an acceptable transitional state given the narrowed API surface.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
699bd80 to
28b3a87
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — 3 of the 4 issues have been addressed.
- ✅
maven-api-classworldsadded to<exportedArtifacts>inextension.xml(lines 154–155) —ClassCastExceptionrisk eliminated. - ✅
installEmbeddedTerminal()and dumb-terminal color detection restored inMavenCli.java— embedded-terminal regression fixed. - ✅
applyExportOrOpen()dead-code concern resolved — the module-access wiring is now a proper pipeline:m2.confparser →ConfigurationHandler→Configurator→ClassWorld.addExports/addOpens/addReads. Well done.
Still open — JUL handler leak (impl/maven-cli/…/LookupInvoker.java):
activateLogging() calls SLF4JBridgeHandler.install() (guarded by isInstalled()), but SLF4JBridgeHandler.uninstall() is never called — not in the finally block, and not in the closeables list. When Maven runs embedded (IDE, CI tooling, Verifier), the handler remains on the JVM's root java.util.logging logger after Maven exits. The next JUL event in the host process routes through the closed Maven classloader → NoClassDefFoundError: org/slf4j/Logger.
The finally block currently:
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
System.setProperties(oldProps);
}Should be:
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
System.setProperties(oldProps);
SLF4JBridgeHandler.uninstall();
}This review was generated by an AI agent, Hermès on behalf of @gnodet.
28b3a87 to
5e281fc
Compare
Retracting: the JUL handler leak was already fixed on master (restoreRootLoggerHandlers, commit 05b8933). This PR branch predates the fix but is not the cause.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — all 3 original issues have been addressed.
- ✅
maven-api-classworldsadded to<exportedArtifacts>inextension.xml(lines 154–155) —ClassCastExceptionrisk eliminated. - ✅
installEmbeddedTerminal()and dumb-terminal color detection restored inMavenCli.java— embedded-terminal regression fixed. - ✅
applyExportOrOpen()dead-code concern resolved — the module-access wiring is now a proper pipeline:m2.confparser →ConfigurationHandler→Configurator→ClassWorld.addExports/addOpens/addReads.
The JUL handler leak I raised in the dismissed review was a false positive — LookupInvoker.java is not changed by this PR, and restoreRootLoggerHandlers() was already added to master (commit 05b8933) before this branch was last rebased. It will be included on the next rebase.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
3ff1535 to
c14913f
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
These new @Experimental API interfaces use getXxx() naming where Maven 4 API conventions require noun-style no-arg accessors (xxx()). This is a standing project rule for all @Experimental interfaces in maven-api-* modules.
The exception classes (ClassWorldException, NoSuchRealmException, DuplicateRealmException) are in the api module and are part of the public contract — they should follow the same convention.
For ClassWorld.getRealm(id) / getClassRealm(id), the methods take an argument so the no-arg accessor rule doesn't strictly apply; however realm(id) / classRealm(id) would still be more consistent with the rest of the API style.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the previous CHANGES_REQUESTED is withdrawn.
The noun-style accessor convention (id() vs getId()) applies to @Immutable value types only (e.g. Artifact, ArtifactCoordinates). ClassRealm and ClassWorld are mutable objects — they have mutating methods (addURL(), importFrom(), newRealm(), disposeRealm()) and are not annotated @Immutable. Standard JavaBeans getXxx() accessors are correct for mutable types. The counter-argument was accurate; that review was wrong.
New commit 58296b58 is correct: the 4 boot JAR glob references (plexus-classworlds-* → maven-classworlds-*) are consistent with component.xml which ships org.apache.maven:maven-classworlds in boot/. LAUNCHER_CLASS correctly retains org.codehaus.plexus.classworlds.launcher.Launcher — the internalised module preserves the original package structure for backward compatibility. No remaining source-level plexus-classworlds launcher-path references found.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — 3 new commits need attention.
The boot classpath addition (47265078) and the Launcher.getEnhancedMainMethod() dual-candidate approach (ca6b40c4) are both correct. However the companion commit (64f5d4ca) that changed delegateMain() in MavenCling to look up the API ClassWorld type breaks three existing sub-commands.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the delegateMain() fix is correct.
The dual-candidate lookup in delegateMain() (MavenCling.java) now mirrors Launcher.getEnhancedMainMethod() exactly: it tries org.codehaus.plexus.classworlds.ClassWorld first (matching MavenEncCling, MavenShellCling, MavenUpCling), then org.apache.maven.api.classworlds.ClassWorld (matching MavenValCling). The method.invoke(null, args, world) call is safe for both paths because the impl ClassWorld implements the API ClassWorld interface — passing the impl instance where the API type is expected is a valid widening reference conversion.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
rmannibucau
left a comment
There was a problem hiding this comment.
think we should take time to refine the API, we dont need all that nor all the concepts (world, realm, strategy). Maybe something closer to classloader would benefit the api on the long run
|
Thanks for the input, @rmannibucau. The API is explicitly
Happy to iterate on the API shape in a follow-up once the internalization lands. Is there a specific concept you'd drop or collapse? That would make the design conversation more concrete. |
|
@gnodet didnt yet fully defined it but feel like it could just be exposing a MavenClassLoader or alike and not split that much concepts. integration can then be with other custom classloaders since it is what the abstractions are about most of the time and classloader are better defined than legacy classworld concept for java dev but it might need jpms careness with the work you do in parallel. So (maven)classloader+modulelayer sounds like the way to move forward for me but it is just a first feedback from my past interactions with plexus-classworld and OSGi/EE. |
2b3866e to
30c8eac
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — previous findings all addressed, but two regressions introduced by the second new commit (30c8eac8).
Boot launcher mismatch (Maven won't start)
component.xml correctly places maven-classworlds-<version>.jar and maven-api-classworlds-<version>.jar in boot/. However mvn and mvn.cmd still use the old plexus-classworlds-*.jar glob — that pattern matches nothing in the assembled distribution and Maven fails immediately at launch (ClassWorld Launcher is never loaded). This commit must also update the glob in both launchers.
MavenValCling broken by launcher revert
The dual-candidate lookup in delegateMain() and getEnhancedMainMethod() was the correct fix approved in the previous review. This commit reverts both back to a single-type lookup on org.codehaus.plexus.classworlds.ClassWorld. MavenValCling.main(String[], ClassWorld) uses org.apache.maven.api.classworlds.ClassWorld (the API type) — the narrowed method lookup will throw NoSuchMethodException at runtime whenever maven.mainClass=org.apache.maven.cling.MavenValCling is set. The dual-candidate approach must be restored.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
Thanks for the review @rmannibucau. The goal here is to internalize plexus-classworlds as an Apache Maven artifact and expose a minimal, stable API for the concepts that plugin authors genuinely need today (mostly realm introspection). The API surface is already quite small — That said, I agree the longer-term direction is worth discussing. The |
|
@rmannibucau Thanks for the feedback. The API is marked A few points on the current design choices:
That said, if you have a concrete proposal for a slimmer API surface (e.g. just expose the import/export operations and drop |
30c8eac to
4942bbf
Compare
|
two open questions:
rest LGTM |
|
Thanks @rmannibucau for the final pair of questions. 1. Preserve the jar name in the distro for backward compat? Yes, strongly agreed. The assembled distribution currently ships The assembly plugin supports <dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>boot</outputDirectory>
<includes>
<include>org.apache.maven:maven-classworlds</include>
</includes>
<outputFileNameMapping>plexus-classworlds-${artifact.version}.jar</outputFileNameMapping>
</dependencySet>
2. Drop the The jars ( Generating them at test time would require either: (a) a separate Maven sub-module that compiles them and produces JARs before the main module's tests run, or (b) an in-test bytecode generation approach (e.g. ASM). Both are significantly more complex than static fixtures and would themselves need sources tracked in git — just Java source files instead of class files. My preference is to leave them as binary test fixtures in this PR (it faithfully copies the plexus-classworlds approach) and track the replacement as a follow-up if the project wants it. Keeping the scope of this internalization PR minimal makes review easier. Does that work for you, or would you prefer we tackle the jar generation in this PR? Claude Code on behalf of Guillaume Nodet |
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the backward-compatibility fix is correct.
The approach of renaming maven-classworlds-<version>.jar → plexus-classworlds-<version>.jar in boot/ via <outputFileNameMapping> in component.xml is sound: wrapper scripts, CI tooling, and IDEs that glob boot/plexus-classworlds-*.jar continue to work without change. The launcher globs in mvn and mvn.cmd are now consistent with the renamed boot artifact, and the test stubs in both shell test scripts have been updated accordingly.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
for the jar asm or subproject "fixture" would work I think, i dont care much while we reach a stage we dont trust binaries like that (and not blaming know it was there) |
…che#11028) Fork plexus-classworlds 2.x into impl/maven-classworlds and expose a stable public API via api/maven-api-classworlds under the org.apache.maven.api.classworlds package. New modules: - api/maven-api-classworlds: ClassWorld, ClassRealm, Strategy, ClassWorldListener, exceptions under org.apache.maven.api.classworlds - impl/maven-classworlds: fork of plexus-classworlds with the existing org.codehaus.plexus.classworlds implementation plus backward-compat adapters under org.codehaus.classworlds
…aunchers) Replace the external plexus-classworlds dependency with maven-classworlds across the codebase and update the boot classpath in the launchers. - Replace plexus-classworlds dependency with maven-classworlds in all affected module poms (maven-core, maven-cli, maven-compat, maven-plugin-api, maven-resolver-provider, apache-maven) - Update assembly component.xml: swap boot entry to maven-classworlds + maven-api-classworlds, exclude both from lib - Update all import sites to org.codehaus.plexus.classworlds.* - Add maven-classworlds and maven-api-classworlds to exportedArtifacts in extension.xml (prevents ClassCastException in plugins) - Remove classWorldsVersion property from root pom.xml - Update LAUNCHER_JAR glob in mvn/mvn.cmd to maven-classworlds-*.jar, add maven-api-classworlds-*.jar to boot classpath, use cygpath --path for the compound path on Cygwin/MinGW - Update test scripts for new jar names - Update Launcher.getEnhancedMainMethod() and delegateMain() to handle both impl and API ClassWorld types for backward compatibility
Per review feedback from @rmannibucau, demote the public API surface: remove the api/maven-api-classworlds module and revert all consumer code to use the plexus-classworlds implementation types directly. The internalization of plexus-classworlds as impl/maven-classworlds is preserved. A stable public API can be designed and introduced in a follow-up once the internalization has settled. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Now that the API interfaces are removed, the fully-qualified names that were needed to disambiguate API vs impl types can be simplified. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Now that the API interfaces are removed, the fully-qualified names and casts that were needed to disambiguate or downcast from API to impl types are no longer necessary. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…tibility The assembled distribution renames maven-classworlds-*.jar back to plexus-classworlds-*.jar via outputFileNameMapping in component.xml. This keeps existing wrapper scripts, CI tooling, and IDEs that glob boot/plexus-classworlds-*.jar working without any change. mvn, mvn.cmd, and test stubs are updated to match. Requested by @rmannibucau in review.
40b45d9 to
fa168cb
Compare
Replace 17 committed binary test fixture JARs with a TestJarGenerator that compiles Java sources and assembles JARs at test time using the JDK's javax.tools.JavaCompiler and JarOutputStream APIs. All JARs are written to target/test-jars/ before tests run via a @BeforeAll hook in AbstractClassWorldsTestCase. Conf files updated to reference target/test-jars/ instead of src/test/test-data/. No binary blobs remain in the repository; every fixture is fully auditable from its Java source.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — previous findings all addressed. One nit in the new commit.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the Javadoc nit is addressed.
The corrected description now accurately matches the implementation: it states that existing JARs are overwritten on each run and that stale JARs (from a previous run whose names are no longer generated) are not deleted. That is precise and actionable for anyone who hits a stale-artifact issue.
All previous findings across this PR are now fully resolved. LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…d parent contexts activate POM-property conditions Commit 267e65f (backport of PR apache#13545) introduced a dedicated interpolationProperties field to prevent POM-declared properties from self-activating profiles via start(Map). However, it incorrectly dropped the model.withProperties(interpolationProperties) call that makes those properties accessible via getModelProperty() in non-sandboxed (project parent) contexts. The 4.0.x implementation keeps both: - model.withProperties(map) so getModelProperty() works for project parents - interpolationProperties stored separately for path interpolation The sandbox (withoutUserPropertiesAndFilesystem()) overrides getModelProperty() to return null, which is the guard against POM property self-activation in dependency/external builds (apache#13390). Non-sandboxed project parent builds should still be able to activate condition-based profiles that reference POM-declared properties. Fixes testResolvedDependencyParentCacheDoesNotShareActivationWithProjectParent at line 380: assertEquals("activated", profile.pom.condition)
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — all previous findings are addressed. One new commit needs attention.
New commit (651d7a58) — fix: restore model.withProperties() in start(Map)
The fix is correct and matches master behavior. Before the fix, start(Map<String, String> interpolationProperties) passed the original model (built with Model.newInstance() in the test helper, which has no <properties>) to the constructor, leaving getModelProperty() returning null for POM-declared keys. The sandbox's withoutUserPropertiesAndFilesystem() override (which unconditionally returns null from getModelProperty()) is the actual guard against self-activation in dependency parent contexts — so restoring model.withProperties(interpolationProperties) for the outer context is safe.
One minor observation on the updated interpolatePath logic: after this fix, interpolationProperties and model.getProperties() contain the same map, so the interpolationProperties-first check inside interpolate() is now redundant for the non-sandbox path. That's not a bug — the behavior is correct — but the comment still describes the check as preventing self-activation, which is now handled by the sandbox override rather than by this ordering. A follow-up cleanup of the interpolate() comment would improve clarity, but it's not a blocker.
The Javadoc update is accurate and clearly documents the sandbox contract.
Pre-fix validation: the assertion at line 380 (assertEquals("activated", projectParentModel.getProperties().get("profile.pom.condition"))) was failing before this commit — getModelProperty() returned null for pom.declared.prop because the context was constructed with Model.newInstance() (no properties). After the fix it returns "hello", the condition ${pom.declared.prop} == 'hello' fires, and the profile activates. ✅
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
…nalize-classworlds # Conflicts: # impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultProfileActivationContext.java
…es it Commit 651d7a5 (in this branch) restored model.withProperties(interpolationProperties) in start(Map) so that POM-property conditions could fire in project-parent paths. This is now incorrect: PR apache#1774 (Cascading profile activation, commit 9e7a17e) landed in master and provides the proper mechanism: POM properties from activated profiles flow through getCascadedProfileProperty(), not getModelProperty(). The cascading PR also updated testResolvedDependencyParentCacheDoesNotShareActivationWithProjectParent to assert that profile.pom.condition must NOT self-activate even in the project-parent path (assertNull at line 381-383), which conflicts with what 651d7a5 introduced. Revert start(Map) to pass the original model (not model.withProperties(...)). Path interpolation is unaffected — interpolationProperties is still passed separately and used exclusively inside interpolate() for placeholder resolution (see apache#10375). The fix for apache#13390 remains intact.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the previous findings are all addressed, and the new commit correctly reverts the start(Map) model override.
- ✅ Revert is correct:
commit 651d7a58restoredmodel.withProperties(interpolationProperties)instart(Map)to enable condition-based profile activation for project-parent paths. This is superseded by PR #1774 (cascading activation, commit9e7a17eb8b), which introducedgetCascadedProfileProperty()as the proper mechanism for that use case. The cascading PR also updatedtestResolvedDependencyParentCacheDoesNotShareActivationWithProjectParenttoassertNullonprofile.pom.conditionin the project-parent path — which directly conflicts with what651d7a58introduced. - ✅ Javadoc is accurate: "for path interpolation only / model's properties are NOT overridden" correctly describes the post-revert behaviour.
interpolationPropertiesis only consumed ininterpolate()(line 553), never by profile activators. - ✅
interpolate()comment is still correct: the check-interpolationProperties-first remark ("without being exposed throughgetModelProperty()and thus without being able to self-activate profiles") is accurate again — the two maps are distinct after the revert. - ✅ No test changes needed: the
assertNullassertion at line 381–383 ofDefaultModelBuilderTest(merged from master via PR #13555) already exercises and validates this code path.
My earlier observation about the interpolate() check being "redundant for the non-sandbox path" (from the 651d7a58 review) is now moot — the maps are distinct again, so the check is correct.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Summary
Internalizes
plexus-classworldsasimpl/maven-classworlds, replacing the external dependency with an in-tree module.Per review feedback from @rmannibucau, the public API module (
api/maven-api-classworlds) has been removed — the codebase uses the implementation types directly. A stable API can be designed and introduced in a follow-up once the internalization has settled.This is a prerequisite for:
--enable-native-access(PR B)ModuleLayersupport (PR C)Changes
New module
impl/maven-classworlds— fork ofplexus-classworldswith theorg.codehaus.plexus.classworldsimplementation, backward-compat adapters underorg.codehaus.classworlds, and new capabilities:moduledirective inm2.conf— loads JARs on the JPMS module-path in a childModuleLayer(enables targeted--enable-native-access)META-INF/maven/module-accessdescriptor — classpath plugins can declareadd-exports/add-opens/add-readsagainst named modules declarativelyAcross the codebase
plexus-classworldsdependency withmaven-classworldsacross all modulesclassWorldsVersionproperty from rootpom.xmlScope
This PR intentionally excludes:
mvn,mvn.cmd,m2.confchanges (PR B — JLine on module-path)createModularPluginRealm,<modular>true</modular>,ModuleLayerCreationException(PR C — per-plugin modular realms)Note on
org.codehaus.classworldscompat packageThe
org.codehaus.classworldsbackward-compat package is intentionally kept inimpl/maven-classworldsfor now. Dropping it requires that eclipse-sisu/sisu-project#280 be merged first — three classes inorg.eclipse.sisu.plexusstill hold compiled references to the legacy package. Once that Sisu PR lands and a new Sisu release is available, the compat layer can be removed.Testing
impl/maven-classworldsandimpl/maven-corecompile and the classworlds unit tests pass.Note:
impl/maven-clihas pre-existing compilation issues from master changes not yet integrated into this branch; they will resolve on rebase.Supersedes #11029