Skip to content

Commit 26e6d4d

Browse files
authored
Improve RelocationTest and junit entry checks (#1270)
* Improve `defaultEnableRelocation` * Improve `relocateDependencyFiles` * Improve `relocateDependencyFilesWithFiltering` * Improve `remapClassNamesForRelocatedFilesInProjectSource` * Improve `relocateDoesNotDropDependencyResources` * Improve `doesNotErrorOnRelocatingJava9Classes` * Reuse `junitEntries` read from the real jar
1 parent bd6f0ce commit 26e6d4d

File tree

9 files changed

+120
-120
lines changed

9 files changed

+120
-120
lines changed

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ApplicationPluginTest : BasePluginTest() {
7373

7474
commonAssertions(
7575
jarPath("myapp-shadow/lib/myapp-1.0-all.jar", installPath),
76-
entriesContained = arrayOf("my/Main.class", "junit/framework/Test.class"),
76+
entriesContained = arrayOf("my/Main.class", *junitEntries),
7777
)
7878

7979
val unixScript = path("myapp-shadow/bin/myapp", installPath)

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ abstract class BasePluginTest {
193193
packageName: String = "my",
194194
withImports: Boolean = false,
195195
className: String = "Main",
196-
) {
196+
): String {
197197
val imports = if (withImports) "import junit.framework.Test;" else ""
198198
val classRef = if (withImports) "\"Refs: \" + Test.class.getName()" else "\"Refs: null\""
199199
path("src/$sourceSet/java/$packageName/$className.java").writeText(
@@ -212,6 +212,7 @@ abstract class BasePluginTest {
212212
}
213213
""".trimIndent(),
214214
)
215+
return packageName.replace('.', '/') + "/$className.class"
215216
}
216217

217218
fun writeClientAndServerModules(
@@ -347,6 +348,11 @@ abstract class BasePluginTest {
347348
}
348349

349350
val junitJar: Path = requireResourceAsPath("junit-3.8.2.jar")
351+
val junitEntries: Array<String> = JarPath(junitJar)
352+
.use { it.entries().toList() }
353+
.map { entry -> entry.name }
354+
.filterNot { it == "junit3.8.2/" || it.startsWith("META-INF/") }
355+
.toTypedArray()
350356

351357
val shadowJar: String = """
352358
tasks.named('$SHADOW_JAR_TASK_NAME', ${ShadowJar::class.java.name})

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class FilteringTest : BasePluginTest() {
190190
assertThat(outputServerShadowJar).useAll {
191191
containsEntries(
192192
"server/Server.class",
193-
"junit/framework/Test.class",
193+
*junitEntries,
194194
)
195195
doesNotContainEntries(
196196
"client/Client.class",
@@ -216,7 +216,7 @@ class FilteringTest : BasePluginTest() {
216216
"server/Server.class",
217217
)
218218
doesNotContainEntries(
219-
"junit/framework/Test.class",
219+
*junitEntries,
220220
)
221221
}
222222
}

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginTest.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class JavaPluginTest : BasePluginTest() {
8484
assertThat(outputShadowJar).useAll {
8585
containsEntries(
8686
"my/Main.class",
87-
"junit/framework/Test.class",
87+
*junitEntries,
8888
)
8989
}
9090
}
@@ -123,7 +123,7 @@ class JavaPluginTest : BasePluginTest() {
123123
assertThat(jarPath("build/libs/fat.jar")).useAll {
124124
containsEntries(
125125
"my/Passed.class",
126-
"junit/framework/Test.class",
126+
*junitEntries,
127127
)
128128
doesNotContainEntries("/")
129129
}
@@ -139,7 +139,7 @@ class JavaPluginTest : BasePluginTest() {
139139
containsEntries(
140140
"client/Client.class",
141141
"server/Server.class",
142-
"junit/framework/Test.class",
142+
*junitEntries,
143143
)
144144
}
145145
}
@@ -156,7 +156,7 @@ class JavaPluginTest : BasePluginTest() {
156156
)
157157
doesNotContainEntries(
158158
"client/Client.class",
159-
"junit/framework/Test.class",
159+
*junitEntries,
160160
"client/junit/framework/Test.class",
161161
)
162162
}
@@ -171,17 +171,19 @@ class JavaPluginTest : BasePluginTest() {
171171
@Test
172172
fun shadowProjectShadowJar() {
173173
writeClientAndServerModules(clientShadowed = true)
174+
val shadowedEntries = junitEntries
175+
.map { it.replace("junit/framework/", "client/junit/framework/") }.toTypedArray()
174176

175177
run(serverShadowJarTask)
176178

177179
assertThat(outputServerShadowJar).useAll {
178180
containsEntries(
179181
"client/Client.class",
180-
"client/junit/framework/Test.class",
181182
"server/Server.class",
183+
*shadowedEntries,
182184
)
183185
doesNotContainEntries(
184-
"junit/framework/Test.class",
186+
*junitEntries.filter { it.startsWith("junit/framework/") }.toTypedArray(),
185187
)
186188
}
187189
assertThat(jarPath("client/build/libs/client-1.0-all.jar")).useAll {
@@ -523,8 +525,8 @@ class JavaPluginTest : BasePluginTest() {
523525
assertThat(result).taskOutcomeEquals(":$testShadowJarTask", SUCCESS)
524526
assertThat(jarPath("build/libs/my-1.0-tests.jar")).useAll {
525527
containsEntries(
526-
"junit/framework/Test.class",
527528
"my/Main.class",
529+
*junitEntries,
528530
)
529531
getMainAttr(mainClassAttributeKey).isNotNull()
530532
}
@@ -618,7 +620,7 @@ class JavaPluginTest : BasePluginTest() {
618620
assertThat(jarPath("build/libs/my-shadow.tar")).useAll {
619621
containsEntries(
620622
"my/Main.class",
621-
"junit/framework/Test.class",
623+
*junitEntries,
622624
)
623625
}
624626
}

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/MinimizeTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class MinimizeTest : BasePluginTest() {
6363
"lib/UnusedLibEntity.class",
6464
)
6565
doesNotContainEntries(
66-
"junit/framework/Test.class",
66+
*junitEntries,
6767
)
6868
}
6969
}
@@ -123,7 +123,7 @@ class MinimizeTest : BasePluginTest() {
123123
assertThat(outputServerShadowJar).useAll {
124124
containsEntries(
125125
"server/Server.class",
126-
"junit/framework/Test.class",
126+
*junitEntries,
127127
)
128128
doesNotContainEntries(
129129
"client/Client.class",
@@ -184,7 +184,7 @@ class MinimizeTest : BasePluginTest() {
184184
containsEntries(
185185
"client/Client.class",
186186
"server/Server.class",
187-
"junit/framework/TestCase.class",
187+
*junitEntries,
188188
)
189189
}
190190

@@ -200,7 +200,7 @@ class MinimizeTest : BasePluginTest() {
200200
containsEntries(
201201
"client/Client.class",
202202
"server/Server.class",
203-
"junit/framework/TestCase.class",
203+
*junitEntries,
204204
)
205205
}
206206
}

0 commit comments

Comments
 (0)