Skip to content

Commit

Permalink
Split ServiceFileTransformerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jan 4, 2025
1 parent c139a52 commit d14fcaf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.jengelman.gradle.plugins.shadow.transformers

import assertk.assertThat
import assertk.assertions.exists
import assertk.assertions.isEqualTo
import kotlin.io.path.appendText
import org.junit.jupiter.api.Test

class ServiceFileTransformerTest : BaseTransformerTest() {

@Test
fun serviceResourceTransformer() {
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(buildJarOne(), buildJarTwo()),
transformerBlock = """
exclude 'META-INF/services/com.acme.*'
""".trimIndent(),
),
)

run(shadowJarTask)

assertThat(outputShadowJar).exists()

val text1 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_SHADE)
assertThat(text1).isEqualTo(CONTENT_ONE_TWO)

val text2 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_FOO)
assertThat(text2).isEqualTo("one")
}

@Test
fun serviceResourceTransformerAlternatePath() {
val one = buildJarOne {
insert(ENTRY_FOO_SHADE, CONTENT_ONE)
}
val two = buildJarTwo {
insert(ENTRY_FOO_SHADE, CONTENT_TWO)
}
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(one, two),
transformerBlock = """
path = "META-INF/foo"
""".trimIndent(),
),
)

run(shadowJarTask)

assertThat(outputShadowJar).exists()

val text = getJarFileContents(outputShadowJar, ENTRY_FOO_SHADE)
assertThat(text).isEqualTo(CONTENT_ONE_TWO)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,6 @@ import org.junit.jupiter.params.provider.MethodSource

class TransformersTest : BaseTransformerTest() {

@Test
fun serviceResourceTransformer() {
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(buildJarOne(), buildJarTwo()),
transformerBlock = """
exclude 'META-INF/services/com.acme.*'
""".trimIndent(),
),
)

run(shadowJarTask)

assertThat(outputShadowJar).exists()

val text1 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_SHADE)
assertThat(text1).isEqualTo(CONTENT_ONE_TWO)

val text2 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_FOO)
assertThat(text2).isEqualTo("one")
}

@Test
fun serviceResourceTransformerAlternatePath() {
val one = buildJarOne {
insert(ENTRY_FOO_SHADE, CONTENT_ONE)
}
val two = buildJarTwo {
insert(ENTRY_FOO_SHADE, CONTENT_TWO)
}
projectScriptPath.appendText(
transform<ServiceFileTransformer>(
shadowBlock = fromJar(one, two),
transformerBlock = """
path = "META-INF/foo"
""".trimIndent(),
),
)

run(shadowJarTask)

assertThat(outputShadowJar).exists()

val text = getJarFileContents(outputShadowJar, ENTRY_FOO_SHADE)
assertThat(text).isEqualTo(CONTENT_ONE_TWO)
}

@Test
fun serviceResourceTransformerShortSyntax() {
projectScriptPath.appendText(
Expand Down Expand Up @@ -589,7 +542,6 @@ class TransformersTest : BaseTransformerTest() {
"" to ManifestAppenderTransformer::class,
"" to ManifestResourceTransformer::class,
"{ keyTransformer = { it.toLowerCase() } }" to PropertiesFileTransformer::class,
"" to ServiceFileTransformer::class,
"" to XmlAppendingTransformer::class,
)
}
Expand Down

0 comments on commit d14fcaf

Please sign in to comment.