Skip to content

Commit bd6f0ce

Browse files
authored
Replace shadow names in functional tests (#1269)
* Write test main classes to my packages by default * Replace other shadow packages * Replace groups for artifacts a, b, c, and d * Replace project names
1 parent 87d5aa8 commit bd6f0ce

File tree

11 files changed

+136
-136
lines changed

11 files changed

+136
-136
lines changed

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

Lines changed: 8 additions & 8 deletions
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("shadow/Main.class", "junit/framework/Test.class"),
76+
entriesContained = arrayOf("my/Main.class", "junit/framework/Test.class"),
7777
)
7878

7979
val unixScript = path("myapp-shadow/bin/myapp", installPath)
@@ -119,7 +119,7 @@ class ApplicationPluginTest : BasePluginTest() {
119119
projectBlock = """
120120
shadowJar {
121121
manifest {
122-
attributes '$mainClassAttributeKey': 'shadow.Main2'
122+
attributes '$mainClassAttributeKey': 'my.Main2'
123123
}
124124
}
125125
""".trimIndent(),
@@ -135,8 +135,8 @@ class ApplicationPluginTest : BasePluginTest() {
135135
assertions(run(runShadowTask).output, "foo")
136136
commonAssertions(
137137
jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar"),
138-
entriesContained = entriesInA + arrayOf("shadow/Main.class", "shadow/Main2.class"),
139-
mainClassAttr = "shadow.Main2",
138+
entriesContained = entriesInA + arrayOf("my/Main.class", "my/Main2.class"),
139+
mainClassAttr = "my.Main2",
140140
)
141141

142142
projectScriptPath.appendText(
@@ -213,7 +213,7 @@ class ApplicationPluginTest : BasePluginTest() {
213213
projectBlock: String = "",
214214
applicationBlock: String = "",
215215
settingsBlock: String = "",
216-
dependenciesBlock: String = "implementation 'shadow:a:1.0'",
216+
dependenciesBlock: String = "implementation 'my:a:1.0'",
217217
runShadowBlock: String = "",
218218
) {
219219
writeMainClass(withImports = mainClassWithImports)
@@ -222,7 +222,7 @@ class ApplicationPluginTest : BasePluginTest() {
222222
apply plugin: 'application'
223223
$projectBlock
224224
application {
225-
mainClass = 'shadow.Main'
225+
mainClass = 'my.Main'
226226
$applicationBlock
227227
}
228228
dependencies {
@@ -244,8 +244,8 @@ class ApplicationPluginTest : BasePluginTest() {
244244

245245
private fun commonAssertions(
246246
jarPath: JarPath,
247-
entriesContained: Array<String> = entriesInA + "shadow/Main.class",
248-
mainClassAttr: String = "shadow.Main",
247+
entriesContained: Array<String> = entriesInA + "my/Main.class",
248+
mainClassAttr: String = "my.Main",
249249
classPathAttr: String? = null,
250250
) {
251251
assertThat(jarPath).useAll {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ abstract class BasePluginTest {
5757
)
5858
localRepo.module("junit", "junit", "3.8.2") {
5959
useJar(junitJar)
60-
}.module("shadow", "a", "1.0") {
60+
}.module("my", "a", "1.0") {
6161
buildJar {
6262
insert("a.properties", "a")
6363
insert("a2.properties", "a2")
6464
}
65-
}.module("shadow", "b", "1.0") {
65+
}.module("my", "b", "1.0") {
6666
buildJar {
6767
insert("b.properties", "b")
6868
}
6969
}.publish()
7070

71-
artifactAJar = path("shadow/a/1.0/a-1.0.jar", parent = localRepo.root)
72-
artifactBJar = path("shadow/b/1.0/b-1.0.jar", parent = localRepo.root)
71+
artifactAJar = path("my/a/1.0/a-1.0.jar", parent = localRepo.root)
72+
artifactBJar = path("my/b/1.0/b-1.0.jar", parent = localRepo.root)
7373
entriesInA = arrayOf("a.properties", "a2.properties")
7474
entriesInB = arrayOf("b.properties")
7575
entriesInAB = entriesInA + entriesInB
@@ -98,15 +98,15 @@ abstract class BasePluginTest {
9898

9999
val projectScriptPath: Path get() = path("build.gradle")
100100
val settingsScriptPath: Path get() = path("settings.gradle")
101-
open val outputShadowJar: JarPath get() = jarPath("build/libs/shadow-1.0-all.jar")
101+
open val outputShadowJar: JarPath get() = jarPath("build/libs/my-1.0-all.jar")
102102
val outputServerShadowJar: JarPath get() = jarPath("server/build/libs/server-1.0-all.jar")
103103

104104
fun getDefaultProjectBuildScript(
105105
javaPlugin: String = "java",
106106
withGroup: Boolean = false,
107107
withVersion: Boolean = false,
108108
): String {
109-
val groupInfo = if (withGroup) "group = 'shadow'" else ""
109+
val groupInfo = if (withGroup) "group = 'my'" else ""
110110
val versionInfo = if (withVersion) "version = '1.0'" else ""
111111
return """
112112
plugins {
@@ -124,7 +124,7 @@ abstract class BasePluginTest {
124124
// this test, and we won't accidentally use cached outputs from a different test or a different build.
125125
// https://docs.gradle.org/current/userguide/build_cache.html#sec:build_cache_configure_local
126126
buildCacheBlock: String = "local { directory = file('build-cache') }",
127-
endBlock: String = "rootProject.name = 'shadow'",
127+
endBlock: String = "rootProject.name = 'my'",
128128
): String {
129129
return """
130130
$startBlock
@@ -173,31 +173,32 @@ abstract class BasePluginTest {
173173
}
174174

175175
fun publishArtifactCD(circular: Boolean = false) {
176-
localRepo.module("shadow", "c", "1.0") {
176+
localRepo.module("my", "c", "1.0") {
177177
buildJar {
178178
insert("c.properties", "c")
179179
}
180180
if (circular) {
181-
addDependency("shadow", "d", "1.0")
181+
addDependency("my", "d", "1.0")
182182
}
183-
}.module("shadow", "d", "1.0") {
183+
}.module("my", "d", "1.0") {
184184
buildJar {
185185
insert("d.properties", "d")
186186
}
187-
addDependency("shadow", "c", "1.0")
187+
addDependency("my", "c", "1.0")
188188
}.publish()
189189
}
190190

191191
fun writeMainClass(
192192
sourceSet: String = "main",
193+
packageName: String = "my",
193194
withImports: Boolean = false,
194195
className: String = "Main",
195196
) {
196197
val imports = if (withImports) "import junit.framework.Test;" else ""
197198
val classRef = if (withImports) "\"Refs: \" + Test.class.getName()" else "\"Refs: null\""
198-
path("src/$sourceSet/java/shadow/$className.java").writeText(
199+
path("src/$sourceSet/java/$packageName/$className.java").writeText(
199200
"""
200-
package shadow;
201+
package $packageName;
201202
$imports
202203
public class $className {
203204
public static void main(String[] args) {

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class FilteringTest : BasePluginTest() {
2424
projectScriptPath.appendText(
2525
"""
2626
dependencies {
27-
implementation 'shadow:a:1.0'
28-
implementation 'shadow:b:1.0'
27+
implementation 'my:a:1.0'
28+
implementation 'my:b:1.0'
2929
}
3030
""".trimIndent() + System.lineSeparator(),
3131
)
@@ -76,11 +76,11 @@ class FilteringTest : BasePluginTest() {
7676
projectScriptPath.appendText(
7777
"""
7878
dependencies {
79-
implementation 'shadow:d:1.0'
79+
implementation 'my:d:1.0'
8080
}
8181
$shadowJar {
8282
dependencies {
83-
exclude(dependency('shadow:d:.*'))
83+
exclude(dependency('my:d:.*'))
8484
}
8585
}
8686
""".trimIndent(),
@@ -100,7 +100,7 @@ class FilteringTest : BasePluginTest() {
100100
commonAssertions()
101101

102102
val replaced = projectScriptPath.readText()
103-
.replace("exclude(dependency('shadow:d:1.0'))", "exclude(dependency('shadow:c:1.0'))")
103+
.replace("exclude(dependency('my:d:1.0'))", "exclude(dependency('my:c:1.0'))")
104104
projectScriptPath.writeText(replaced)
105105
val result = run(shadowJarTask)
106106

@@ -123,7 +123,7 @@ class FilteringTest : BasePluginTest() {
123123
commonAssertions()
124124

125125
val replaced = projectScriptPath.readText()
126-
.replace("exclude(dependency('shadow:d:1.0'))", "exclude 'a.properties'")
126+
.replace("exclude(dependency('my:d:1.0'))", "exclude 'a.properties'")
127127
projectScriptPath.writeText(replaced)
128128

129129
val result = run(shadowJarTask)
@@ -147,18 +147,18 @@ class FilteringTest : BasePluginTest() {
147147
projectScriptPath.appendText(
148148
"""
149149
dependencies {
150-
implementation 'shadow:d:1.0'
150+
implementation 'my:d:1.0'
151151
}
152152
$shadowJar {
153153
dependencies {
154-
include(dependency('shadow:d:1.0'))
154+
include(dependency('my:d:1.0'))
155155
}
156156
}
157157
""".trimIndent(),
158158
)
159-
path("src/main/java/shadow/Passed.java").writeText(
159+
path("src/main/java/my/Passed.java").writeText(
160160
"""
161-
package shadow;
161+
package my;
162162
public class Passed {}
163163
""".trimIndent(),
164164
)
@@ -168,7 +168,7 @@ class FilteringTest : BasePluginTest() {
168168
assertThat(outputShadowJar).useAll {
169169
containsEntries(
170170
"d.properties",
171-
"shadow/Passed.class",
171+
"my/Passed.class",
172172
)
173173
val entries = entriesInAB + "c.properties"
174174
doesNotContainEntries(*entries)
@@ -260,11 +260,11 @@ class FilteringTest : BasePluginTest() {
260260
projectScriptPath.appendText(
261261
"""
262262
dependencies {
263-
implementation 'shadow:d:1.0'
263+
implementation 'my:d:1.0'
264264
}
265265
$shadowJar {
266266
dependencies {
267-
exclude(dependency('shadow:d:1.0'))
267+
exclude(dependency('my:d:1.0'))
268268
}
269269
}
270270
""".trimIndent(),

0 commit comments

Comments
 (0)