Skip to content

Commit 2bbe80b

Browse files
committed
Cleanups
1 parent 735d8c4 commit 2bbe80b

15 files changed

+46
-66
lines changed

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import assertk.assertions.exists
88
import assertk.assertions.isEqualTo
99
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
1010
import com.github.jengelman.gradle.plugins.shadow.util.isRegular
11-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
1211
import kotlin.io.path.appendText
1312
import kotlin.io.path.readText
1413
import kotlin.io.path.writeText

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.github.jengelman.gradle.plugins.shadow
22

33
import assertk.Assert
4+
import assertk.all
5+
import assertk.assertThat
6+
import assertk.assertions.doesNotContain
47
import assertk.assertions.isEqualTo
58
import assertk.assertions.isNotNull
69
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME
@@ -10,6 +13,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1013
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
1114
import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenRepository
1215
import com.github.jengelman.gradle.plugins.shadow.util.JarPath
16+
import java.io.Closeable
1317
import java.nio.file.Path
1418
import java.util.Properties
1519
import kotlin.io.path.ExperimentalPathApi
@@ -35,7 +39,7 @@ import org.junit.jupiter.api.TestInstance
3539

3640
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3741
abstract class BasePluginTest {
38-
lateinit var root: Path
42+
lateinit var projectRoot: Path
3943
lateinit var localRepo: AppendableMavenRepository
4044

4145
@BeforeAll
@@ -60,7 +64,7 @@ abstract class BasePluginTest {
6064

6165
@BeforeEach
6266
open fun setup() {
63-
root = createTempDirectory()
67+
projectRoot = createTempDirectory()
6468

6569
projectScriptPath.writeText(getDefaultProjectBuildScript(withGroup = true, withVersion = true))
6670
settingsScriptPath.writeText(getDefaultSettingsBuildScript())
@@ -71,7 +75,7 @@ abstract class BasePluginTest {
7175
fun cleanup() {
7276
runCatching {
7377
// TODO: workaround for https://github.com/junit-team/junit5/issues/2811.
74-
root.deleteRecursively()
78+
projectRoot.deleteRecursively()
7579
}
7680

7781
println(projectScriptPath.readText())
@@ -82,6 +86,15 @@ abstract class BasePluginTest {
8286
localRepo.root.deleteRecursively()
8387
}
8488

89+
open val shadowJarTask = ":$SHADOW_JAR_TASK_NAME"
90+
open val runShadowTask = ":$SHADOW_RUN_TASK_NAME"
91+
val serverShadowJarTask = ":server:$SHADOW_JAR_TASK_NAME"
92+
93+
val projectScriptPath: Path get() = path("build.gradle")
94+
val settingsScriptPath: Path get() = path("settings.gradle")
95+
open val outputShadowJar: JarPath get() = jarPath("build/libs/shadow-1.0-all.jar")
96+
val outputServerShadowJar: JarPath get() = jarPath("server/build/libs/server-1.0-all.jar")
97+
8598
fun getDefaultProjectBuildScript(
8699
javaPlugin: String = "java",
87100
withGroup: Boolean = false,
@@ -115,32 +128,16 @@ abstract class BasePluginTest {
115128
""".trimIndent() + System.lineSeparator()
116129
}
117130

118-
open val shadowJarTask = ":$SHADOW_JAR_TASK_NAME"
119-
open val runShadowTask = ":$SHADOW_RUN_TASK_NAME"
120-
val serverShadowJarTask = ":server:$SHADOW_JAR_TASK_NAME"
121-
122-
val projectScriptPath: Path
123-
get() = path("build.gradle")
124-
125-
val settingsScriptPath: Path
126-
get() = path("settings.gradle")
127-
128-
open val outputShadowJar: JarPath
129-
get() = jarPath("build/libs/shadow-1.0-all.jar")
130-
131-
val outputServerShadowJar: JarPath
132-
get() = jarPath("server/build/libs/server-1.0-all.jar")
133-
134131
fun jarPath(path: String): JarPath {
135-
val realPath = root.resolve(path).also {
132+
val realPath = projectRoot.resolve(path).also {
136133
check(it.exists()) { "Path not found: $it" }
137134
check(it.isRegularFile()) { "Path is not a regular file: $it" }
138135
}
139136
return JarPath(realPath)
140137
}
141138

142139
fun path(path: String): Path {
143-
return root.resolve(path).also {
140+
return projectRoot.resolve(path).also {
144141
if (it.exists()) return@also
145142
it.parent.createDirectories()
146143
// We should create text file only if it doesn't exist.
@@ -300,7 +297,7 @@ abstract class BasePluginTest {
300297

301298
fun runner(
302299
arguments: Iterable<String> = emptyList(),
303-
projectDir: Path? = root,
300+
projectDir: Path? = projectRoot,
304301
): GradleRunner = GradleRunner.create()
305302
.forwardOutput()
306303
.withPluginClasspath()
@@ -362,18 +359,20 @@ abstract class BasePluginTest {
362359
}
363360

364361
fun BuildResult.assertNoDeprecationWarnings() = apply {
365-
output.lines().forEach {
366-
assert(!containsDeprecationWarning(it))
367-
}
362+
assertThat(output).doesNotContain(
363+
"has been deprecated and is scheduled to be removed in Gradle",
364+
"has been deprecated. This is scheduled to be removed in Gradle",
365+
)
368366
}
369367

370-
fun Assert<BuildResult>.taskOutcomeEquals(taskPath: String, expectedOutcome: TaskOutcome) {
371-
return transform { it.task(taskPath)?.outcome }.isNotNull().isEqualTo(expectedOutcome)
368+
fun <T : Closeable> Assert<T>.useAll(body: Assert<T>.() -> Unit) = all {
369+
body()
370+
// Close the resource after all assertions are done.
371+
given { it.use(block = {}) }
372372
}
373373

374-
private fun containsDeprecationWarning(output: String): Boolean {
375-
return output.contains("has been deprecated and is scheduled to be removed in Gradle") ||
376-
output.contains("has been deprecated. This is scheduled to be removed in Gradle")
374+
fun Assert<BuildResult>.taskOutcomeEquals(taskPath: String, expectedOutcome: TaskOutcome) {
375+
return transform { it.task(taskPath)?.outcome }.isNotNull().isEqualTo(expectedOutcome)
377376
}
378377
}
379378
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow
33
import assertk.assertThat
44
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
55
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
6-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
76
import kotlin.io.path.appendText
87
import kotlin.io.path.readText
98
import kotlin.io.path.writeText
@@ -201,13 +200,13 @@ class FilteringTest : BasePluginTest() {
201200
run(serverShadowJarTask)
202201

203202
assertThat(outputServerShadowJar).useAll {
204-
doesNotContainEntries(
205-
"client/Client.class",
206-
)
207203
containsEntries(
208204
"server/Server.class",
209205
"junit/framework/Test.class",
210206
)
207+
doesNotContainEntries(
208+
"client/Client.class",
209+
)
211210
}
212211
}
213212

@@ -224,13 +223,13 @@ class FilteringTest : BasePluginTest() {
224223
run(serverShadowJarTask)
225224

226225
assertThat(outputServerShadowJar).useAll {
227-
doesNotContainEntries(
228-
"junit/framework/Test.class",
229-
)
230226
containsEntries(
231227
"client/Client.class",
232228
"server/Server.class",
233229
)
230+
doesNotContainEntries(
231+
"junit/framework/Test.class",
232+
)
234233
}
235234
}
236235

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/PublishingTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.github.jengelman.gradle.plugins.shadow.util.Issue
99
import com.github.jengelman.gradle.plugins.shadow.util.JarPath
1010
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
1111
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
12-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
1312
import com.squareup.moshi.JsonAdapter
1413
import com.squareup.moshi.Moshi
1514
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
@@ -33,12 +32,12 @@ class PublishingTest : BasePluginTest() {
3332
private val gmmAdapter = moshi.adapter(GradleModuleMetadata::class.java)
3433
private val pomReader = MavenXpp3Reader()
3534

36-
private lateinit var remoteRepo: Path
35+
private lateinit var remoteRepoPath: Path
3736

3837
@BeforeEach
3938
override fun setup() {
4039
super.setup()
41-
remoteRepo = root.resolve("remote-maven-repo")
40+
remoteRepoPath = projectRoot.resolve("remote-maven-repo")
4241
settingsScriptPath.appendText("rootProject.name = 'maven'" + System.lineSeparator())
4342
}
4443

@@ -216,7 +215,7 @@ class PublishingTest : BasePluginTest() {
216215
}
217216

218217
private fun repoPath(path: String): Path {
219-
return remoteRepo.resolve(path).also {
218+
return remoteRepoPath.resolve(path).also {
220219
check(it.exists()) { "Path not found: $it" }
221220
check(it.isRegularFile()) { "Path is not a regular file: $it" }
222221
}
@@ -257,7 +256,7 @@ class PublishingTest : BasePluginTest() {
257256
}
258257
repositories {
259258
maven {
260-
url = '${remoteRepo.toUri()}'
259+
url = '${remoteRepoPath.toUri()}'
261260
}
262261
}
263262
}

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import assertk.assertFailure
44
import assertk.assertThat
55
import assertk.assertions.isEqualTo
66
import assertk.assertions.isInstanceOf
7+
import assertk.fail
78
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHADOW_JAR_TASK_NAME
89
import com.github.jengelman.gradle.plugins.shadow.util.Issue
910
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
1011
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
11-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
1212
import java.net.URLClassLoader
1313
import kotlin.io.path.appendText
1414
import kotlin.io.path.writeText
1515
import org.junit.jupiter.api.Test
16-
import org.junit.jupiter.api.fail
1716
import org.opentest4j.AssertionFailedError
1817

1918
class RelocationTest : BasePluginTest() {
20-
2119
@Test
2220
fun defaultEnableRelocation() {
2321
projectScriptPath.appendText(

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.github.jengelman.gradle.plugins.shadow.util.Issue
1313
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
1414
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
1515
import com.github.jengelman.gradle.plugins.shadow.util.isRegular
16-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
1716
import kotlin.io.path.appendText
1817
import kotlin.io.path.readText
1918
import kotlin.io.path.writeText
@@ -27,7 +26,6 @@ import org.junit.jupiter.api.condition.EnabledForJreRange
2726
import org.junit.jupiter.api.condition.JRE
2827

2928
class ShadowPluginTest : BasePluginTest() {
30-
3129
@Test
3230
fun applyPlugin() {
3331
val projectName = "my-shadow"

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/BaseCachingTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE
1616
import org.junit.jupiter.api.BeforeEach
1717
import org.junit.jupiter.api.io.TempDir
1818

19-
sealed class BaseCachingTest : BasePluginTest() {
20-
19+
abstract class BaseCachingTest : BasePluginTest() {
2120
@TempDir
2221
lateinit var alternateDir: Path
2322

@@ -48,7 +47,7 @@ sealed class BaseCachingTest : BasePluginTest() {
4847
// ignore if the file does not exist
4948
}
5049
alternateDir.deleteRecursively()
51-
root.copyToRecursively(alternateDir, followLinks = false, overwrite = false)
50+
projectRoot.copyToRecursively(alternateDir, followLinks = false, overwrite = false)
5251
// check that shadowJar pulls from cache in the original directory
5352
assertShadowJarHasResult(firstOutcome)
5453
// check that shadowJar pulls from cache in a different directory

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/MinimizationCachingTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import assertk.assertThat
44
import com.github.jengelman.gradle.plugins.shadow.util.JarPath
55
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
66
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
7-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
87
import kotlin.io.path.appendText
98
import kotlin.io.path.writeText
109
import org.junit.jupiter.api.Test

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/RelocationCachingTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow.caching
33
import assertk.assertThat
44
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
55
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
6-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
76
import kotlin.io.path.appendText
87
import org.junit.jupiter.api.Test
98

src/funcTest/kotlin/com/github/jengelman/gradle/plugins/shadow/caching/ShadowJarCachingTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import assertk.assertThat
44
import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
55
import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries
66
import com.github.jengelman.gradle.plugins.shadow.util.isRegular
7-
import com.github.jengelman.gradle.plugins.shadow.util.useAll
87
import kotlin.io.path.appendText
98
import kotlin.io.path.readText
109
import kotlin.io.path.writeText

0 commit comments

Comments
 (0)