Skip to content
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

[MNG-7632] Regression: combine.children breaks when combining executions #1168

Merged
merged 3 commits into from
Jun 19, 2023
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 @@ -225,14 +225,14 @@ public static XmlNode merge(XmlNode dominant, XmlNode recessive, Boolean childMe

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());
}
Expand All @@ -243,7 +243,7 @@ public static XmlNode merge(XmlNode dominant, XmlNode recessive, Boolean childMe
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;
}
Expand Down Expand Up @@ -344,14 +344,7 @@ public static XmlNode merge(XmlNode dominant, XmlNode recessive, Boolean childMe
}
}

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,36 @@ void testShouldRemoveDoNotRemoveTagWhenSwappedInputDOMs() throws Exception {
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());
}
Expand Down