Repository: GradleUp/shadow (kotlin)

Issue:
Allow XmlAppendingTransformer to merge nested levels
Idea is to merge xml respecting levels

```
<a><b /></a>
```

and

```
<a><c/></a>
```

will be

```
<a><b/><c/></a>
```

Pull request:
- Closes #168.
- Follow up #1151.

Patch:
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.kt
index ed0b8d52d..f60d034de 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformer.kt
@@ -52,7 +52,7 @@ public open class XmlAppendingTransformer @Inject constructor(
         }
       }.build(context.inputStream)
     } catch (e: JDOMException) {
-      throw RuntimeException("Error processing resource $resource: ${e.message}", e)
+      throw RuntimeException("Error processing resource ${resource.get()}: ${e.message}", e)
     }
 
     if (doc == null) {


Test patch:
diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt
index 41f215257..b29eec5ab 100644
--- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt
+++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt
@@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers
 
 import assertk.assertThat
 import assertk.assertions.isEqualTo
+import com.github.jengelman.gradle.plugins.shadow.util.Issue
 import com.github.jengelman.gradle.plugins.shadow.util.getContent
 import kotlin.io.path.appendText
 import org.junit.jupiter.api.Test
@@ -9,7 +10,7 @@ import org.junit.jupiter.api.Test
 class XmlAppendingTransformerTest : BaseTransformerTest() {
   @Test
   fun appendXmlFiles() {
-    val propertiesXml = "properties.xml"
+    val xmlEntry = "properties.xml"
     val xmlContent = """
       <?xml version="1.0" encoding="UTF-8"?>
       <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
@@ -17,26 +18,25 @@ class XmlAppendingTransformerTest : BaseTransformerTest() {
         <entry key="%s">%s</entry>
       </properties>
     """.trimIndent()
-
-    val xml1 = buildJar("xml1.jar") {
-      insert(propertiesXml, xmlContent.format("key1", "val1"))
+    val one = buildJarOne {
+      insert(xmlEntry, xmlContent.format("key1", "val1"))
     }
-    val xml2 = buildJar("xml2.jar") {
-      insert(propertiesXml, xmlContent.format("key2", "val2"))
+    val two = buildJarTwo {
+      insert(xmlEntry, xmlContent.format("key2", "val2"))
     }
 
     projectScriptPath.appendText(
       transform<XmlAppendingTransformer>(
-        shadowJarBlock = fromJar(xml1, xml2),
+        shadowJarBlock = fromJar(one, two),
         transformerBlock = """
-          resource = 'properties.xml'
+          resource = '$xmlEntry'
         """.trimIndent(),
       ),
     )
 
     run(shadowJarTask)
 
-    val content = outputShadowJar.use { it.getContent(propertiesXml) }.trimIndent()
+    val content = outputShadowJar.use { it.getContent(xmlEntry) }.trimIndent()
     assertThat(content).isEqualTo(
       """
         <?xml version="1.0" encoding="UTF-8"?>
@@ -49,28 +49,43 @@ class XmlAppendingTransformerTest : BaseTransformerTest() {
     )
   }
 
+  @Issue(
+    "https://github.com/GradleUp/shadow/issues/168",
+  )
   @Test
-  fun canBundleMetaInfoPluginXml() {
-    val xmlEntry = "META-INF/plugin.xml"
+  fun canMergeNestedLevels() {
+    val xmlEntry = "META-INF/nested.xml"
     val xmlContent = """
       <?xml version="1.0" encoding="UTF-8"?>
-      <plugin>
-        <id>my.plugin.id</id>
-      </plugin>
+      <a>%s</a>
     """.trimIndent()
-    val pluginJar = buildJar("plugin.jar") {
-      insert(xmlEntry, xmlContent)
+    val one = buildJarOne {
+      insert(xmlEntry, xmlContent.format("<b />"))
+    }
+    val two = buildJarTwo {
+      insert(xmlEntry, xmlContent.format("<c />"))
     }
 
     projectScriptPath.appendText(
       transform<XmlAppendingTransformer>(
-        shadowJarBlock = fromJar(pluginJar),
+        shadowJarBlock = fromJar(one, two),
+        transformerBlock = """
+          resource = '$xmlEntry'
+        """.trimIndent(),
       ),
     )
 
     run(shadowJarTask)
 
     val content = outputShadowJar.use { it.getContent(xmlEntry) }.trimIndent()
-    assertThat(content).isEqualTo(xmlContent)
+    assertThat(content).isEqualTo(
+      """
+        <?xml version="1.0" encoding="UTF-8"?>
+        <a>
+          <b />
+          <c />
+        </a>
+      """.trimIndent(),
+    )
   }
 }