diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt index a883faf8a..7a525bb8f 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt @@ -3,27 +3,36 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.util.getContent -import java.nio.file.Path import kotlin.io.path.appendText -import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource class AppendingTransformerTest : BaseTransformerTest() { - @Test - fun appendTestProperties() { + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun appendTestProperties(shortSyntax: Boolean) { val one = buildJarOne { insert(ENTRY_TEST_PROPERTIES, CONTENT_ONE) } val two = buildJarTwo { insert(ENTRY_TEST_PROPERTIES, CONTENT_TWO) } - projectScriptPath.appendText( + val config = if (shortSyntax) { + """ + $shadowJar { + ${fromJar(one, two)} + append('$ENTRY_TEST_PROPERTIES') + } + """.trimIndent() + } else { transform( shadowJarBlock = fromJar(one, two), transformerBlock = """ resource = '$ENTRY_TEST_PROPERTIES' """.trimIndent(), - ), - ) + ) + } + projectScriptPath.appendText(config) run(shadowJarTask) @@ -31,68 +40,44 @@ class AppendingTransformerTest : BaseTransformerTest() { assertThat(content).isEqualTo(CONTENT_ONE_TWO) } - @Test - fun appendTestPropertiesShortSyntax() { + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun appendApplicationYaml(shortSyntax: Boolean) { val one = buildJarOne { - insert(ENTRY_TEST_PROPERTIES, CONTENT_ONE) + insert("resources/$APPLICATION_YML_FILE", CONTENT_ONE) + insert("resources/config/$APPLICATION_YML_FILE", CONTENT_TWO) } val two = buildJarTwo { - insert(ENTRY_TEST_PROPERTIES, CONTENT_TWO) + insert("resources/$APPLICATION_YML_FILE", CONTENT_TWO) + insert("resources/config/$APPLICATION_YML_FILE", CONTENT_THREE) } - projectScriptPath.appendText( + val config = if (shortSyntax) { """ $shadowJar { ${fromJar(one, two)} - append('$ENTRY_TEST_PROPERTIES') + append('resources/$APPLICATION_YML_FILE', '$APPLICATION_YML_SEPARATOR') + append('resources/config/$APPLICATION_YML_FILE', '$APPLICATION_YML_SEPARATOR') } - """.trimIndent(), - ) - - run(shadowJarTask) - - val content = outputShadowJar.use { it.getContent(ENTRY_TEST_PROPERTIES) } - assertThat(content).isEqualTo(CONTENT_ONE_TWO) - } - - @Test - fun appendApplicationYaml() { - val (one, two) = writeApplicationYamlJars() - - projectScriptPath.appendText( - transform( + """.trimIndent() + } else { + val block1 = transform( shadowJarBlock = fromJar(one, two), transformerBlock = """ resource = 'resources/$APPLICATION_YML_FILE' separator = '$APPLICATION_YML_SEPARATOR' """.trimIndent(), - ), - ) - - run(shadowJarTask) - - val content = outputShadowJar.use { it.getContent("resources/$APPLICATION_YML_FILE") } - assertThat(content).isEqualTo( - """ - $CONTENT_ONE - --- - $CONTENT_TWO - """.trimIndent(), - ) - } + ) + val block2 = transform( + shadowJarBlock = fromJar(one, two), + transformerBlock = """ + resource = 'resources/config/$APPLICATION_YML_FILE' + separator = '$APPLICATION_YML_SEPARATOR' + """.trimIndent(), + ) + block1 + System.lineSeparator() + block2 + } - @Test - fun appendApplicationYamlShortSyntax() { - val (one, two) = writeApplicationYamlJars() - - projectScriptPath.appendText( - """ - $shadowJar { - ${fromJar(one, two)} - append('resources/$APPLICATION_YML_FILE', '$APPLICATION_YML_SEPARATOR') - append('resources/config/$APPLICATION_YML_FILE', '$APPLICATION_YML_SEPARATOR') - } - """.trimIndent(), - ) + projectScriptPath.appendText(config) run(shadowJarTask) @@ -114,18 +99,6 @@ class AppendingTransformerTest : BaseTransformerTest() { ) } - private fun writeApplicationYamlJars(): Pair { - val one = buildJarOne { - insert("resources/$APPLICATION_YML_FILE", CONTENT_ONE) - insert("resources/config/$APPLICATION_YML_FILE", CONTENT_TWO) - } - val two = buildJarTwo { - insert("resources/$APPLICATION_YML_FILE", CONTENT_TWO) - insert("resources/config/$APPLICATION_YML_FILE", CONTENT_THREE) - } - return one to two - } - private companion object { const val APPLICATION_YML_FILE = "application.yml" const val APPLICATION_YML_SEPARATOR = "\\n---\\n" diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt index a13a43dbb..ecb4a6991 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt @@ -14,15 +14,26 @@ import com.github.jengelman.gradle.plugins.shadow.util.getContent import java.nio.file.Path import kotlin.io.path.appendText import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource class GroovyExtensionModuleTransformerTest : BaseTransformerTest() { - @Test - fun groovyExtensionModuleTransformer() { - projectScriptPath.appendText( + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun groovyExtensionModuleTransformer(shortSyntax: Boolean) { + val config = if (shortSyntax) { + """ + $shadowJar { + ${fromJar(buildJarFoo(), buildJarBar())} + mergeGroovyExtensionModules() + } + """.trimIndent() + } else { transform( shadowJarBlock = fromJar(buildJarFoo(), buildJarBar()), - ), - ) + ) + } + projectScriptPath.appendText(config) run(shadowJarTask) @@ -45,22 +56,6 @@ class GroovyExtensionModuleTransformerTest : BaseTransformerTest() { commonAssertions(PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR) } - @Test - fun groovyExtensionModuleTransformerShortSyntax() { - projectScriptPath.appendText( - """ - $shadowJar { - ${fromJar(buildJarFoo(), buildJarBar())} - mergeGroovyExtensionModules() - } - """.trimIndent(), - ) - - run(shadowJarTask) - - commonAssertions(PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR) - } - private fun buildJarFoo( entry: String = PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR, ): Path = buildJar("foo.jar") { diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index 8fef8b325..684f95bbf 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -7,18 +7,31 @@ import com.github.jengelman.gradle.plugins.shadow.util.getContent import kotlin.io.path.appendText import kotlin.io.path.writeText import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource class ServiceFileTransformerTest : BaseTransformerTest() { - @Test - fun serviceResourceTransformer() { - projectScriptPath.appendText( + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun serviceResourceTransformer(shortSyntax: Boolean) { + val config = if (shortSyntax) { + """ + $shadowJar { + ${fromJar(buildJarOne(), buildJarTwo())} + mergeServiceFiles { + exclude 'META-INF/services/com.acme.*' + } + } + """.trimIndent() + } else { transform( shadowJarBlock = fromJar(buildJarOne(), buildJarTwo()), transformerBlock = """ exclude 'META-INF/services/com.acme.*' """.trimIndent(), - ), - ) + ) + } + projectScriptPath.appendText(config) run(shadowJarTask) @@ -28,22 +41,31 @@ class ServiceFileTransformerTest : BaseTransformerTest() { } } - @Test - fun serviceResourceTransformerAlternatePath() { + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun serviceResourceTransformerAlternatePath(shortSyntax: Boolean) { val one = buildJarOne { insert(ENTRY_FOO_SHADE, CONTENT_ONE) } val two = buildJarTwo { insert(ENTRY_FOO_SHADE, CONTENT_TWO) } - projectScriptPath.appendText( + val config = if (shortSyntax) { + """ + $shadowJar { + ${fromJar(one, two)} + mergeServiceFiles("META-INF/foo") + } + """.trimIndent() + } else { transform( shadowJarBlock = fromJar(one, two), transformerBlock = """ path = 'META-INF/foo' """.trimIndent(), - ), - ) + ) + } + projectScriptPath.appendText(config) run(shadowJarTask) @@ -52,28 +74,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { } @Test - fun serviceResourceTransformerShortSyntax() { - projectScriptPath.appendText( - """ - $shadowJar { - ${fromJar(buildJarOne(), buildJarTwo())} - mergeServiceFiles { - exclude 'META-INF/services/com.acme.*' - } - } - """.trimIndent(), - ) - - run(shadowJarTask) - - assertThat(outputShadowJar).useAll { - getContent(ENTRY_SERVICES_SHADE).isEqualTo(CONTENT_ONE_TWO) - getContent(ENTRY_SERVICES_FOO).isEqualTo("one") - } - } - - @Test - fun serviceResourceTransformerShortSyntaxRelocation() { + fun serviceResourceTransformerRelocation() { val one = buildJarOne { insert( "META-INF/services/java.sql.Driver", @@ -148,29 +149,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { } } - @Test - fun serviceResourceTransformerShortSyntaxAlternatePath() { - val one = buildJarOne { - insert(ENTRY_FOO_SHADE, CONTENT_ONE) - } - val two = buildJarTwo { - insert(ENTRY_FOO_SHADE, CONTENT_TWO) - } - projectScriptPath.appendText( - """ - $shadowJar { - ${fromJar(one, two)} - mergeServiceFiles("META-INF/foo") - } - """.trimIndent(), - ) - - run(shadowJarTask) - - val content = outputShadowJar.use { it.getContent(ENTRY_FOO_SHADE) } - assertThat(content).isEqualTo(CONTENT_ONE_TWO) - } - @Issue( "https://github.com/GradleUp/shadow/issues/70", "https://github.com/GradleUp/shadow/issues/71",