Skip to content

Fix @attribute prefix ignored in array elements#52

Merged
gnodet merged 1 commit into
mainfrom
fix/28-array-attributes
Jun 23, 2026
Merged

Fix @attribute prefix ignored in array elements#52
gnodet merged 1 commit into
mainfrom
fix/28-array-attributes

Conversation

@gnodet

@gnodet gnodet commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Claude Code on behalf of Guillaume Nodet

Summary

  • Fix the @ prefix for XML attributes being ignored when processing objects inside arrays in buildXmlNode
  • Two code paths in JsonReaderHelper (wrapper objects and regular objects within arrays) created child elements for all fields without checking for the @ prefix — only the top-level code path handled it correctly
  • Add test case for the shade plugin transformers use case from the issue

Example

This YAML configuration now correctly produces <transformer implementation="..."> instead of <transformer><@implementation>...</@implementation></transformer>:

configuration:
  transformers:
    - "@implementation": org.apache.maven.plugins.shade.resource.ManifestResourceTransformer
      mainClass: com.example.Main

Note: In YAML, @ is a reserved indicator, so keys starting with @ must be quoted.

Test plan

  • New test testBuildPluginConfigAttributes verifies shade plugin transformer configuration with @implementation attributes
  • All 77 existing tests pass

Fixes #28

Summary by CodeRabbit

  • New Features

    • Enhanced YAML configuration parser to support XML attributes in plugin configurations.
  • Tests

    • Added test coverage for plugin configuration attributes in Maven build scenarios.

The @ prefix for XML attributes was only handled at the top level of
buildXmlNode but not within array-of-objects processing. Fields like
@implementation in plugin configuration arrays were incorrectly created
as child elements instead of XML attributes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

buildXmlNode is updated so that fields with @-prefixed names inside array element objects are parsed as XML attributes (with the @ stripped), while non-prefixed fields remain child nodes. A new test and YAML fixture verify this behavior using maven-shade-plugin transformer configuration.

Changes

@-prefix attribute parsing in array elements

Layer / File(s) Summary
Attribute vs. child filtering in buildXmlNode
extension/src/main/java/eu/maveniverse/maven/mason/JsonReaderHelper.java
Both wrapper-object and regular-object branches in the array-element loop now separate @-prefixed fields into an XML attributes map (with @ stripped) from non-prefixed fields that become child XmlNodes. The constructed XmlNode for each element now receives the populated attributes map.
Test and YAML fixture for transformer attributes
extension/src/test/resources/yaml/build-plugin-config-attributes.yaml, extension/src/test/java/eu/maveniverse/maven/mason/YamlParserTest.java
New build-plugin-config-attributes.yaml configures maven-shade-plugin transformers using @implementation syntax. The new testBuildPluginConfigAttributes test parses this fixture and asserts the resulting Model contains the correct implementation attributes and mainClass child elements.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, an @ leads the way,
No longer a child lost in the fray.
It strips off its prefix and claims its own space,
An attribute now, with its own XML face.
The transformers rejoice—mainClass shines bright!
Little rabbit fixed YAML with one patch tonight. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing the bug where the @attribute prefix is ignored in array elements, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR directly addresses issue #28 by implementing the requested feature to handle @-prefixed attributes in array elements, enabling the exact YAML-to-XML transformation the user requested.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the @attribute prefix handling in JsonReaderHelper, with supporting test and test data files—no unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/28-array-attributes

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
extension/src/test/java/eu/maveniverse/maven/mason/YamlParserTest.java (1)

190-242: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add one assertion path for wrapper-object array entries.

This test validates the regular-object array form, but not the wrapper-object form (- transformer: { "@implementation": ... }), which is also modified in buildXmlNode. Adding that variant here (or a companion fixture) would lock both branches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extension/src/test/java/eu/maveniverse/maven/mason/YamlParserTest.java`
around lines 190 - 242, The testBuildPluginConfigAttributes method currently
validates the regular-object array form for plugin transformer configuration,
but does not test the wrapper-object form (using attributes like
"`@implementation`" instead of "implementation") which is also handled in the
buildXmlNode method. Add a new test method or companion YAML fixture that covers
the wrapper-object array entry variant to ensure both code branches are properly
tested and validated.
extension/src/main/java/eu/maveniverse/maven/mason/JsonReaderHelper.java (1)

234-259: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the object-field split into a shared helper.

Both branches now duplicate the same @-attribute vs child-node parsing. This is exactly the behavior that previously drifted between paths; centralizing it reduces regression risk.

♻️ Suggested direction
+private static ParsedXmlObject parseObjectFields(
+        JsonParser parser, InputSource inputSrc, boolean addLocationInformation) throws IOException {
+    Map<String, String> attributes = new LinkedHashMap<>();
+    List<XmlNode> children = new ArrayList<>();
+    JsonToken token = parser.currentToken();
+    while (token == JsonToken.FIELD_NAME) {
+        String field = parser.currentName();
+        token = parser.nextToken();
+        if (field.startsWith("@")) {
+            attributes.put(field.substring(1), parser.getText());
+        } else {
+            children.add(XmlNode.newInstance(
+                    field, parser.getText(), new LinkedHashMap<>(), new ArrayList<>(),
+                    createLocation(parser, inputSrc, addLocationInformation)));
+        }
+        token = parser.nextToken();
+    }
+    return new ParsedXmlObject(attributes, children);
+}

Also applies to: 260-283

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@extension/src/main/java/eu/maveniverse/maven/mason/JsonReaderHelper.java`
around lines 234 - 259, The object-field parsing logic (checking if objFieldName
starts with "@" to classify as attribute versus child node) is duplicated across
multiple branches. Extract this conditional logic that differentiates between
attributes and child nodes into a shared helper method. This helper should take
the field name, parser state, and relevant collections (objAttributes and
objectChildren), then handle the attribute-vs-child-node classification
consistently. Call this helper method from all locations where the
objFieldName.startsWith("@") pattern is currently duplicated to ensure
consistent behavior and reduce regression risk across different parsing paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@extension/src/main/java/eu/maveniverse/maven/mason/JsonReaderHelper.java`:
- Around line 234-259: The object-field parsing logic (checking if objFieldName
starts with "@" to classify as attribute versus child node) is duplicated across
multiple branches. Extract this conditional logic that differentiates between
attributes and child nodes into a shared helper method. This helper should take
the field name, parser state, and relevant collections (objAttributes and
objectChildren), then handle the attribute-vs-child-node classification
consistently. Call this helper method from all locations where the
objFieldName.startsWith("@") pattern is currently duplicated to ensure
consistent behavior and reduce regression risk across different parsing paths.

In `@extension/src/test/java/eu/maveniverse/maven/mason/YamlParserTest.java`:
- Around line 190-242: The testBuildPluginConfigAttributes method currently
validates the regular-object array form for plugin transformer configuration,
but does not test the wrapper-object form (using attributes like
"`@implementation`" instead of "implementation") which is also handled in the
buildXmlNode method. Add a new test method or companion YAML fixture that covers
the wrapper-object array entry variant to ensure both code branches are properly
tested and validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0ef9c5f-459a-4c31-b67a-2f4562b6bcd7

📥 Commits

Reviewing files that changed from the base of the PR and between 7999a2e and a9ed878.

📒 Files selected for processing (3)
  • extension/src/main/java/eu/maveniverse/maven/mason/JsonReaderHelper.java
  • extension/src/test/java/eu/maveniverse/maven/mason/YamlParserTest.java
  • extension/src/test/resources/yaml/build-plugin-config-attributes.yaml

@gnodet gnodet merged commit 27c498e into main Jun 23, 2026
12 checks passed
@gnodet gnodet deleted the fix/28-array-attributes branch June 23, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Description internal properties of the tag

1 participant