-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add support for complex data injection in @MojoParameter for unit testing #11426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gnodet
merged 3 commits into
apache:master
from
gnodet:feature/testing-complex-mojo-params
Nov 26, 2025
Merged
Add support for complex data injection in @MojoParameter for unit testing #11426
gnodet
merged 3 commits into
apache:master
from
gnodet:feature/testing-complex-mojo-params
Nov 26, 2025
+235
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ting Fixes apachegh-11427 This commit enhances the @MojoParameter annotation to support injection of complex data types when unit testing mojos, with comprehensive test coverage. Key features: 1. Added xml attribute to @MojoParameter annotation: - xml=true (default): Parse value as XML content (existing behavior) - xml=false: Treat value as plain text, escaping XML special characters - Enables comma-separated lists and values with special characters 2. Updated MojoExtension to handle the xml flag: - When xml=true, value is parsed as XML elements - When xml=false, value is escaped and treated as plain text - Properly handles special characters like <, >, &, etc. 3. Added comprehensive unit tests (15 new tests) covering: - List<String> with XML format - List<String> with comma-separated format using xml=false - String arrays with both XML and comma-separated formats - Map<String, String> with XML format - Properties with XML format - Custom bean objects with nested properties - Primitive types (int, boolean) - Special characters in values with xml=false 4. Fixed plugin.xml type declarations: - Changed from java.lang.List<java.lang.String> (HTML-encoded) - To java.util.List (proper Maven plugin descriptor format) - Maven's plugin descriptor doesn't support parameterized types in <type> - Added proper type declarations for Map, Properties, arrays, and custom beans All tests pass successfully (22 tests in maven-testing module).
41117ba to
ce70464
Compare
| .replace("'", "'"); | ||
| s = "<" + mp.name() + ">" + escapedValue + "</" + mp.name() + ">"; | ||
| } | ||
| try { |
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a small details (not really important), but the code could be factorized a little bit:
String value = mp.value();
if (!mp.xml()) {
// Treat as plain text - escape XML special characters
value = value
.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace("\"", """)
.replace("'", "'");
}
String s = '<' + mp.name() + '>' + value + "</" + mp.name() + '>';I also replaced strings of 1 character by single characters.
desruisseaux
approved these changes
Nov 18, 2025
impl/maven-testing/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
Outdated
Show resolved
Hide resolved
gnodet
commented
Nov 26, 2025
impl/maven-testing/src/main/java/org/apache/maven/api/plugin/testing/MojoExtension.java
Outdated
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances the
@MojoParameterannotation to support injection of complex data types when unit testing mojos, with comprehensive test coverage.Key Features
1. Added
xmlattribute to@MojoParameterannotationxml=true(default): Parse value as XML content (existing behavior)xml=false: Treat value as plain text, escaping XML special characters2. Updated
MojoExtensionto handle thexmlflagxml=true, value is parsed as XML elementsxml=false, value is escaped and treated as plain text<,>,&, etc.3. Comprehensive unit tests (15 new tests)
Covering:
List<String>with XML formatList<String>with comma-separated format usingxml=falseString[]arrays with both XML and comma-separated formatsMap<String, String>with XML formatPropertieswith XML formatint,boolean)xml=false4. Fixed plugin.xml type declarations
java.lang.List<java.lang.String>(HTML-encoded)java.util.List(proper Maven plugin descriptor format)<type>Map,Properties, arrays, and custom beansTesting
All tests pass successfully (22 tests in maven-testing module).
Example Usage
Pull Request opened by Augment Code with guidance from the PR author