This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 441ba71b0 [MNG-7632] Regression: combine.children breaks when
combining executions (#1168)
441ba71b0 is described below
commit 441ba71b0499a20da3004f44c56576385bd05e96
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Jun 19 17:07:18 2023 +0200
[MNG-7632] Regression: combine.children breaks when combining executions
(#1168)
---
.../org/apache/maven/internal/xml/XmlNodeImpl.java | 19 +++++---------
.../apache/maven/internal/xml/XmlNodeImplTest.java | 30 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git
a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
index 7dbfc8344..f40511279 100644
---
a/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
+++
b/maven-xml-impl/src/main/java/org/apache/maven/internal/xml/XmlNodeImpl.java
@@ -225,14 +225,14 @@ public class XmlNodeImpl implements Serializable, XmlNode
{
String value = dominant.getValue();
Object location = dominant.getInputLocation();
- Map<String, String> attrs = null;
+ Map<String, String> attrs = dominant.getAttributes();
List<XmlNode> children = null;
for (Map.Entry<String, String> attr :
recessive.getAttributes().entrySet()) {
String key = attr.getKey();
- if (isEmpty(dominant.getAttribute(key))) {
- if (attrs == null) {
- attrs = new HashMap<>();
+ if (isEmpty(attrs.get(key))) {
+ if (attrs == dominant.getAttributes()) {
+ attrs = new HashMap<>(attrs);
}
attrs.put(key, attr.getValue());
}
@@ -243,7 +243,7 @@ public class XmlNodeImpl implements Serializable, XmlNode {
if (childMergeOverride != null) {
mergeChildren = childMergeOverride;
} else {
- String childMergeMode =
dominant.getAttribute(CHILDREN_COMBINATION_MODE_ATTRIBUTE);
+ String childMergeMode =
attrs.get(CHILDREN_COMBINATION_MODE_ATTRIBUTE);
if (CHILDREN_COMBINATION_APPEND.equals(childMergeMode)) {
mergeChildren = false;
}
@@ -344,14 +344,7 @@ public class XmlNodeImpl implements Serializable, XmlNode {
}
}
- if (value != null || attrs != null || children != null) {
- if (attrs != null) {
- Map<String, String> nattrs = attrs;
- attrs = new HashMap<>(dominant.getAttributes());
- attrs.putAll(nattrs);
- } else {
- attrs = dominant.getAttributes();
- }
+ if (value != null || attrs != dominant.getAttributes() || children
!= null) {
if (children == null) {
children = dominant.getChildren();
}
diff --git
a/maven-xml-impl/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
b/maven-xml-impl/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
index 88618ab5b..5fd8080a8 100644
---
a/maven-xml-impl/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
+++
b/maven-xml-impl/src/test/java/org/apache/maven/internal/xml/XmlNodeImplTest.java
@@ -610,6 +610,36 @@ class XmlNodeImplTest {
assertEquals(recessiveConfig.toString(), result.toString());
}
+ @Test
+ void testMergeCombineChildrenAppendOnRecessive() throws
XmlPullParserException, IOException {
+ String dominant = "<relocations>\n" + " <relocation>\n"
+ + "
<pattern>org.apache.shiro.crypto.CipherService</pattern>\n"
+ + "
<shadedPattern>org.apache.shiro.crypto.cipher.CipherService</shadedPattern>\n"
+ + " </relocation>\n"
+ + "</relocations>";
+ String recessive = "<relocations combine.children=\"append\">\n"
+ + " <relocation>\n"
+ + " <pattern>javax.faces</pattern>\n"
+ + " <shadedPattern>jakarta.faces</shadedPattern>\n"
+ + " </relocation>\n"
+ + "</relocations>";
+ String expected = "<relocations combine.children=\"append\">\n"
+ + " <relocation>\n"
+ + " <pattern>javax.faces</pattern>\n"
+ + " <shadedPattern>jakarta.faces</shadedPattern>\n"
+ + " </relocation>\n"
+ + " <relocation>\n"
+ + "
<pattern>org.apache.shiro.crypto.CipherService</pattern>\n"
+ + "
<shadedPattern>org.apache.shiro.crypto.cipher.CipherService</shadedPattern>\n"
+ + " </relocation>\n"
+ + "</relocations>";
+
+ XmlNodeImpl d = XmlNodeBuilder.build(new StringReader(dominant));
+ XmlNodeImpl r = XmlNodeBuilder.build(new StringReader(recessive));
+ XmlNode m = d.merge(r);
+ assertEquals(expected, m.toString().replaceAll("\r\n", "\n"));
+ }
+
private static List<XmlNode> getChildren(XmlNode node, String name) {
return node.getChildren().stream().filter(n ->
n.getName().equals(name)).collect(Collectors.toList());
}