Repository navigation
Add Mojo configuration introspection service - #14111
abdulhannansyed wants to merge 1 commit into
Conversation
gnodet-bot
left a comment
There was a problem hiding this comment.
Thank you for this feature! Adding a MojoConfigurationService for introspecting Mojo parameters without instantiation is a useful capability. I have a few issues to address before this can merge.
🔴 Wrong @since tag
The @since tag on MojoConfigurationService reads 4.1.0, but master is currently 4.2.0-SNAPSHOT. This must be @since 4.2.0.
🟠 Missing class name in exception messages
Both guard clauses in DefaultMojoConfigurationService throw an IllegalArgumentException with a fixed message, making it impossible to diagnose failures at runtime. The message should include the actual runtime class name of the rejected argument.
// Instead of:
throw new IllegalArgumentException("Unsupported MojoExecution implementation");
// Use:
throw new IllegalArgumentException("Unsupported MojoExecution implementation: " + mojoExecution.getClass().getName());Same for the Project guard clause.
🟡 Cross-package coupling via PluginConfigurationInterpolator
DefaultMojoConfigurationService lives in configuration.internal but imports PluginConfigurationInterpolator from plugin.internal. Coupling two separate internal packages is a layering concern — PluginConfigurationInterpolator should either be moved to the shared configuration.internal package or extracted to a non-internal location.
🟡 TCCL swap undocumented
The TCCL swap at line 100 carries an implicit threading restriction: callers must invoke getParameters() from the same thread that holds the plugin class loader. Consider adding a @ThreadSafe / @NotThreadSafe annotation or at minimum a Javadoc note explaining why the TCCL swap is needed and what threading contract callers must honour.
🔵 Test boilerplate: createMavenSession(null) / new ClassWorld() repeated 11×
Each of the 11 test methods calls createMavenSession(null) and new ClassWorld(...) independently. Extract them to a @BeforeEach setup method.
🔵 No negative tests for guard clauses
The implementation rejects non-DefaultMojoExecution, non-DefaultProject, and non-V4-Mojo inputs with IllegalArgumentException. None of these cases are tested. Please add assertThrows tests for each guard clause.
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 — all 6 issues have been addressed.
- 🔴
@sincetag — ✅ fixed to@since 4.2.0 - 🟠 Exception messages missing class name — ✅ both now include
.getClass().getName() - 🟡 Cross-package coupling (
PluginConfigurationInterpolatorinplugin.internal) — ✅ moved toconfiguration.internal - 🟡 TCCL swap undocumented — ✅ Javadoc now states the class loader is temporarily set and restored
- 🔵 Test boilerplate repeated 11× — ✅ extracted to
@BeforeEach setUp() - 🔵 No negative tests for guard clauses — ✅ three
assertThrowstests added (rejectsUnsupportedMojoExecutionImplementation,rejectsUnsupportedProjectImplementation,rejectsNonV4Mojo)
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
There was a problem hiding this comment.
Thanks for the PR! Before we go further on the implementation, I'd like to understand the intended use case better, as it drives some key design choices.
Who is the caller? The description says "embedders", which makes sense — a Mojo doesn't need this, it already gets its parameters injected. So this is for tools that want to inspect resolved Mojo configuration without executing the Mojo: IDEs, migration tools, linters, JBang/Quarkus dev-mode, etc.
V3 plugin support is mandatory. The current implementation rejects any Mojo with !isV4Api(). In practice, the plugins embedders most want to inspect today — maven-compiler-plugin, maven-surefire-plugin, maven-jar-plugin — are all V3 plugins. The equivalent abstractions exist in core (PluginParameterExpressionEvaluator, ComponentConfigurator("basic")), so the V4-only restriction is a simplification choice, not a technical constraint. This needs to be supported before the API can be considered useful.
Return type: Map<String, Object> vs Map<String, XmlNode>.
This depends entirely on what callers actually do with the values. The current Map<String, Object> has a classloader leak: for primitive types (String, int, boolean, File, Path) it's fine, but for complex nested types (e.g. <archive> in maven-jar-plugin) the converter instantiates objects from the plugin realm. The caller is in a different classloader and can't cast or even inspect those types — ClassCastException guaranteed.
Could you describe your concrete use case? Specifically: what do you do with the returned objects? If the answer is "display them" or "check whether a parameter is set", then Map<String, XmlNode> (the interpolated configuration tree, before type conversion) is the right contract — no classloader exposure, no Mojo instantiation, and it works identically for V3 and V4 plugins. If you genuinely need typed values, then we need to constrain the return type to JDK types only and document that explicitly.
|
@abdulhannansyed548-cmd Thanks for the PR! Before we go further on the implementation, I'd like to understand the intended use case better, as it drives some key design choices. Who is the caller? The description says "embedders", which makes sense — a Mojo doesn't need this, it already gets its parameters injected. So this is for tools that want to inspect resolved Mojo configuration without executing the Mojo: IDEs, migration tools, linters, JBang/Quarkus dev-mode, etc. V3 plugin support is mandatory. The current implementation rejects any Mojo with Return type: Could you describe your concrete use case? Specifically: what do you do with the returned objects? If the answer is "display them" or "check whether a parameter is set", then This comment was posted by an AI agent, Hermès, on behalf of @gnodet. |
|
@gnodet Thanks for raising these points. Let me clarify the intended use case. The primary use case I had in mind is IDE integration, particularly the kind of functionality currently implemented by m2e. For example, its Java project configurator reads resolved parameters from The caller needs resolved parameter values, rather than a configured Mojo instance. In this scenario, the values are primarily simple types and collections such as I agree that returning complex objects loaded from a plugin realm through I also agree that V3 support is important. The compiler, Surefire, and JAR plugins are practical examples, so restricting the service to V4 plugins would significantly limit its usefulness. I think we should clarify the result contract before extending the implementation. One possibility is to return typed values only for supported JDK types and avoid exposing plugin-specific complex objects. Another is to return an interpolated Would you prefer the service to expose only the classloader-neutral XML representation, or should we retain typed access for supported JDK types as part of this API? |
Good idea, retaining typed access for supported JDK types looks like a good middle ground to me. |
|
Hi @gnodet , I've pushed an update addressing the feedback discussed in the review. The changes include:
I also ran the full Maven Core reactor test suite:
All 30 modules passed; Maven Core reported 708 tests, 0 failures, 0 errors, and 1 skipped. Could you please review the updated implementation, particularly the Thanks! |
139f0f5 to
3f69d5d
Compare
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — the previous CHANGES_REQUESTED findings are all resolved. ✅ The new commit adds V3 support and extracts PluginConfigurationInterpolator to configuration.internal. Two correctness issues found in the new code.
🔴 StringIndexOutOfBoundsException in findCachedMethod when called from setDefault
EnhancedCompositeBeanHelper.setDefault() calls findCachedMethod(beanType, "", null) to locate a default "set" method (line 83). Inside findCachedMethod, the first thing it does is:
String title = Character.toTitleCase(propertyName.charAt(0)) + propertyName.substring(1);When propertyName is "", charAt(0) throws StringIndexOutOfBoundsException. The fallback lookup in the caller (methodCache.get("set")) is never reached — the exception propagates up before the fallback branch on lines 85–87 executes.
🟠 No null check on pluginRealm after setupPluginRealm
After calling pluginManager.setupPluginRealm(...), the code re-reads pluginDescriptor.getClassRealm(). If setupPluginRealm succeeds but fails to register a realm (unusual but possible with certain plugin descriptor inconsistencies), pluginRealm remains null. Then:
setContextClassLoader(null)silently clears the TCCLClass.forName(impl, false, null)uses the boot classloader →ClassNotFoundException- The error message
"Could not resolve Mojo parameters"with an attachedClassNotFoundExceptionis misleading since realm setup ostensibly succeeded
The finally block restores the TCCL correctly, but adding an explicit null check here makes the failure mode unambiguous.
🔵 Unbounded static caches
METHOD_CACHE and FIELD_CACHE are static ConcurrentHashMap fields keyed by Class<?>. They are never evicted. Each distinct mojo class loaded across plugin realms adds an entry that holds a strong reference to the Class<?>, keeping its ClassLoader (the plugin realm) alive indefinitely — preventing GC of the entire realm and all classes it loaded. In a long-running daemon build with many plugins this is a steady memory leak.
Consider WeakHashMap<Class<?>, ...> (with appropriate synchronization), a size-bounded LRU, or at minimum document the unbounded growth in the class Javadoc. clearCaches() exists for testing, but is not called in production.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
| private MethodInfo findCachedMethod(Class<?> beanType, String propertyName, Class<?> valueType) { | ||
| Map<String, MethodInfo> classMethodCache = METHOD_CACHE.computeIfAbsent(beanType, this::buildMethodCache); | ||
|
|
||
| String title = Character.toTitleCase(propertyName.charAt(0)) + propertyName.substring(1); |
There was a problem hiding this comment.
🔴 StringIndexOutOfBoundsException when propertyName is "": setDefault() on line 83 calls findCachedMethod(beanType, "", null). When this reaches here, propertyName.charAt(0) throws StringIndexOutOfBoundsException before the fallback classMethodCache.get("set") in the caller (lines 85–87) is reached.
| String title = Character.toTitleCase(propertyName.charAt(0)) + propertyName.substring(1); | |
| if (propertyName.isEmpty()) { | |
| return classMethodCache.get("set"); | |
| } | |
| String title = Character.toTitleCase(propertyName.charAt(0)) + propertyName.substring(1); |
| if (pluginRealm == null) { | ||
| try { | ||
| pluginManager.setupPluginRealm(pluginDescriptor, interpolationSession, null, null, null); | ||
| pluginRealm = pluginDescriptor.getClassRealm(); |
There was a problem hiding this comment.
🟠 Missing null guard: if setupPluginRealm succeeds without registering a realm, pluginRealm is null here. setContextClassLoader(null) then silently clears the TCCL, and Class.forName(..., false, null) throws ClassNotFoundException with a misleading error message. Add an explicit check:
| pluginRealm = pluginDescriptor.getClassRealm(); | |
| pluginRealm = pluginDescriptor.getClassRealm(); | |
| if (pluginRealm == null) { | |
| throw new IllegalStateException( | |
| "Plugin realm setup completed but no ClassRealm was registered for " | |
| + pluginDescriptor.getId()); | |
| } |
| private static final ConcurrentMap<Class<?>, Map<String, MethodInfo>> METHOD_CACHE = new ConcurrentHashMap<>(); | ||
|
|
||
| // Cache for field lookups: Class -> FieldName -> Field | ||
| private static final ConcurrentMap<Class<?>, Map<String, Field>> FIELD_CACHE = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
🔵 Unbounded static cache: METHOD_CACHE and FIELD_CACHE are static and never evicted. Each distinct mojo Class<?> from any plugin realm adds an entry that holds a strong reference to the Class<?> — keeping its ClassLoader (the plugin realm) alive indefinitely, preventing GC of the entire realm and all classes it loaded. clearCaches() exists for testing but is not called in production. Consider WeakHashMap<Class<?>, ...> (synchronized) or document the unbounded growth.
Overview
Implement a Mojo configuration introspection service for the Maven v4 API, allowing embedders to inspect resolved Mojo parameter values without instantiating or executing the root Mojo.
Implementation
MojoConfigurationServiceto the Maven API.Testing
git diff --check: cleanTo make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following: