Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,46 +231,56 @@ public static XmlNode buildXmlNode(JsonParser parser, InputSource inputSrc, bool
// Skip the wrapper field, use its contents directly
token = parser.nextToken(); // Move to the start of inner object
if (token == JsonToken.START_OBJECT) {
Map<String, String> objAttributes = new LinkedHashMap<>();
List<XmlNode> objectChildren = new ArrayList<>();
while ((token = parser.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
String objFieldName = parser.currentName();
token = parser.nextToken();
objectChildren.add(XmlNode.newInstance(
objFieldName,
parser.getText(),
new LinkedHashMap<>(),
new ArrayList<>(),
createLocation(parser, inputSrc, addLocationInformation)));
if (objFieldName.startsWith("@")) {
objAttributes.put(objFieldName.substring(1), parser.getText());
} else {
objectChildren.add(XmlNode.newInstance(
objFieldName,
parser.getText(),
new LinkedHashMap<>(),
new ArrayList<>(),
createLocation(parser, inputSrc, addLocationInformation)));
}
}
}
parser.nextToken(); // Skip the outer object's END_OBJECT
arrayChildren.add(XmlNode.newInstance(
singularName,
null,
new LinkedHashMap<>(),
objAttributes,
objectChildren,
createLocation(parser, inputSrc, addLocationInformation)));
}
} else {
// Regular object, process its fields
Map<String, String> objAttributes = new LinkedHashMap<>();
List<XmlNode> objectChildren = new ArrayList<>();
parser.currentName(); // Reset to first field
while (token == JsonToken.FIELD_NAME) {
String objFieldName = parser.currentName();
token = parser.nextToken();
objectChildren.add(XmlNode.newInstance(
objFieldName,
parser.getText(),
new LinkedHashMap<>(),
new ArrayList<>(),
createLocation(parser, inputSrc, addLocationInformation)));
if (objFieldName.startsWith("@")) {
objAttributes.put(objFieldName.substring(1), parser.getText());
} else {
objectChildren.add(XmlNode.newInstance(
objFieldName,
parser.getText(),
new LinkedHashMap<>(),
new ArrayList<>(),
createLocation(parser, inputSrc, addLocationInformation)));
}
token = parser.nextToken();
}
arrayChildren.add(XmlNode.newInstance(
singularName,
null,
new LinkedHashMap<>(),
objAttributes,
objectChildren,
createLocation(parser, inputSrc, addLocationInformation)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,60 @@ void testBuildPlugins() throws Exception {
assertModelEquals(expected, actual);
}

@Test
void testBuildPluginConfigAttributes() throws Exception {
Model actual = loadAndParse("build-plugin-config-attributes.yaml");
Model expected = Model.newBuilder()
.modelVersion("4.0.0")
.groupId("org.apache.maven.extensions")
.artifactId("maven-yaml-extension")
.version("1.0.0-SNAPSHOT")
.name("Maven YAML Extension")
.build(Build.newBuilder()
.plugins(List.of(Plugin.newBuilder()
.groupId("org.apache.maven.plugins")
.artifactId("maven-shade-plugin")
.version("3.5.0")
.configuration(XmlNode.newInstance(
"configuration",
null,
null,
List.of(XmlNode.newInstance(
"transformers",
null,
null,
List.of(
XmlNode.newInstance(
"transformer",
null,
Map.of(
"implementation",
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"),
List.of(
XmlNode.newInstance(
"mainClass",
"com.example.Main",
null,
null,
null)),
null),
XmlNode.newInstance(
"transformer",
null,
Map.of(
"implementation",
"org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"),
null,
null)),
null)),
null))
.build()))
.build())
.build();

assertModelEquals(expected, actual);
}

@Test
void testBuildExtensions() throws Exception {
Model actual = loadAndParse("build-extensions.yaml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##
## Copyright (c) 2025 Guillaume Nodet
##
## This program and the accompanying materials are made available under
## the terms of the Eclipse Public License 2.0 which accompanies this
## distribution and is available at:
## https://www.eclipse.org/legal/epl-2.0/
##
## SPDX-License-Identifier: EPL-2.0
##
modelVersion: 4.0.0
groupId: org.apache.maven.extensions
artifactId: maven-yaml-extension
version: 1.0.0-SNAPSHOT
name: Maven YAML Extension
build:
plugins:
- id: org.apache.maven.plugins:maven-shade-plugin:3.5.0
configuration:
transformers:
- "@implementation": org.apache.maven.plugins.shade.resource.ManifestResourceTransformer
mainClass: com.example.Main
- "@implementation": org.apache.maven.plugins.shade.resource.ServicesResourceTransformer
Loading