@@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.internal
22
33import assertk.assertThat
44import assertk.assertions.contains
5+ import assertk.assertions.doesNotContain
56import assertk.assertions.isEqualTo
67import assertk.assertions.isTrue
78import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator
@@ -19,6 +20,8 @@ import kotlin.reflect.KClass
1920import org.gradle.api.file.FileCopyDetails
2021import org.junit.jupiter.api.Test
2122import org.junit.jupiter.api.io.TempDir
23+ import org.junit.jupiter.params.ParameterizedTest
24+ import org.junit.jupiter.params.provider.ValueSource
2225
2326/* *
2427 * The cases reflect the cases in
@@ -143,13 +146,15 @@ class BytecodeRemappingTest {
143146 .contains(" (L$relocatedFixtureBase ;L$relocatedFixtureBase ;)L$relocatedFixtureBase ;" )
144147 }
145148
146- @Test
147- fun methodPrimitivePlusClassIsRelocated () {
149+ @ParameterizedTest
150+ @ValueSource(chars = [' B' , ' C' , ' D' , ' F' , ' I' , ' J' , ' S' , ' Z' ])
151+ fun primitivePlusClassMethodIsRelocated (primitiveDescriptor : Char ) {
148152 val result = fixtureSubjectDetails.remapClass(relocators)
149153
150154 val classModel = ClassFile .of().parse(result)
151155 val methodDescriptors = classModel.methods().map { it.methodType().stringValue() }
152- assertThat(methodDescriptors).contains(" (BL$relocatedFixtureBase ;)L$relocatedFixtureBase ;" )
156+ assertThat(methodDescriptors)
157+ .contains(" (${primitiveDescriptor} L$relocatedFixtureBase ;)L$relocatedFixtureBase ;" )
153158 }
154159
155160 @Test
@@ -162,7 +167,46 @@ class BytecodeRemappingTest {
162167 classModel.constantPool().mapNotNull { entry ->
163168 if (entry is java.lang.classfile.constantpool.StringEntry ) entry.stringValue() else null
164169 }
165- assertThat(stringConstants).contains(" com.example.relocated.BytecodeRemappingTest\$ FixtureBase" )
170+ assertThat(stringConstants)
171+ .contains($$" com.example.relocated.BytecodeRemappingTest$FixtureBase " )
172+ }
173+
174+ @Test
175+ fun stringConstantNotRelocatedWhenSkipEnabled () {
176+ val skipRelocators =
177+ setOf (
178+ SimpleRelocator (
179+ " com.github.jengelman.gradle.plugins.shadow.internal" ,
180+ " com.example.relocated" ,
181+ skipStringConstants = true ,
182+ )
183+ )
184+ val result = fixtureSubjectDetails.remapClass(skipRelocators)
185+
186+ val classModel = ClassFile .of().parse(result)
187+ val stringConstants =
188+ classModel.constantPool().mapNotNull { entry ->
189+ if (entry is java.lang.classfile.constantpool.StringEntry ) entry.stringValue() else null
190+ }
191+ assertThat(stringConstants)
192+ .doesNotContain($$" com.example.relocated.BytecodeRemappingTest$FixtureBase " )
193+ }
194+
195+ @Test
196+ fun multiClassDescriptorStringConstantIsRelocated () {
197+ val result = fixtureSubjectDetails.remapClass(relocators)
198+
199+ val classModel = ClassFile .of().parse(result)
200+ val stringConstants =
201+ classModel.constantPool().mapNotNull { entry ->
202+ if (entry is java.lang.classfile.constantpool.StringEntry ) entry.stringValue() else null
203+ }
204+ // Verify that two adjacent class references in a single string constant are both relocated
205+ // (regression test for the issue-1403 pattern).
206+ assertThat(stringConstants)
207+ .contains(
208+ $$" ()Lcom/example/relocated/BytecodeRemappingTest$FixtureBase ;Lcom/example/relocated/BytecodeRemappingTest$FixtureBase ;"
209+ )
166210 }
167211
168212 @Test
@@ -258,13 +302,29 @@ class BytecodeRemappingTest {
258302 val array2dField: Array <Array <FixtureBase >> = emptyArray()
259303 val stringConstant: String =
260304 $$" com.github.jengelman.gradle.plugins.shadow.internal.BytecodeRemappingTest$FixtureBase "
305+ val multiClassDescriptor: String =
306+ $$" ()Lcom/github/jengelman/gradle/plugins/shadow/internal/BytecodeRemappingTest$FixtureBase ;Lcom/github/jengelman/gradle/plugins/shadow/internal/BytecodeRemappingTest$FixtureBase ;"
261307
262308 fun method (arg : FixtureBase ): FixtureBase = arg
263309
264310 fun methodMultiArgs (a : FixtureBase , b : FixtureBase ): FixtureBase = a
265311
266312 fun methodWithPrimitivePlusClass (b : Byte , arg : FixtureBase ): FixtureBase = arg
267313
314+ fun methodWithCharPlusClass (c : Char , arg : FixtureBase ): FixtureBase = arg
315+
316+ fun methodWithDoublePlusClass (d : Double , arg : FixtureBase ): FixtureBase = arg
317+
318+ fun methodWithFloatPlusClass (f : Float , arg : FixtureBase ): FixtureBase = arg
319+
320+ fun methodWithIntPlusClass (i : Int , arg : FixtureBase ): FixtureBase = arg
321+
322+ fun methodWithLongPlusClass (l : Long , arg : FixtureBase ): FixtureBase = arg
323+
324+ fun methodWithShortPlusClass (s : Short , arg : FixtureBase ): FixtureBase = arg
325+
326+ fun methodWithBooleanPlusClass (z : Boolean , arg : FixtureBase ): FixtureBase = arg
327+
268328 fun methodWithCheckCast (arg : Any ): FixtureBase {
269329 (arg as FixtureBase ).toString()
270330 return arg
0 commit comments