-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone XmlAppendingTransformerTest (#1151)
* Add XmlAppendingTransformerTest * Add a test for checking META-INF/plugin.xml
- Loading branch information
Showing
2 changed files
with
75 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...in/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.github.jengelman.gradle.plugins.shadow.transformers | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import kotlin.io.path.appendText | ||
import org.junit.jupiter.api.Test | ||
|
||
class XmlAppendingTransformerTest : BaseTransformerTest() { | ||
@Test | ||
fun appendXmlFiles() { | ||
val propertiesXml = "properties.xml" | ||
val xmlContent = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> | ||
<properties version="1.0"> | ||
<entry key="%s">%s</entry> | ||
</properties> | ||
""".trimIndent() | ||
|
||
val xml1 = buildJar("xml1.jar") { | ||
insert(propertiesXml, xmlContent.format("key1", "val1")) | ||
} | ||
val xml2 = buildJar("xml2.jar") { | ||
insert(propertiesXml, xmlContent.format("key2", "val2")) | ||
} | ||
|
||
projectScriptPath.appendText( | ||
transform<XmlAppendingTransformer>( | ||
shadowJarBlock = fromJar(xml1, xml2), | ||
transformerBlock = """ | ||
resource = 'properties.xml' | ||
""".trimIndent(), | ||
), | ||
) | ||
|
||
run(shadowJarTask) | ||
|
||
val content = outputShadowJar.use { it.getContent(propertiesXml) }.trimIndent() | ||
assertThat(content).isEqualTo( | ||
""" | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> | ||
<properties version="1.0"> | ||
<entry key="key1">val1</entry> | ||
<entry key="key2">val2</entry> | ||
</properties> | ||
""".trimIndent(), | ||
) | ||
} | ||
|
||
@Test | ||
fun canBundleMetaInfoPluginXml() { | ||
val xmlEntry = "META-INF/plugin.xml" | ||
val xmlContent = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin> | ||
<id>my.plugin.id</id> | ||
</plugin> | ||
""".trimIndent() | ||
val pluginJar = buildJar("plugin.jar") { | ||
insert(xmlEntry, xmlContent) | ||
} | ||
|
||
projectScriptPath.appendText( | ||
transform<XmlAppendingTransformer>( | ||
shadowJarBlock = fromJar(pluginJar), | ||
), | ||
) | ||
|
||
run(shadowJarTask) | ||
|
||
val content = outputShadowJar.use { it.getContent(xmlEntry) }.trimIndent() | ||
assertThat(content).isEqualTo(xmlContent) | ||
} | ||
} |