gnodet opened a new pull request, #11426:
URL: https://github.com/apache/maven/pull/11426

   This PR 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. 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&lt;java.lang.String&gt;` (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
   
   ## Testing
   All tests pass successfully (22 tests in maven-testing module).
   
   ## Example Usage
   
   ```java
   // Comma-separated list
   @Test
   @InjectMojo(goal = "my-goal", pom = "pom.xml")
   @MojoParameter(name = "items", value = "one,two,three", xml = false)
   public void testCommaSeparatedList(MyMojo mojo) {
       assertEquals(List.of("one", "two", "three"), mojo.items);
   }
   
   // XML format (default)
   @Test
   @InjectMojo(goal = "my-goal", pom = "pom.xml")
   @MojoParameter(name = "items", value = "<item>one</item><item>two</item>")
   public void testXmlList(MyMojo mojo) {
       assertEquals(List.of("one", "two"), mojo.items);
   }
   
   // Complex bean
   @Test
   @InjectMojo(goal = "my-goal", pom = "pom.xml")
   @MojoParameter(name = "config", value = 
"<host>localhost</host><port>8080</port>")
   public void testBean(MyMojo mojo) {
       assertEquals("localhost", mojo.config.host);
       assertEquals(8080, mojo.config.port);
   }
   ```
   
   ---
   Pull Request opened by [Augment Code](https://www.augmentcode.com/) with 
guidance from the PR author


-- 
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]

Reply via email to