Skip to content

Commit 8e2af9a

Browse files
CopilotGoooler
andcommitted
Fix skipStringConstants per-relocator behavior: use continue instead of return
Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
1 parent 154c2d4 commit 8e2af9a

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

  • src
    • main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal
    • test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Relocators.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private fun Set<Relocator>.realMap(name: String, mapLiterals: Boolean): String {
3535

3636
for (relocator in this) {
3737
if (mapLiterals && relocator.skipStringConstants) {
38-
return name
38+
continue
3939
} else if (relocator.canRelocateClass(newName)) {
4040
return prefix + relocator.relocateClass(newName) + suffix
4141
} else if (relocator.canRelocatePath(newName)) {

src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatorsTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
33
import assertk.assertThat
44
import assertk.assertions.isEqualTo
55
import com.github.jengelman.gradle.plugins.shadow.internal.mapName
6+
import org.junit.jupiter.api.Test
67
import org.junit.jupiter.params.ParameterizedTest
78
import org.junit.jupiter.params.provider.Arguments
89
import org.junit.jupiter.params.provider.MethodSource
@@ -15,6 +16,29 @@ class RelocatorsTest {
1516
assertThat(relocators.mapName(input)).isEqualTo(expected)
1617
}
1718

19+
/**
20+
* Verifies that a relocator with [Relocator.skipStringConstants] = true is skipped individually
21+
* when mapping literals, rather than short-circuiting the entire set of relocators.
22+
*/
23+
@Test
24+
fun skipStringConstantsIsPerRelocator() {
25+
val skippingRelocator =
26+
SimpleRelocator("org.package", "shadow.org.package", skipStringConstants = true)
27+
val normalRelocator = SimpleRelocator("com.example", "shadow.com.example")
28+
val relocators = linkedSetOf(skippingRelocator, normalRelocator)
29+
30+
// The skipping relocator cannot match "com.example.Foo", but the normal one can.
31+
// Ensure the normal relocator is still applied even though the first one has skipStringConstants.
32+
assertThat(relocators.mapName("com.example.Foo", mapLiterals = true))
33+
.isEqualTo("shadow.com.example.Foo")
34+
// When mapLiterals=true, the skipping relocator should not apply to its own pattern.
35+
assertThat(relocators.mapName("org.package.Bar", mapLiterals = true))
36+
.isEqualTo("org.package.Bar")
37+
// When mapLiterals=false, the skipping relocator applies normally.
38+
assertThat(relocators.mapName("org.package.Bar", mapLiterals = false))
39+
.isEqualTo("shadow.org.package.Bar")
40+
}
41+
1842
private companion object {
1943
val primitiveTypes = setOf('B', 'C', 'D', 'F', 'I', 'J', 'S', 'Z')
2044

0 commit comments

Comments
 (0)