From 60b563dce5e65f1143bd6de9b727846a93f429b0 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 21:06:05 +0800 Subject: [PATCH 01/13] Add Path.toJarFile --- .../jengelman/gradle/plugins/shadow/ApplicationTest.kt | 3 +-- .../jengelman/gradle/plugins/shadow/BasePluginTest.kt | 6 ++++-- .../jengelman/gradle/plugins/shadow/RelocationTest.kt | 3 +-- .../gradle/plugins/shadow/ShadowPluginTest.kt | 10 +++++----- .../plugins/shadow/transformers/BaseTransformerTest.kt | 3 +-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 6fe3f2464..445a230ac 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -5,7 +5,6 @@ import assertk.assertions.contains import assertk.assertions.containsAtLeast import assertk.assertions.exists import assertk.assertions.isEqualTo -import java.util.jar.JarFile import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText @@ -44,7 +43,7 @@ class ApplicationTest : BasePluginTest() { assertContains(installedJar, listOf("a.properties", "a2.properties", "myapp/Main.class")) - val jarFile = JarFile(installedJar.toFile()) + val jarFile = installedJar.toJarFile() assertThat(jarFile.manifest.mainAttributes.getValue("Main-Class")) .isEqualTo("myapp.Main") diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index 52f2e216a..059f85707 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -145,7 +145,7 @@ abstract class BasePluginTest { } fun assertContains(jarPath: Path, paths: List) { - JarFile(jarPath.toFile()).use { jar -> + jarPath.toJarFile().use { jar -> paths.forEach { path -> assert(jar.getJarEntry(path) != null) { "Jar file $jarPath does not contain entry $path" } } @@ -153,7 +153,7 @@ abstract class BasePluginTest { } fun assertDoesNotContain(jarPath: Path, paths: List) { - JarFile(jarPath.toFile()).use { jar -> + jarPath.toJarFile().use { jar -> paths.forEach { path -> assert(jar.getJarEntry(path) == null) { "Jar file $jarPath contains entry $path" } } @@ -331,6 +331,8 @@ abstract class BasePluginTest { fun String.toProperties(): Properties = Properties().apply { load(byteInputStream()) } + fun Path.toJarFile(): JarFile = JarFile(toFile()) + fun fromJar(vararg paths: Path): String { return paths.joinToString(System.lineSeparator()) { "from('${it.toUri().toURL().path}')" } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index b0e002124..70421c84e 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -7,7 +7,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf import com.github.jengelman.gradle.plugins.shadow.util.Issue import java.net.URLClassLoader -import java.util.jar.JarFile import kotlin.io.path.appendText import kotlin.io.path.writeText import org.junit.jupiter.api.Test @@ -116,7 +115,7 @@ class RelocationTest : BasePluginTest() { ), ) - val jarFile = JarFile(outputShadowJar.toFile()) + val jarFile = outputShadowJar.toJarFile() assertThat(jarFile.manifest.mainAttributes.getValue("TEST-VALUE")).isEqualTo("FOO") } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index fc639d8e8..cc8e835b2 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -536,7 +536,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val entries = JarFile(outputShadowJar.toFile()).entries().toList() + val entries = outputShadowJar.toJarFile().entries().toList() assertThat(entries.size).isEqualTo(2) } @@ -553,7 +553,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = JarFile(outputShadowJar.toFile()).manifest.mainAttributes + val attributes = outputShadowJar.toJarFile().manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isNull() } @@ -578,7 +578,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = JarFile(outputShadowJar.toFile()).manifest.mainAttributes + val attributes = outputShadowJar.toJarFile().manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isEqualTo("/libs/a.jar junit-3.8.2.jar") } @@ -598,7 +598,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = JarFile(outputShadowJar.toFile()).manifest.mainAttributes + val attributes = outputShadowJar.toJarFile().manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isEqualTo("junit-3.8.2.jar") } @@ -757,7 +757,7 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputShadowJar).exists() - val entries = JarFile(outputShadowJar.toFile()).entries().toList() + val entries = outputShadowJar.toJarFile().entries().toList() assertThat(entries.count { it.name.endsWith(".class") }).isEqualTo(1) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt index 31e35640c..e95ae9889 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt @@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import com.github.jengelman.gradle.plugins.shadow.BasePluginTest import com.github.jengelman.gradle.plugins.shadow.util.AppendableJar import java.nio.file.Path -import java.util.jar.JarFile import kotlin.io.path.writeText sealed class BaseTransformerTest : BasePluginTest() { @@ -57,7 +56,7 @@ sealed class BaseTransformerTest : BasePluginTest() { const val ENTRY_GROOVY_EXTENSION_MODULE = "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule" fun getJarFileContents(jarPath: Path, entryName: String): String { - JarFile(jarPath.toFile()).use { jar -> + jarPath.toJarFile().use { jar -> val entry = jar.getJarEntry(entryName) ?: error("Entry not found: $entryName") return jar.getInputStream(entry).bufferedReader().readText() } From 1768d0a180f0ac338a54977aaf32cb0c9bb774c7 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 21:33:24 +0800 Subject: [PATCH 02/13] Add JarPath to simplify assertions --- .../gradle/plugins/shadow/ApplicationTest.kt | 10 +- .../gradle/plugins/shadow/BasePluginTest.kt | 30 ++--- .../plugins/shadow/ConfigurationCacheSpec.kt | 15 +-- .../gradle/plugins/shadow/FilteringTest.kt | 53 +++----- .../gradle/plugins/shadow/RelocationTest.kt | 40 +++---- .../gradle/plugins/shadow/ShadowPluginTest.kt | 113 +++++++----------- .../transformers/BaseTransformerTest.kt | 7 -- .../ServiceFileTransformerTest.kt | 22 ++-- .../shadow/transformers/TransformersTest.kt | 69 +++++------ .../gradle/plugins/shadow/util/JarPath.kt | 52 ++++++++ 10 files changed, 184 insertions(+), 227 deletions(-) create mode 100644 src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 445a230ac..f889cba51 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -5,6 +5,7 @@ import assertk.assertions.contains import assertk.assertions.containsAtLeast import assertk.assertions.exists import assertk.assertions.isEqualTo +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText @@ -38,13 +39,12 @@ class ApplicationTest : BasePluginTest() { assertThat(result.output).contains("Running application with JDK 17") assertThat(result.output).contains("TestApp: Hello World! (foo)") - val installedJar = path("build/install/myapp-shadow/lib/myapp-1.0-all.jar") + val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar") assertThat(installedJar).exists() - assertContains(installedJar, listOf("a.properties", "a2.properties", "myapp/Main.class")) + installedJar.assertContains(listOf("a.properties", "a2.properties", "myapp/Main.class")) - val jarFile = installedJar.toJarFile() - assertThat(jarFile.manifest.mainAttributes.getValue("Main-Class")) + assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class")) .isEqualTo("myapp.Main") path("build/install/myapp-shadow/bin/myapp").let { startScript -> @@ -83,7 +83,7 @@ class ApplicationTest : BasePluginTest() { run(ShadowApplicationPlugin.SHADOW_INSTALL_TASK_NAME) - assertThat(path("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).exists() + assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).exists() } private fun prepare( diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index 059f85707..897fe010f 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -5,9 +5,9 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHA import com.github.jengelman.gradle.plugins.shadow.tasks.JavaJarExec import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenFileRepository +import com.github.jengelman.gradle.plugins.shadow.util.JarPath import java.nio.file.Path import java.util.Properties -import java.util.jar.JarFile import kotlin.io.path.ExperimentalPathApi import kotlin.io.path.Path import kotlin.io.path.absolutePathString @@ -123,11 +123,13 @@ abstract class BasePluginTest { val settingsScriptPath: Path get() = path("settings.gradle") - val outputShadowJar: Path - get() = path("build/libs/shadow-1.0-all.jar") + val outputShadowJar: JarPath + get() = jarPath("build/libs/shadow-1.0-all.jar") - val outputServerShadowJar: Path - get() = path("server/build/libs/server-1.0-all.jar") + val outputServerShadowJar: JarPath + get() = jarPath("server/build/libs/server-1.0-all.jar") + + fun jarPath(path: String): JarPath = JarPath(path(path)) fun path(path: String): Path { return root.resolve(path).also { @@ -144,22 +146,6 @@ abstract class BasePluginTest { return AppendableMavenFileRepository(root.resolve(path)) } - fun assertContains(jarPath: Path, paths: List) { - jarPath.toJarFile().use { jar -> - paths.forEach { path -> - assert(jar.getJarEntry(path) != null) { "Jar file $jarPath does not contain entry $path" } - } - } - } - - fun assertDoesNotContain(jarPath: Path, paths: List) { - jarPath.toJarFile().use { jar -> - paths.forEach { path -> - assert(jar.getJarEntry(path) == null) { "Jar file $jarPath contains entry $path" } - } - } - } - private val runner: GradleRunner get() { return GradleRunner.create() @@ -331,8 +317,6 @@ abstract class BasePluginTest { fun String.toProperties(): Properties = Properties().apply { load(byteInputStream()) } - fun Path.toJarFile(): JarFile = JarFile(toFile()) - fun fromJar(vararg paths: Path): String { return paths.joinToString(System.lineSeparator()) { "from('${it.toUri().toURL().path}')" } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt index 05857c983..aeebc5154 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt @@ -2,11 +2,10 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains -import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isNotNull +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText -import kotlin.io.path.deleteExisting import kotlin.io.path.writeText import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.TaskOutcome @@ -76,12 +75,10 @@ class ConfigurationCacheSpec : BasePluginTest() { outputShadowJar.deleteExisting() val result = run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "b.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("a2.properties"), ) result.assertCcReused() @@ -102,12 +99,10 @@ class ConfigurationCacheSpec : BasePluginTest() { val result = run(shadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("server/Server.class", "junit/framework/Test.class"), ) - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("client/Client.class"), ) result.assertCcReused() diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt index 08c2f4cf5..5ac93ecdd 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt @@ -1,9 +1,9 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat -import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isNotNull +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText @@ -32,8 +32,7 @@ class FilteringTest : BasePluginTest() { @Test fun includeAllDependencies() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "a2.properties", "b.properties"), ) } @@ -50,12 +49,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "b.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("a2.properties"), ) } @@ -107,12 +104,10 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "a2.properties", "b.properties", "d.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("c.properties"), ) } @@ -134,12 +129,10 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a2.properties", "b.properties", "c.properties", "d.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("a.properties"), ) } @@ -168,12 +161,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("d.properties", "shadow/Passed.class"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("a.properties", "a2.properties", "b.properties", "c.properties"), ) } @@ -191,12 +182,10 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("client/Client.class"), ) - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("server/Server.class", "junit/framework/Test.class"), ) } @@ -214,12 +203,10 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("junit/framework/Test.class"), ) - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class"), ) } @@ -238,12 +225,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "b.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("a2.properties"), ) } @@ -274,12 +259,10 @@ class FilteringTest : BasePluginTest() { } private fun commonAssertions() { - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "a2.properties", "b.properties", "c.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("d.properties"), ) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index 70421c84e..6908a7cb3 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -2,10 +2,10 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertFailure import assertk.assertThat -import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf import com.github.jengelman.gradle.plugins.shadow.util.Issue +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import java.net.URLClassLoader import kotlin.io.path.appendText import kotlin.io.path.writeText @@ -27,8 +27,7 @@ class RelocationTest : BasePluginTest() { ) run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "META-INF/MANIFEST.MF", "shadow/junit/textui/ResultPrinter.class", @@ -72,8 +71,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "META-INF/MANIFEST.MF", "a/ResultPrinter.class", @@ -94,8 +92,7 @@ class RelocationTest : BasePluginTest() { ), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf( "junit/textui/ResultPrinter.class", "junit/textui/TestRunner.class", @@ -115,8 +112,7 @@ class RelocationTest : BasePluginTest() { ), ) - val jarFile = outputShadowJar.toJarFile() - assertThat(jarFile.manifest.mainAttributes.getValue("TEST-VALUE")).isEqualTo("FOO") + assertThat(outputShadowJar.manifest.mainAttributes.getValue("TEST-VALUE")).isEqualTo("FOO") } @Test @@ -139,8 +135,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "a/ResultPrinter.class", "b/Test.class", @@ -154,8 +149,7 @@ class RelocationTest : BasePluginTest() { ), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf( "a/TestRunner.class", "b/Assert.class", @@ -166,8 +160,7 @@ class RelocationTest : BasePluginTest() { ), ) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "junit/textui/TestRunner.class", "junit/framework/Assert.class", @@ -212,8 +205,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "shadow/ShadowTest.class", "shadow/junit/Test.class", @@ -221,8 +213,7 @@ class RelocationTest : BasePluginTest() { ), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf( "junit/framework", "junit/framework/Test.class", @@ -298,11 +289,10 @@ class RelocationTest : BasePluginTest() { run(":app:$shadowJarTask") - val appOutput = path("app/build/libs/app-all.jar") + val appOutput = jarPath("app/build/libs/app-all.jar") assertThat(appOutput).exists() - assertContains( - appOutput, + appOutput.assertContains( listOf( "TEST", "APP-TEST", @@ -345,16 +335,14 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf( "bar/Foo.class", "bar/foo.properties", "bar/dep.properties", ), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf( "foo/Foo.class", "foo/foo.properties", diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index cc8e835b2..dad8098fc 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -2,7 +2,6 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains -import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import assertk.assertions.isNull @@ -10,7 +9,7 @@ import assertk.assertions.isTrue import com.github.jengelman.gradle.plugins.shadow.legacy.LegacyShadowPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.Issue -import java.util.jar.JarFile +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.toPath @@ -123,15 +122,13 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) - val outputShadowJar = path("build/libs/shadow.jar") + val outputShadowJar = jarPath("build/libs/shadow.jar") assertThat(outputShadowJar).exists() - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("shadow/Passed.class", "junit/framework/Test.class"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("/"), ) } @@ -143,8 +140,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class", "junit/framework/Test.class"), ) } @@ -174,12 +170,10 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class"), ) - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("junit/framework/Test.class"), ) } @@ -202,12 +196,10 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("server/Server.class", "junit/framework/Test.class"), ) - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("client/Client.class"), ) } @@ -229,8 +221,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class"), ) } @@ -261,8 +252,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), ) @@ -276,8 +266,7 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputServerShadowJar).exists() // TODO: I don't think junit classes should be in the output jar, but it's the test case // from https://github.com/GradleUp/shadow/pull/420, need to investigate more... - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), ) } @@ -292,15 +281,13 @@ class ShadowPluginTest : BasePluginTest() { writeApiLibAndImplModules() run(":impl:$shadowJarTask") - val implOutput = path("impl/build/libs/impl-all.jar") + val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() - assertContains( - implOutput, + implOutput.assertContains( listOf("impl/SimpleEntity.class", "api/Entity.class", "api/UnusedEntity.class", "lib/LibEntity.class"), ) - assertDoesNotContain( - implOutput, + implOutput.assertDoesNotContain( listOf("junit/framework/Test.class", "lib/UnusedLibEntity.class"), ) } @@ -324,11 +311,10 @@ class ShadowPluginTest : BasePluginTest() { ) run(":impl:$shadowJarTask") - val implOutput = path("impl/build/libs/impl-all.jar") + val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() - assertContains( - implOutput, + implOutput.assertContains( listOf( "impl/SimpleEntity.class", "api/Entity.class", @@ -337,8 +323,7 @@ class ShadowPluginTest : BasePluginTest() { "lib/UnusedLibEntity.class", ), ) - assertDoesNotContain( - implOutput, + implOutput.assertDoesNotContain( listOf("junit/framework/Test.class"), ) } @@ -348,21 +333,18 @@ class ShadowPluginTest : BasePluginTest() { writeShadowedClientAndServerModules() run(":server:jar") - val serverOutput = path("server/build/libs/server-1.0.jar") - val clientOutput = path("client/build/libs/client-all.jar") + val serverOutput = jarPath("server/build/libs/server-1.0.jar") + val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(serverOutput).exists() - assertContains( - serverOutput, + serverOutput.assertContains( listOf("server/Server.class"), ) - assertDoesNotContain( - serverOutput, + serverOutput.assertDoesNotContain( listOf("client/Client.class", "junit/framework/Test.class", "client/junit/framework/Test.class"), ) assertThat(clientOutput).exists() - assertContains( - clientOutput, + clientOutput.assertContains( listOf("client/Client.class", "client/junit/framework/Test.class"), ) } @@ -372,20 +354,17 @@ class ShadowPluginTest : BasePluginTest() { writeShadowedClientAndServerModules() run(serverShadowJarTask) - val clientOutput = path("client/build/libs/client-all.jar") + val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(outputServerShadowJar).exists() - assertContains( - outputServerShadowJar, + outputServerShadowJar.assertContains( listOf("client/Client.class", "client/junit/framework/Test.class", "server/Server.class"), ) - assertDoesNotContain( - outputServerShadowJar, + outputServerShadowJar.assertDoesNotContain( listOf("junit/framework/Test.class"), ) assertThat(clientOutput).exists() - assertContains( - clientOutput, + clientOutput.assertContains( listOf("client/Client.class", "client/junit/framework/Test.class"), ) } @@ -418,12 +397,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("shadow/Passed.class", "a.properties", "META-INF/a.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("META-INF/INDEX.LIST", "META-INF/a.SF", "META-INF/a.DSA", "META-INF/a.RSA", "module-info.class"), ) } @@ -444,12 +421,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "a2.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("b.properties"), ) } @@ -483,8 +458,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("api.properties", "implementation.properties", "runtimeOnly.properties", "implementation-dep.properties"), ) } @@ -505,12 +479,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertContains( - outputShadowJar, + outputShadowJar.assertContains( listOf("a.properties", "a2.properties"), ) - assertDoesNotContain( - outputShadowJar, + outputShadowJar.assertDoesNotContain( listOf("b.properties"), ) } @@ -536,8 +508,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val entries = outputShadowJar.toJarFile().entries().toList() - assertThat(entries.size).isEqualTo(2) + assertThat(outputShadowJar.entries().toList().size).isEqualTo(2) } @Test @@ -553,7 +524,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = outputShadowJar.toJarFile().manifest.mainAttributes + val attributes = outputShadowJar.manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isNull() } @@ -578,7 +549,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = outputShadowJar.toJarFile().manifest.mainAttributes + val attributes = outputShadowJar.manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isEqualTo("/libs/a.jar junit-3.8.2.jar") } @@ -598,8 +569,8 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val attributes = outputShadowJar.toJarFile().manifest.mainAttributes - assertThat(attributes.getValue("Class-Path")).isEqualTo("junit-3.8.2.jar") + assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path")) + .isEqualTo("junit-3.8.2.jar") } @Issue( @@ -757,7 +728,7 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputShadowJar).exists() - val entries = outputShadowJar.toJarFile().entries().toList() + val entries = outputShadowJar.entries().toList() assertThat(entries.count { it.name.endsWith(".class") }).isEqualTo(1) } @@ -783,13 +754,13 @@ class ShadowPluginTest : BasePluginTest() { ) val result = run(testShadowJarTask) - val testJar = path("build/libs/shadow-1.0-tests.jar") + val testJar = jarPath("build/libs/shadow-1.0-tests.jar") assertThat(result.task(":$testShadowJarTask")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) assertThat(testJar).exists() - assertThat(JarFile(testJar.toFile()).getEntry("junit")).isNotNull() + assertThat(testJar.getEntry("junit")).isNotNull() } private fun writeShadowedClientAndServerModules() { diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt index e95ae9889..12b732786 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/BaseTransformerTest.kt @@ -55,13 +55,6 @@ sealed class BaseTransformerTest : BasePluginTest() { const val ENTRY_SERVICE_EXTENSION_MODULE = "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule" const val ENTRY_GROOVY_EXTENSION_MODULE = "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule" - fun getJarFileContents(jarPath: Path, entryName: String): String { - jarPath.toJarFile().use { jar -> - val entry = jar.getJarEntry(entryName) ?: error("Entry not found: $entryName") - return jar.getInputStream(entry).bufferedReader().readText() - } - } - inline fun transform( shadowJarBlock: String = "", transformerBlock: String = "", diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index 47a58eecb..63f554e40 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -1,9 +1,9 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat -import assertk.assertions.exists import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.util.Issue +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import org.junit.jupiter.api.Test @@ -25,10 +25,10 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text1 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_SHADE) + val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - val text2 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_FOO) + val text2 = outputShadowJar.getEntryContent(ENTRY_SERVICES_FOO) assertThat(text2).isEqualTo("one") } @@ -53,7 +53,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, ENTRY_FOO_SHADE) + val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -74,10 +74,10 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text1 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_SHADE) + val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - val text2 = getJarFileContents(outputShadowJar, ENTRY_SERVICES_FOO) + val text2 = outputShadowJar.getEntryContent(ENTRY_SERVICES_FOO) assertThat(text2).isEqualTo("one") } @@ -126,7 +126,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text1 = getJarFileContents(outputShadowJar, "META-INF/services/java.sql.Driver") + val text1 = outputShadowJar.getEntryContent("META-INF/services/java.sql.Driver") assertThat(text1).isEqualTo( """ oracle.jdbc.OracleDriver @@ -136,7 +136,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { """.trimIndent(), ) - val text2 = getJarFileContents(outputShadowJar, "META-INF/services/myapache.axis.components.compiler.Compiler") + val text2 = outputShadowJar.getEntryContent("META-INF/services/myapache.axis.components.compiler.Compiler") assertThat(text2).isEqualTo( """ myapache.axis.components.compiler.Javac @@ -144,7 +144,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { """.trimIndent(), ) - val text3 = getJarFileContents(outputShadowJar, "META-INF/services/org.apache.commons.logging.LogFactory") + val text3 = outputShadowJar.getEntryContent("META-INF/services/org.apache.commons.logging.LogFactory") assertThat(text3).isEqualTo( """ myapache.commons.logging.impl.LogFactoryImpl @@ -174,7 +174,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, ENTRY_FOO_SHADE) + val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -209,7 +209,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, servicesShadowEntry) + val text = outputShadowJar.getEntryContent(servicesShadowEntry) assertThat(text).isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO) } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 85371752e..0c58e9b88 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -1,14 +1,12 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat -import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue -import java.util.jar.JarInputStream +import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists import kotlin.io.path.appendText -import kotlin.io.path.inputStream import kotlin.io.path.writeText import kotlin.reflect.KClass import org.junit.jupiter.api.Test @@ -38,7 +36,7 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, ENTRY_TEST_PROPERTIES) + val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -63,7 +61,7 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, ENTRY_TEST_PROPERTIES) + val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -85,12 +83,10 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - JarInputStream(outputShadowJar.inputStream()).use { jis -> - val mf = jis.manifest - assertThat(mf).isNotNull() - assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") - assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") - } + val mf = outputShadowJar.manifest + assertThat(mf).isNotNull() + assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") + assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") } @Test @@ -118,13 +114,11 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - JarInputStream(outputShadowJar.inputStream()).use { jis -> - val mf = jis.manifest - assertThat(mf).isNotNull() - assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") - assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") - assertThat(mf.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") - } + val mf = outputShadowJar.manifest + assertThat(mf).isNotNull() + assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") + assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") + assertThat(mf.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") } @Test @@ -166,7 +160,7 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val text = getJarFileContents(outputShadowJar, propertiesXml) + val text = outputShadowJar.getEntryContent(propertiesXml) assertThat(text.trimIndent()).isEqualTo( """ @@ -202,24 +196,21 @@ class TransformersTest : BaseTransformerTest() { run("jar", shadowJarTask) - val jar = path("build/libs/shadow-1.0.jar") - assertThat(jar).exists() + val outputJar = jarPath("build/libs/shadow-1.0.jar") + assertThat(outputJar).exists() assertThat(outputShadowJar).exists() - JarInputStream(outputShadowJar.inputStream()).use { jis -> - val mf = jis.manifest - assertThat(mf).isNotNull() - assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") - assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") - assertThat(mf.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") - } - JarInputStream(jar.inputStream()).use { jis -> - val mf = jis.manifest - assertThat(mf).isNotNull() - assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("FAILED") - assertThat(mf.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") - assertThat(mf.mainAttributes.getValue("New-Entry")).isNull() - } + val mf1 = outputShadowJar.manifest + assertThat(mf1).isNotNull() + assertThat(mf1.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") + assertThat(mf1.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") + assertThat(mf1.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") + + val mf2 = outputJar.manifest + assertThat(mf2).isNotNull() + assertThat(mf2.mainAttributes.getValue("Test-Entry")).isEqualTo("FAILED") + assertThat(mf2.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") + assertThat(mf2.mainAttributes.getValue("New-Entry")).isNull() } @Test @@ -256,7 +247,7 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val props = getJarFileContents(outputShadowJar, ENTRY_SERVICE_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) @@ -299,14 +290,14 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val props = getJarFileContents(outputShadowJar, ENTRY_GROOVY_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getEntryContent(ENTRY_GROOVY_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) .isEqualTo("com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension") assertThat(props.getProperty("staticExtensionClasses")) .isEqualTo("com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension") - assertDoesNotContain(outputShadowJar, listOf(ENTRY_SERVICE_EXTENSION_MODULE)) + outputShadowJar.assertDoesNotContain(listOf(ENTRY_SERVICE_EXTENSION_MODULE)) } @Test @@ -346,7 +337,7 @@ class TransformersTest : BaseTransformerTest() { assertThat(outputShadowJar).exists() - val props = getJarFileContents(outputShadowJar, ENTRY_SERVICE_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt new file mode 100644 index 000000000..b25609667 --- /dev/null +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -0,0 +1,52 @@ +package com.github.jengelman.gradle.plugins.shadow.util + +import assertk.Assert +import assertk.assertThat +import assertk.assertions.exists +import assertk.fail +import java.nio.file.Path +import java.util.jar.JarFile +import kotlin.io.path.deleteExisting + +/** + * A wrapper for [JarFile] that also implements [Path]. + * + * We must declare some extensions like [kotlin.io.path.deleteExisting] or [assertk.assertions.exists] + * as they could not be delegated to [JarPath] type. + */ +class JarPath(val path: Path) : + JarFile(path.toFile()), + Path by path { + + fun deleteExisting() { + path.deleteExisting() + } + + fun getEntryContent(entryName: String): String { + val entry = getJarEntry(entryName) ?: error("Entry not found: $entryName") + return getInputStream(entry).bufferedReader().readText() + } + + fun assertContains(entries: Iterable) { + entries.forEach { entry -> + assertThat(getEntry(entry)).given { actual -> + actual ?: fail("Jar file $path does not contain entry $entry") + } + } + } + + fun assertDoesNotContain(entries: Iterable) { + entries.forEach { entry -> + assertThat(getEntry(entry)).given { actual -> + if (actual == null) return + fail("Jar file $path contains entry $entry") + } + } + } + + companion object { + fun Assert.exists() { + transform { it.path }.exists() + } + } +} From 3faa56ce4a268d548be2d5215508702228bb2466 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 22:43:50 +0800 Subject: [PATCH 03/13] Move exists out of companion object --- .../jengelman/gradle/plugins/shadow/ApplicationTest.kt | 2 +- .../gradle/plugins/shadow/ConfigurationCacheSpec.kt | 2 +- .../jengelman/gradle/plugins/shadow/FilteringTest.kt | 2 +- .../jengelman/gradle/plugins/shadow/RelocationTest.kt | 2 +- .../jengelman/gradle/plugins/shadow/ShadowPluginTest.kt | 2 +- .../shadow/transformers/ServiceFileTransformerTest.kt | 2 +- .../plugins/shadow/transformers/TransformersTest.kt | 2 +- .../jengelman/gradle/plugins/shadow/util/JarPath.kt | 8 +++----- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index f889cba51..33f4b4f99 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -5,7 +5,7 @@ import assertk.assertions.contains import assertk.assertions.containsAtLeast import assertk.assertions.exists import assertk.assertions.isEqualTo -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt index aeebc5154..d35b9cb05 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt @@ -4,7 +4,7 @@ import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isEqualTo import assertk.assertions.isNotNull -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import org.gradle.testkit.runner.BuildResult diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt index 5ac93ecdd..ca1d1457b 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNotNull -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index 6908a7cb3..4a691173d 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -5,7 +5,7 @@ import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf import com.github.jengelman.gradle.plugins.shadow.util.Issue -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import java.net.URLClassLoader import kotlin.io.path.appendText import kotlin.io.path.writeText diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index dad8098fc..fdf163da4 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -9,7 +9,7 @@ import assertk.assertions.isTrue import com.github.jengelman.gradle.plugins.shadow.legacy.LegacyShadowPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.Issue -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.toPath diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index 63f554e40..bdd172400 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.util.Issue -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import org.junit.jupiter.api.Test diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 0c58e9b88..fa35ac2d7 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -5,7 +5,7 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue -import com.github.jengelman.gradle.plugins.shadow.util.JarPath.Companion.exists +import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import kotlin.reflect.KClass diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index b25609667..bd3126865 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -43,10 +43,8 @@ class JarPath(val path: Path) : } } } +} - companion object { - fun Assert.exists() { - transform { it.path }.exists() - } - } +fun Assert.exists() { + transform { it.path }.exists() } From 75824858450a2c895ae3d22a999ad9e7d427ed6b Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 22:56:05 +0800 Subject: [PATCH 04/13] assertContains and assertDoesNotContain -> containsEntries and doesNotContainEntries --- .../gradle/plugins/shadow/ApplicationTest.kt | 5 +- .../plugins/shadow/ConfigurationCacheSpec.kt | 10 ++-- .../gradle/plugins/shadow/FilteringTest.kt | 36 ++++++------ .../gradle/plugins/shadow/RelocationTest.kt | 25 ++++---- .../gradle/plugins/shadow/ShadowPluginTest.kt | 57 ++++++++++--------- .../shadow/transformers/TransformersTest.kt | 3 +- .../gradle/plugins/shadow/util/JarPath.kt | 27 ++++----- 7 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 33f4b4f99..7b87232cc 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -5,6 +5,7 @@ import assertk.assertions.contains import assertk.assertions.containsAtLeast import assertk.assertions.exists import assertk.assertions.isEqualTo +import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText @@ -41,9 +42,7 @@ class ApplicationTest : BasePluginTest() { val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar") assertThat(installedJar).exists() - - installedJar.assertContains(listOf("a.properties", "a2.properties", "myapp/Main.class")) - + assertThat(installedJar).containsEntries(listOf("a.properties", "a2.properties", "myapp/Main.class")) assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class")) .isEqualTo("myapp.Main") diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt index d35b9cb05..ad56fd599 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt @@ -4,6 +4,8 @@ import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isEqualTo import assertk.assertions.isNotNull +import com.github.jengelman.gradle.plugins.shadow.util.containsEntries +import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText @@ -75,10 +77,10 @@ class ConfigurationCacheSpec : BasePluginTest() { outputShadowJar.deleteExisting() val result = run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "b.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("a2.properties"), ) result.assertCcReused() @@ -99,10 +101,10 @@ class ConfigurationCacheSpec : BasePluginTest() { val result = run(shadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("server/Server.class", "junit/framework/Test.class"), ) - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("client/Client.class"), ) result.assertCcReused() diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt index ca1d1457b..073e983f0 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt @@ -3,6 +3,8 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isNotNull +import com.github.jengelman.gradle.plugins.shadow.util.containsEntries +import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText @@ -32,7 +34,7 @@ class FilteringTest : BasePluginTest() { @Test fun includeAllDependencies() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "a2.properties", "b.properties"), ) } @@ -49,10 +51,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "b.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("a2.properties"), ) } @@ -104,10 +106,10 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "a2.properties", "b.properties", "d.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("c.properties"), ) } @@ -129,10 +131,10 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a2.properties", "b.properties", "c.properties", "d.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("a.properties"), ) } @@ -161,10 +163,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("d.properties", "shadow/Passed.class"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("a.properties", "a2.properties", "b.properties", "c.properties"), ) } @@ -182,10 +184,10 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("client/Client.class"), ) - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("server/Server.class", "junit/framework/Test.class"), ) } @@ -203,10 +205,10 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("junit/framework/Test.class"), ) - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class"), ) } @@ -225,10 +227,10 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "b.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("a2.properties"), ) } @@ -259,10 +261,10 @@ class FilteringTest : BasePluginTest() { } private fun commonAssertions() { - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "a2.properties", "b.properties", "c.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("d.properties"), ) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index 4a691173d..11780d7f7 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -5,6 +5,8 @@ import assertk.assertThat import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf import com.github.jengelman.gradle.plugins.shadow.util.Issue +import com.github.jengelman.gradle.plugins.shadow.util.containsEntries +import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import java.net.URLClassLoader import kotlin.io.path.appendText @@ -27,7 +29,7 @@ class RelocationTest : BasePluginTest() { ) run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "META-INF/MANIFEST.MF", "shadow/junit/textui/ResultPrinter.class", @@ -71,7 +73,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "META-INF/MANIFEST.MF", "a/ResultPrinter.class", @@ -92,7 +94,7 @@ class RelocationTest : BasePluginTest() { ), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf( "junit/textui/ResultPrinter.class", "junit/textui/TestRunner.class", @@ -135,7 +137,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "a/ResultPrinter.class", "b/Test.class", @@ -149,7 +151,7 @@ class RelocationTest : BasePluginTest() { ), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf( "a/TestRunner.class", "b/Assert.class", @@ -160,7 +162,7 @@ class RelocationTest : BasePluginTest() { ), ) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "junit/textui/TestRunner.class", "junit/framework/Assert.class", @@ -205,7 +207,7 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "shadow/ShadowTest.class", "shadow/junit/Test.class", @@ -213,7 +215,7 @@ class RelocationTest : BasePluginTest() { ), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf( "junit/framework", "junit/framework/Test.class", @@ -291,8 +293,7 @@ class RelocationTest : BasePluginTest() { val appOutput = jarPath("app/build/libs/app-all.jar") assertThat(appOutput).exists() - - appOutput.assertContains( + assertThat(appOutput).containsEntries( listOf( "TEST", "APP-TEST", @@ -335,14 +336,14 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf( "bar/Foo.class", "bar/foo.properties", "bar/dep.properties", ), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf( "foo/Foo.class", "foo/foo.properties", diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index fdf163da4..c3dc7b366 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -9,6 +9,8 @@ import assertk.assertions.isTrue import com.github.jengelman.gradle.plugins.shadow.legacy.LegacyShadowPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.Issue +import com.github.jengelman.gradle.plugins.shadow.util.containsEntries +import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText @@ -125,10 +127,10 @@ class ShadowPluginTest : BasePluginTest() { val outputShadowJar = jarPath("build/libs/shadow.jar") assertThat(outputShadowJar).exists() - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("shadow/Passed.class", "junit/framework/Test.class"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("/"), ) } @@ -140,7 +142,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class", "junit/framework/Test.class"), ) } @@ -170,10 +172,10 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class"), ) - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("junit/framework/Test.class"), ) } @@ -196,10 +198,10 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("server/Server.class", "junit/framework/Test.class"), ) - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("client/Client.class"), ) } @@ -221,7 +223,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class"), ) } @@ -252,7 +254,7 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), ) @@ -266,7 +268,7 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputServerShadowJar).exists() // TODO: I don't think junit classes should be in the output jar, but it's the test case // from https://github.com/GradleUp/shadow/pull/420, need to investigate more... - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), ) } @@ -284,10 +286,10 @@ class ShadowPluginTest : BasePluginTest() { val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() - implOutput.assertContains( + assertThat(implOutput).containsEntries( listOf("impl/SimpleEntity.class", "api/Entity.class", "api/UnusedEntity.class", "lib/LibEntity.class"), ) - implOutput.assertDoesNotContain( + assertThat(implOutput).doesNotContainEntries( listOf("junit/framework/Test.class", "lib/UnusedLibEntity.class"), ) } @@ -314,7 +316,7 @@ class ShadowPluginTest : BasePluginTest() { val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() - implOutput.assertContains( + assertThat(implOutput).containsEntries( listOf( "impl/SimpleEntity.class", "api/Entity.class", @@ -323,7 +325,7 @@ class ShadowPluginTest : BasePluginTest() { "lib/UnusedLibEntity.class", ), ) - implOutput.assertDoesNotContain( + assertThat(implOutput).doesNotContainEntries( listOf("junit/framework/Test.class"), ) } @@ -337,14 +339,15 @@ class ShadowPluginTest : BasePluginTest() { val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(serverOutput).exists() - serverOutput.assertContains( + assertThat(serverOutput).containsEntries( listOf("server/Server.class"), ) - serverOutput.assertDoesNotContain( + assertThat(serverOutput).doesNotContainEntries( listOf("client/Client.class", "junit/framework/Test.class", "client/junit/framework/Test.class"), ) + assertThat(clientOutput).exists() - clientOutput.assertContains( + assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), ) } @@ -357,14 +360,14 @@ class ShadowPluginTest : BasePluginTest() { val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(outputServerShadowJar).exists() - outputServerShadowJar.assertContains( + assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class", "server/Server.class"), ) - outputServerShadowJar.assertDoesNotContain( + assertThat(outputServerShadowJar).doesNotContainEntries( listOf("junit/framework/Test.class"), ) assertThat(clientOutput).exists() - clientOutput.assertContains( + assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), ) } @@ -397,10 +400,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("shadow/Passed.class", "a.properties", "META-INF/a.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("META-INF/INDEX.LIST", "META-INF/a.SF", "META-INF/a.DSA", "META-INF/a.RSA", "module-info.class"), ) } @@ -421,10 +424,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "a2.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("b.properties"), ) } @@ -458,7 +461,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("api.properties", "implementation.properties", "runtimeOnly.properties", "implementation-dep.properties"), ) } @@ -479,10 +482,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - outputShadowJar.assertContains( + assertThat(outputShadowJar).containsEntries( listOf("a.properties", "a2.properties"), ) - outputShadowJar.assertDoesNotContain( + assertThat(outputShadowJar).doesNotContainEntries( listOf("b.properties"), ) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index fa35ac2d7..e948acdc8 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -5,6 +5,7 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue +import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText @@ -297,7 +298,7 @@ class TransformersTest : BaseTransformerTest() { .isEqualTo("com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension") assertThat(props.getProperty("staticExtensionClasses")) .isEqualTo("com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension") - outputShadowJar.assertDoesNotContain(listOf(ENTRY_SERVICE_EXTENSION_MODULE)) + assertThat(outputShadowJar).doesNotContainEntries(listOf(ENTRY_SERVICE_EXTENSION_MODULE)) } @Test diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index bd3126865..3b6de6f53 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -1,7 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow.util import assertk.Assert -import assertk.assertThat import assertk.assertions.exists import assertk.fail import java.nio.file.Path @@ -26,25 +25,19 @@ class JarPath(val path: Path) : val entry = getJarEntry(entryName) ?: error("Entry not found: $entryName") return getInputStream(entry).bufferedReader().readText() } +} - fun assertContains(entries: Iterable) { - entries.forEach { entry -> - assertThat(getEntry(entry)).given { actual -> - actual ?: fail("Jar file $path does not contain entry $entry") - } - } - } +fun Assert.exists() = transform { it.path }.exists() - fun assertDoesNotContain(entries: Iterable) { - entries.forEach { entry -> - assertThat(getEntry(entry)).given { actual -> - if (actual == null) return - fail("Jar file $path contains entry $entry") - } - } +fun Assert.containsEntries(entries: Iterable) = transform { + entries.forEach { entry -> + it.getEntry(entry) ?: fail("Jar file ${it.path} does not contain entry $entry") } } -fun Assert.exists() { - transform { it.path }.exists() +fun Assert.doesNotContainEntries(entries: Iterable) = transform { + entries.forEach { entry -> + it.getEntry(entry) ?: return@forEach + fail("Jar file ${it.path} contains entry $entry") + } } From d71a92427b7852d462374634cf73436c0816fe75 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 23:16:52 +0800 Subject: [PATCH 05/13] Close jar file first before deleting --- .../com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 3b6de6f53..35a805d74 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -18,6 +18,7 @@ class JarPath(val path: Path) : Path by path { fun deleteExisting() { + close() path.deleteExisting() } From 2d11942065d4ce53e0336e83d93adb496dc5dce8 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sat, 4 Jan 2025 23:23:50 +0800 Subject: [PATCH 06/13] Cleanups --- .../gradle/plugins/shadow/ApplicationTest.kt | 4 +++- .../gradle/plugins/shadow/RelocationTest.kt | 4 ++-- .../gradle/plugins/shadow/ShadowPluginTest.kt | 16 ++++++++-------- .../shadow/transformers/TransformersTest.kt | 6 ++---- .../gradle/plugins/shadow/util/JarPath.kt | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 7b87232cc..5d3994418 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -42,7 +42,9 @@ class ApplicationTest : BasePluginTest() { val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar") assertThat(installedJar).exists() - assertThat(installedJar).containsEntries(listOf("a.properties", "a2.properties", "myapp/Main.class")) + assertThat(installedJar).containsEntries( + listOf("a.properties", "a2.properties", "myapp/Main.class"), + ) assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class")) .isEqualTo("myapp.Main") diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index 11780d7f7..ea25276b9 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -113,8 +113,8 @@ class RelocationTest : BasePluginTest() { "junit/framework/TestSuite.class", ), ) - - assertThat(outputShadowJar.manifest.mainAttributes.getValue("TEST-VALUE")).isEqualTo("FOO") + assertThat(outputShadowJar.manifest.mainAttributes.getValue("TEST-VALUE")) + .isEqualTo("FOO") } @Test diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index c3dc7b366..320ebfded 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -124,8 +124,8 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) - val outputShadowJar = jarPath("build/libs/shadow.jar") + val outputShadowJar = jarPath("build/libs/shadow.jar") assertThat(outputShadowJar).exists() assertThat(outputShadowJar).containsEntries( listOf("shadow/Passed.class", "junit/framework/Test.class"), @@ -283,8 +283,8 @@ class ShadowPluginTest : BasePluginTest() { writeApiLibAndImplModules() run(":impl:$shadowJarTask") - val implOutput = jarPath("impl/build/libs/impl-all.jar") + val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() assertThat(implOutput).containsEntries( listOf("impl/SimpleEntity.class", "api/Entity.class", "api/UnusedEntity.class", "lib/LibEntity.class"), @@ -313,8 +313,8 @@ class ShadowPluginTest : BasePluginTest() { ) run(":impl:$shadowJarTask") - val implOutput = jarPath("impl/build/libs/impl-all.jar") + val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).exists() assertThat(implOutput).containsEntries( listOf( @@ -335,9 +335,8 @@ class ShadowPluginTest : BasePluginTest() { writeShadowedClientAndServerModules() run(":server:jar") - val serverOutput = jarPath("server/build/libs/server-1.0.jar") - val clientOutput = jarPath("client/build/libs/client-all.jar") + val serverOutput = jarPath("server/build/libs/server-1.0.jar") assertThat(serverOutput).exists() assertThat(serverOutput).containsEntries( listOf("server/Server.class"), @@ -346,6 +345,7 @@ class ShadowPluginTest : BasePluginTest() { listOf("client/Client.class", "junit/framework/Test.class", "client/junit/framework/Test.class"), ) + val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(clientOutput).exists() assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), @@ -357,7 +357,6 @@ class ShadowPluginTest : BasePluginTest() { writeShadowedClientAndServerModules() run(serverShadowJarTask) - val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( @@ -366,6 +365,8 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputServerShadowJar).doesNotContainEntries( listOf("junit/framework/Test.class"), ) + + val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(clientOutput).exists() assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), @@ -757,11 +758,10 @@ class ShadowPluginTest : BasePluginTest() { ) val result = run(testShadowJarTask) - val testJar = jarPath("build/libs/shadow-1.0-tests.jar") assertThat(result.task(":$testShadowJarTask")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) - + val testJar = jarPath("build/libs/shadow-1.0-tests.jar") assertThat(testJar).exists() assertThat(testJar.getEntry("junit")).isNotNull() } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index e948acdc8..12df45ec6 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -114,7 +114,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) assertThat(outputShadowJar).exists() - val mf = outputShadowJar.manifest assertThat(mf).isNotNull() assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") @@ -197,16 +196,15 @@ class TransformersTest : BaseTransformerTest() { run("jar", shadowJarTask) - val outputJar = jarPath("build/libs/shadow-1.0.jar") - assertThat(outputJar).exists() assertThat(outputShadowJar).exists() - val mf1 = outputShadowJar.manifest assertThat(mf1).isNotNull() assertThat(mf1.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") assertThat(mf1.mainAttributes.getValue("Main-Class")).isEqualTo("shadow.Main") assertThat(mf1.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") + val outputJar = jarPath("build/libs/shadow-1.0.jar") + assertThat(outputJar).exists() val mf2 = outputJar.manifest assertThat(mf2).isNotNull() assertThat(mf2.mainAttributes.getValue("Test-Entry")).isEqualTo("FAILED") diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 35a805d74..e8895e99c 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -10,8 +10,8 @@ import kotlin.io.path.deleteExisting /** * A wrapper for [JarFile] that also implements [Path]. * - * We must declare some extensions like [kotlin.io.path.deleteExisting] or [assertk.assertions.exists] - * as they could not be delegated to [JarPath] type. + * We must declare some functions like [kotlin.io.path.deleteExisting] explicitly as they could not + * be delegated to [JarPath] type. */ class JarPath(val path: Path) : JarFile(path.toFile()), From d1238129dc6f58229ca9d78e15d0b282b6e35abb Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 10:50:30 +0800 Subject: [PATCH 07/13] Don't check extensions in path --- .../jengelman/gradle/plugins/shadow/BasePluginTest.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index 897fe010f..49cc07903 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -17,7 +17,6 @@ import kotlin.io.path.createFile import kotlin.io.path.createTempDirectory import kotlin.io.path.deleteRecursively import kotlin.io.path.exists -import kotlin.io.path.extension import kotlin.io.path.readText import kotlin.io.path.toPath import kotlin.io.path.writeText @@ -129,15 +128,13 @@ abstract class BasePluginTest { val outputServerShadowJar: JarPath get() = jarPath("server/build/libs/server-1.0-all.jar") - fun jarPath(path: String): JarPath = JarPath(path(path)) + fun jarPath(path: String): JarPath = JarPath(root.resolve(path)) fun path(path: String): Path { return root.resolve(path).also { - val extension = it.extension - // Binary files should not be created, text files should be created. - if (it.exists() || extension == "jar" || extension == "zip") return@also - + if (it.exists()) return@also it.parent.createDirectories() + // We should create text file only if it doesn't exist. it.createFile() } } From 79c37e5f3fbbbdad054ce19dfa70893d8a01b3c1 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 11:12:59 +0800 Subject: [PATCH 08/13] Remove extra jar file existing assertions --- .../gradle/plugins/shadow/ApplicationTest.kt | 9 ++---- .../gradle/plugins/shadow/BasePluginTest.kt | 9 +++++- .../plugins/shadow/ConfigurationCacheSpec.kt | 2 -- .../gradle/plugins/shadow/FilteringTest.kt | 3 -- .../gradle/plugins/shadow/RelocationTest.kt | 2 -- .../gradle/plugins/shadow/ShadowPluginTest.kt | 29 ++----------------- .../ServiceFileTransformerTest.kt | 13 --------- .../shadow/transformers/TransformersTest.kt | 20 ------------- .../gradle/plugins/shadow/util/JarPath.kt | 3 -- 9 files changed, 12 insertions(+), 78 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 5d3994418..3b4b085f5 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -3,10 +3,9 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains import assertk.assertions.containsAtLeast -import assertk.assertions.exists import assertk.assertions.isEqualTo +import assertk.assertions.isNotEmpty import com.github.jengelman.gradle.plugins.shadow.util.containsEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText @@ -41,7 +40,6 @@ class ApplicationTest : BasePluginTest() { assertThat(result.output).contains("TestApp: Hello World! (foo)") val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar") - assertThat(installedJar).exists() assertThat(installedJar).containsEntries( listOf("a.properties", "a2.properties", "myapp/Main.class"), ) @@ -49,7 +47,6 @@ class ApplicationTest : BasePluginTest() { .isEqualTo("myapp.Main") path("build/install/myapp-shadow/bin/myapp").let { startScript -> - assertThat(startScript).exists() assertThat(startScript.readText()).contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar") assertThat(startScript.readText()).contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"") assertThat(startScript.readText()).contains("exec \"\$JAVACMD\" \"\$@\"") @@ -69,8 +66,6 @@ class ApplicationTest : BasePluginTest() { run("shadowDistZip") val zip = path("build/distributions/myapp-shadow-1.0.zip") - assertThat(zip).exists() - val entries = ZipFile(zip.toFile()).entries.toList().map { it.name } assertThat(entries).containsAtLeast( "myapp-shadow-1.0/lib/myapp-1.0-all.jar", @@ -84,7 +79,7 @@ class ApplicationTest : BasePluginTest() { run(ShadowApplicationPlugin.SHADOW_INSTALL_TASK_NAME) - assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).exists() + assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar").entries().toList()).isNotEmpty() } private fun prepare( diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index 49cc07903..2a1319432 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -17,6 +17,7 @@ import kotlin.io.path.createFile import kotlin.io.path.createTempDirectory import kotlin.io.path.deleteRecursively import kotlin.io.path.exists +import kotlin.io.path.isRegularFile import kotlin.io.path.readText import kotlin.io.path.toPath import kotlin.io.path.writeText @@ -128,7 +129,13 @@ abstract class BasePluginTest { val outputServerShadowJar: JarPath get() = jarPath("server/build/libs/server-1.0-all.jar") - fun jarPath(path: String): JarPath = JarPath(root.resolve(path)) + fun jarPath(path: String): JarPath { + val realPath = root.resolve(path).also { + check(it.exists()) { "Path not found: $it" } + check(it.isRegularFile()) { "Path is not a regular file: $it" } + } + return JarPath(realPath) + } fun path(path: String): Path { return root.resolve(path).also { diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt index ad56fd599..dab0b5253 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt @@ -6,7 +6,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import org.gradle.testkit.runner.BuildResult @@ -100,7 +99,6 @@ class ConfigurationCacheSpec : BasePluginTest() { outputServerShadowJar.deleteExisting() val result = run(shadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("server/Server.class", "junit/framework/Test.class"), ) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt index 073e983f0..5989fd902 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt @@ -5,7 +5,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isNotNull import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText @@ -183,7 +182,6 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).doesNotContainEntries( listOf("client/Client.class"), ) @@ -204,7 +202,6 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).doesNotContainEntries( listOf("junit/framework/Test.class"), ) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index ea25276b9..74e4bd993 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -7,7 +7,6 @@ import assertk.assertions.isInstanceOf import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import java.net.URLClassLoader import kotlin.io.path.appendText import kotlin.io.path.writeText @@ -292,7 +291,6 @@ class RelocationTest : BasePluginTest() { run(":app:$shadowJarTask") val appOutput = jarPath("app/build/libs/app-all.jar") - assertThat(appOutput).exists() assertThat(appOutput).containsEntries( listOf( "TEST", diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index 320ebfded..8c1d30228 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -11,7 +11,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.toPath @@ -70,8 +69,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) { it.withGradleVersion("8.3") } - - assertThat(outputShadowJar).exists() } @Test @@ -97,8 +94,6 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) - - assertThat(outputShadowJar).exists() } @Test @@ -126,7 +121,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) val outputShadowJar = jarPath("build/libs/shadow.jar") - assertThat(outputShadowJar).exists() + assertThat(outputShadowJar).containsEntries( listOf("shadow/Passed.class", "junit/framework/Test.class"), ) @@ -141,7 +136,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class", "junit/framework/Test.class"), ) @@ -171,7 +165,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class"), ) @@ -197,7 +190,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("server/Server.class", "junit/framework/Test.class"), ) @@ -222,7 +214,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class"), ) @@ -253,7 +244,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), ) @@ -265,7 +255,7 @@ class ShadowPluginTest : BasePluginTest() { """.trimIndent(), ) run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() + // TODO: I don't think junit classes should be in the output jar, but it's the test case // from https://github.com/GradleUp/shadow/pull/420, need to investigate more... assertThat(outputServerShadowJar).containsEntries( @@ -285,7 +275,6 @@ class ShadowPluginTest : BasePluginTest() { run(":impl:$shadowJarTask") val implOutput = jarPath("impl/build/libs/impl-all.jar") - assertThat(implOutput).exists() assertThat(implOutput).containsEntries( listOf("impl/SimpleEntity.class", "api/Entity.class", "api/UnusedEntity.class", "lib/LibEntity.class"), ) @@ -315,7 +304,6 @@ class ShadowPluginTest : BasePluginTest() { run(":impl:$shadowJarTask") val implOutput = jarPath("impl/build/libs/impl-all.jar") - assertThat(implOutput).exists() assertThat(implOutput).containsEntries( listOf( "impl/SimpleEntity.class", @@ -337,7 +325,6 @@ class ShadowPluginTest : BasePluginTest() { run(":server:jar") val serverOutput = jarPath("server/build/libs/server-1.0.jar") - assertThat(serverOutput).exists() assertThat(serverOutput).containsEntries( listOf("server/Server.class"), ) @@ -346,7 +333,6 @@ class ShadowPluginTest : BasePluginTest() { ) val clientOutput = jarPath("client/build/libs/client-all.jar") - assertThat(clientOutput).exists() assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), ) @@ -358,7 +344,6 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) - assertThat(outputServerShadowJar).exists() assertThat(outputServerShadowJar).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class", "server/Server.class"), ) @@ -367,7 +352,6 @@ class ShadowPluginTest : BasePluginTest() { ) val clientOutput = jarPath("client/build/libs/client-all.jar") - assertThat(clientOutput).exists() assertThat(clientOutput).containsEntries( listOf("client/Client.class", "client/junit/framework/Test.class"), ) @@ -511,7 +495,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() assertThat(outputShadowJar.entries().toList().size).isEqualTo(2) } @@ -527,7 +510,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() val attributes = outputShadowJar.manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isNull() } @@ -552,7 +534,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() val attributes = outputShadowJar.manifest.mainAttributes assertThat(attributes.getValue("Class-Path")).isEqualTo("/libs/a.jar junit-3.8.2.jar") } @@ -572,7 +553,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path")) .isEqualTo("junit-3.8.2.jar") } @@ -595,8 +575,6 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) - - assertThat(outputShadowJar).exists() } /** @@ -730,8 +708,6 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val entries = outputShadowJar.entries().toList() assertThat(entries.count { it.name.endsWith(".class") }).isEqualTo(1) } @@ -762,7 +738,6 @@ class ShadowPluginTest : BasePluginTest() { assertThat(result.task(":$testShadowJarTask")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) val testJar = jarPath("build/libs/shadow-1.0-tests.jar") - assertThat(testJar).exists() assertThat(testJar.getEntry("junit")).isNotNull() } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index bdd172400..84af77c42 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.util.Issue -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import org.junit.jupiter.api.Test @@ -23,8 +22,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) @@ -51,8 +48,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -72,8 +67,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) @@ -124,8 +117,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text1 = outputShadowJar.getEntryContent("META-INF/services/java.sql.Driver") assertThat(text1).isEqualTo( """ @@ -172,8 +163,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -207,8 +196,6 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(servicesShadowEntry) assertThat(text).isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 12df45ec6..857d0d0bf 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -6,7 +6,6 @@ import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries -import com.github.jengelman.gradle.plugins.shadow.util.exists import kotlin.io.path.appendText import kotlin.io.path.writeText import kotlin.reflect.KClass @@ -35,8 +34,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -60,8 +57,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -82,8 +77,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val mf = outputShadowJar.manifest assertThat(mf).isNotNull() assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") @@ -113,7 +106,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() val mf = outputShadowJar.manifest assertThat(mf).isNotNull() assertThat(mf.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") @@ -158,8 +150,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val text = outputShadowJar.getEntryContent(propertiesXml) assertThat(text.trimIndent()).isEqualTo( """ @@ -196,7 +186,6 @@ class TransformersTest : BaseTransformerTest() { run("jar", shadowJarTask) - assertThat(outputShadowJar).exists() val mf1 = outputShadowJar.manifest assertThat(mf1).isNotNull() assertThat(mf1.mainAttributes.getValue("Test-Entry")).isEqualTo("PASSED") @@ -204,7 +193,6 @@ class TransformersTest : BaseTransformerTest() { assertThat(mf1.mainAttributes.getValue("New-Entry")).isEqualTo("NEW") val outputJar = jarPath("build/libs/shadow-1.0.jar") - assertThat(outputJar).exists() val mf2 = outputJar.manifest assertThat(mf2).isNotNull() assertThat(mf2.mainAttributes.getValue("Test-Entry")).isEqualTo("FAILED") @@ -244,8 +232,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") @@ -287,8 +273,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val props = outputShadowJar.getEntryContent(ENTRY_GROOVY_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") @@ -334,8 +318,6 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar).exists() - val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") @@ -361,8 +343,6 @@ class TransformersTest : BaseTransformerTest() { ) run(shadowJarTask) - - assertThat(outputShadowJar).exists() } private companion object { diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index e8895e99c..482863405 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -1,7 +1,6 @@ package com.github.jengelman.gradle.plugins.shadow.util import assertk.Assert -import assertk.assertions.exists import assertk.fail import java.nio.file.Path import java.util.jar.JarFile @@ -28,8 +27,6 @@ class JarPath(val path: Path) : } } -fun Assert.exists() = transform { it.path }.exists() - fun Assert.containsEntries(entries: Iterable) = transform { entries.forEach { entry -> it.getEntry(entry) ?: fail("Jar file ${it.path} does not contain entry $entry") From 6692d2dbca44a6753b62927178e8e4ece84ee2aa Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 11:20:43 +0800 Subject: [PATCH 09/13] Replace getJarEntry --- .../com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 482863405..5c66f79ba 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -22,7 +22,7 @@ class JarPath(val path: Path) : } fun getEntryContent(entryName: String): String { - val entry = getJarEntry(entryName) ?: error("Entry not found: $entryName") + val entry = getEntry(entryName) ?: error("Entry not found: $entryName") return getInputStream(entry).bufferedReader().readText() } } From e1fbac27b5a31844bb8d068e3e8349566a294306 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 11:22:46 +0800 Subject: [PATCH 10/13] Rename getEntryContent --- .../ServiceFileTransformerTest.kt | 20 +++++++++---------- .../shadow/transformers/TransformersTest.kt | 12 +++++------ .../gradle/plugins/shadow/util/JarPath.kt | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index 84af77c42..c0549ff5d 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -22,10 +22,10 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) + val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - val text2 = outputShadowJar.getEntryContent(ENTRY_SERVICES_FOO) + val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO) assertThat(text2).isEqualTo("one") } @@ -48,7 +48,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) + val text = outputShadowJar.getContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -67,10 +67,10 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text1 = outputShadowJar.getEntryContent(ENTRY_SERVICES_SHADE) + val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE) assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - val text2 = outputShadowJar.getEntryContent(ENTRY_SERVICES_FOO) + val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO) assertThat(text2).isEqualTo("one") } @@ -117,7 +117,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text1 = outputShadowJar.getEntryContent("META-INF/services/java.sql.Driver") + val text1 = outputShadowJar.getContent("META-INF/services/java.sql.Driver") assertThat(text1).isEqualTo( """ oracle.jdbc.OracleDriver @@ -127,7 +127,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { """.trimIndent(), ) - val text2 = outputShadowJar.getEntryContent("META-INF/services/myapache.axis.components.compiler.Compiler") + val text2 = outputShadowJar.getContent("META-INF/services/myapache.axis.components.compiler.Compiler") assertThat(text2).isEqualTo( """ myapache.axis.components.compiler.Javac @@ -135,7 +135,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { """.trimIndent(), ) - val text3 = outputShadowJar.getEntryContent("META-INF/services/org.apache.commons.logging.LogFactory") + val text3 = outputShadowJar.getContent("META-INF/services/org.apache.commons.logging.LogFactory") assertThat(text3).isEqualTo( """ myapache.commons.logging.impl.LogFactoryImpl @@ -163,7 +163,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(ENTRY_FOO_SHADE) + val text = outputShadowJar.getContent(ENTRY_FOO_SHADE) assertThat(text).isEqualTo(CONTENT_ONE_TWO) } @@ -196,7 +196,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(servicesShadowEntry) + val text = outputShadowJar.getContent(servicesShadowEntry) assertThat(text).isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO) } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 857d0d0bf..f2e98215b 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -34,7 +34,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) + val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -57,7 +57,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(ENTRY_TEST_PROPERTIES) + val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES) assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) } @@ -150,7 +150,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getEntryContent(propertiesXml) + val text = outputShadowJar.getContent(propertiesXml) assertThat(text.trimIndent()).isEqualTo( """ @@ -232,7 +232,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) @@ -273,7 +273,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val props = outputShadowJar.getEntryContent(ENTRY_GROOVY_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getContent(ENTRY_GROOVY_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) @@ -318,7 +318,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val props = outputShadowJar.getEntryContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() + val props = outputShadowJar.getContent(ENTRY_SERVICE_EXTENSION_MODULE).toProperties() assertThat(props.getProperty("moduleName")).isEqualTo("MergedByShadowJar") assertThat(props.getProperty("moduleVersion")).isEqualTo("1.0.0") assertThat(props.getProperty("extensionClasses")) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 5c66f79ba..3d57561e3 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -21,7 +21,7 @@ class JarPath(val path: Path) : path.deleteExisting() } - fun getEntryContent(entryName: String): String { + fun getContent(entryName: String): String { val entry = getEntry(entryName) ?: error("Entry not found: $entryName") return getInputStream(entry).bufferedReader().readText() } From bb06c078110f1ce496f114f030e4b5ee5d02938d Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 11:30:42 +0800 Subject: [PATCH 11/13] Cleanups --- .../gradle/plugins/shadow/ApplicationTest.kt | 4 ++++ .../gradle/plugins/shadow/ShadowPluginTest.kt | 14 +++++++---- .../ServiceFileTransformerTest.kt | 24 +++++++------------ .../shadow/transformers/TransformersTest.kt | 14 ++++++----- .../gradle/plugins/shadow/util/JarPath.kt | 10 ++++---- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 3b4b085f5..54a8c824c 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains import assertk.assertions.containsAtLeast +import assertk.assertions.exists import assertk.assertions.isEqualTo import assertk.assertions.isNotEmpty import com.github.jengelman.gradle.plugins.shadow.util.containsEntries @@ -47,6 +48,7 @@ class ApplicationTest : BasePluginTest() { .isEqualTo("myapp.Main") path("build/install/myapp-shadow/bin/myapp").let { startScript -> + assertThat(startScript).exists() assertThat(startScript.readText()).contains("CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar") assertThat(startScript.readText()).contains("-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"") assertThat(startScript.readText()).contains("exec \"\$JAVACMD\" \"\$@\"") @@ -66,6 +68,8 @@ class ApplicationTest : BasePluginTest() { run("shadowDistZip") val zip = path("build/distributions/myapp-shadow-1.0.zip") + assertThat(zip).exists() + val entries = ZipFile(zip.toFile()).entries.toList().map { it.name } assertThat(entries).containsAtLeast( "myapp-shadow-1.0/lib/myapp-1.0-all.jar", diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index 8c1d30228..716c867c0 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -3,6 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isEqualTo +import assertk.assertions.isNotEmpty import assertk.assertions.isNotNull import assertk.assertions.isNull import assertk.assertions.isTrue @@ -69,6 +70,8 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) { it.withGradleVersion("8.3") } + + assertThat(outputShadowJar.entries().toList()).isNotEmpty() } @Test @@ -94,6 +97,8 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) + + assertThat(outputShadowJar.entries().toList()).isNotEmpty() } @Test @@ -510,8 +515,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - val attributes = outputShadowJar.manifest.mainAttributes - assertThat(attributes.getValue("Class-Path")).isNull() + assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path")).isNull() } @Issue( @@ -534,8 +538,8 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - val attributes = outputShadowJar.manifest.mainAttributes - assertThat(attributes.getValue("Class-Path")).isEqualTo("/libs/a.jar junit-3.8.2.jar") + assertThat(outputShadowJar.manifest.mainAttributes.getValue("Class-Path")) + .isEqualTo("/libs/a.jar junit-3.8.2.jar") } @Issue( @@ -575,6 +579,8 @@ class ShadowPluginTest : BasePluginTest() { ) run(shadowJarTask) + + assertThat(outputShadowJar.entries().toList()).isNotEmpty() } /** diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt index c0549ff5d..aae881fba 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformerTest.kt @@ -22,11 +22,8 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE) - assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - - val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO) - assertThat(text2).isEqualTo("one") + assertThat(outputShadowJar.getContent(ENTRY_SERVICES_SHADE)).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_SERVICES_FOO)).isEqualTo("one") } @Test @@ -48,8 +45,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(ENTRY_FOO_SHADE) - assertThat(text).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_FOO_SHADE)).isEqualTo(CONTENT_ONE_TWO) } @Test @@ -67,11 +63,8 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text1 = outputShadowJar.getContent(ENTRY_SERVICES_SHADE) - assertThat(text1).isEqualTo(CONTENT_ONE_TWO) - - val text2 = outputShadowJar.getContent(ENTRY_SERVICES_FOO) - assertThat(text2).isEqualTo("one") + assertThat(outputShadowJar.getContent(ENTRY_SERVICES_SHADE)).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_SERVICES_FOO)).isEqualTo("one") } @Test @@ -163,8 +156,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(ENTRY_FOO_SHADE) - assertThat(text).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_FOO_SHADE)).isEqualTo(CONTENT_ONE_TWO) } @Issue( @@ -196,7 +188,7 @@ class ServiceFileTransformerTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(servicesShadowEntry) - assertThat(text).isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(servicesShadowEntry)) + .isEqualTo(CONTENT_THREE + "\n" + CONTENT_ONE_TWO) } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index f2e98215b..7cf18b674 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo +import assertk.assertions.isNotEmpty import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue @@ -34,8 +35,8 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES) - assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_TEST_PROPERTIES).trimIndent()) + .isEqualTo(CONTENT_ONE_TWO) } @Test @@ -57,8 +58,8 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(ENTRY_TEST_PROPERTIES) - assertThat(text.trimIndent()).isEqualTo(CONTENT_ONE_TWO) + assertThat(outputShadowJar.getContent(ENTRY_TEST_PROPERTIES).trimIndent()) + .isEqualTo(CONTENT_ONE_TWO) } @Test @@ -150,8 +151,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - val text = outputShadowJar.getContent(propertiesXml) - assertThat(text.trimIndent()).isEqualTo( + assertThat(outputShadowJar.getContent(propertiesXml).trimIndent()).isEqualTo( """ @@ -343,6 +343,8 @@ class TransformersTest : BaseTransformerTest() { ) run(shadowJarTask) + + assertThat(outputShadowJar.entries().toList()).isNotEmpty() } private companion object { diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 3d57561e3..9443abb66 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -27,15 +27,15 @@ class JarPath(val path: Path) : } } -fun Assert.containsEntries(entries: Iterable) = transform { +fun Assert.containsEntries(entries: Iterable) = transform { actual -> entries.forEach { entry -> - it.getEntry(entry) ?: fail("Jar file ${it.path} does not contain entry $entry") + actual.getEntry(entry) ?: fail("Jar file ${actual.path} does not contain entry $entry") } } -fun Assert.doesNotContainEntries(entries: Iterable) = transform { +fun Assert.doesNotContainEntries(entries: Iterable) = transform { actual -> entries.forEach { entry -> - it.getEntry(entry) ?: return@forEach - fail("Jar file ${it.path} contains entry $entry") + actual.getEntry(entry) ?: return@forEach + fail("Jar file ${actual.path} contains entry $entry") } } From 1086f4dee8ad2f904095ab62ecd5e80d38467985 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 12:07:22 +0800 Subject: [PATCH 12/13] Add isRegular assertion --- .../jengelman/gradle/plugins/shadow/ShadowPluginTest.kt | 8 ++++---- .../plugins/shadow/transformers/TransformersTest.kt | 4 ++-- .../jengelman/gradle/plugins/shadow/util/JarPath.kt | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index 716c867c0..6a044c4cf 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.assertThat import assertk.assertions.contains import assertk.assertions.isEqualTo -import assertk.assertions.isNotEmpty import assertk.assertions.isNotNull import assertk.assertions.isNull import assertk.assertions.isTrue @@ -12,6 +11,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries +import com.github.jengelman.gradle.plugins.shadow.util.isRegular import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.toPath @@ -71,7 +71,7 @@ class ShadowPluginTest : BasePluginTest() { it.withGradleVersion("8.3") } - assertThat(outputShadowJar.entries().toList()).isNotEmpty() + assertThat(outputShadowJar).isRegular() } @Test @@ -98,7 +98,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar.entries().toList()).isNotEmpty() + assertThat(outputShadowJar).isRegular() } @Test @@ -580,7 +580,7 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) - assertThat(outputShadowJar.entries().toList()).isNotEmpty() + assertThat(outputShadowJar).isRegular() } /** diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 7cf18b674..5d7fa8fd9 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -2,11 +2,11 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo -import assertk.assertions.isNotEmpty import assertk.assertions.isNotNull import assertk.assertions.isNull import com.github.jengelman.gradle.plugins.shadow.util.Issue import com.github.jengelman.gradle.plugins.shadow.util.doesNotContainEntries +import com.github.jengelman.gradle.plugins.shadow.util.isRegular import kotlin.io.path.appendText import kotlin.io.path.writeText import kotlin.reflect.KClass @@ -344,7 +344,7 @@ class TransformersTest : BaseTransformerTest() { run(shadowJarTask) - assertThat(outputShadowJar.entries().toList()).isNotEmpty() + assertThat(outputShadowJar).isRegular() } private companion object { diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 9443abb66..b7d2186bc 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -1,6 +1,7 @@ package com.github.jengelman.gradle.plugins.shadow.util import assertk.Assert +import assertk.assertions.isNotEmpty import assertk.fail import java.nio.file.Path import java.util.jar.JarFile @@ -27,6 +28,11 @@ class JarPath(val path: Path) : } } +/** + * Common regular assertions for [JarPath]. + */ +fun Assert.isRegular() = transform { it.entries().toList() }.isNotEmpty() + fun Assert.containsEntries(entries: Iterable) = transform { actual -> entries.forEach { entry -> actual.getEntry(entry) ?: fail("Jar file ${actual.path} does not contain entry $entry") From b808fafab1e1ebc4e46a1970ea5189a378c47680 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 5 Jan 2025 12:24:43 +0800 Subject: [PATCH 13/13] Use vararg for containsEntries and doesNotContainEntries --- .../gradle/plugins/shadow/ApplicationTest.kt | 4 +- .../plugins/shadow/ConfigurationCacheSpec.kt | 10 +- .../gradle/plugins/shadow/FilteringTest.kt | 53 +++-- .../gradle/plugins/shadow/RelocationTest.kt | 192 ++++++++---------- .../gradle/plugins/shadow/ShadowPluginTest.kt | 95 ++++++--- .../shadow/transformers/TransformersTest.kt | 4 +- .../gradle/plugins/shadow/util/JarPath.kt | 4 +- 7 files changed, 197 insertions(+), 165 deletions(-) diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 54a8c824c..fe67d30ea 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -42,7 +42,9 @@ class ApplicationTest : BasePluginTest() { val installedJar = jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar") assertThat(installedJar).containsEntries( - listOf("a.properties", "a2.properties", "myapp/Main.class"), + "a.properties", + "a2.properties", + "myapp/Main.class", ) assertThat(installedJar.manifest.mainAttributes.getValue("Main-Class")) .isEqualTo("myapp.Main") diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt index dab0b5253..79ed273a2 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ConfigurationCacheSpec.kt @@ -77,10 +77,11 @@ class ConfigurationCacheSpec : BasePluginTest() { val result = run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "b.properties"), + "a.properties", + "b.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("a2.properties"), + "a2.properties", ) result.assertCcReused() } @@ -100,10 +101,11 @@ class ConfigurationCacheSpec : BasePluginTest() { val result = run(shadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("server/Server.class", "junit/framework/Test.class"), + "server/Server.class", + "junit/framework/Test.class", ) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("client/Client.class"), + "client/Client.class", ) result.assertCcReused() } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt index 5989fd902..add31e8e6 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/FilteringTest.kt @@ -34,7 +34,9 @@ class FilteringTest : BasePluginTest() { fun includeAllDependencies() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "a2.properties", "b.properties"), + "a.properties", + "a2.properties", + "b.properties", ) } @@ -51,10 +53,11 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "b.properties"), + "a.properties", + "b.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("a2.properties"), + "a2.properties", ) } @@ -106,10 +109,13 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "a2.properties", "b.properties", "d.properties"), + "a.properties", + "a2.properties", + "b.properties", + "d.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("c.properties"), + "c.properties", ) } @@ -131,10 +137,13 @@ class FilteringTest : BasePluginTest() { assertThat(result.task(":shadowJar")).isNotNull() .transform { it.outcome }.isEqualTo(TaskOutcome.SUCCESS) assertThat(outputShadowJar).containsEntries( - listOf("a2.properties", "b.properties", "c.properties", "d.properties"), + "a2.properties", + "b.properties", + "c.properties", + "d.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("a.properties"), + "a.properties", ) } @@ -163,10 +172,14 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("d.properties", "shadow/Passed.class"), + "d.properties", + "shadow/Passed.class", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("a.properties", "a2.properties", "b.properties", "c.properties"), + "a.properties", + "a2.properties", + "b.properties", + "c.properties", ) } @@ -183,10 +196,11 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("client/Client.class"), + "client/Client.class", ) assertThat(outputServerShadowJar).containsEntries( - listOf("server/Server.class", "junit/framework/Test.class"), + "server/Server.class", + "junit/framework/Test.class", ) } @@ -203,10 +217,11 @@ class FilteringTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("junit/framework/Test.class"), + "junit/framework/Test.class", ) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class"), + "client/Client.class", + "server/Server.class", ) } @@ -225,10 +240,11 @@ class FilteringTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "b.properties"), + "a.properties", + "b.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("a2.properties"), + "a2.properties", ) } @@ -259,10 +275,13 @@ class FilteringTest : BasePluginTest() { private fun commonAssertions() { assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "a2.properties", "b.properties", "c.properties"), + "a.properties", + "a2.properties", + "b.properties", + "c.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("d.properties"), + "d.properties", ) } } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt index 74e4bd993..6f4b18387 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/RelocationTest.kt @@ -29,24 +29,22 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf( - "META-INF/MANIFEST.MF", - "shadow/junit/textui/ResultPrinter.class", - "shadow/junit/textui/TestRunner.class", - "shadow/junit/framework/Assert.class", - "shadow/junit/framework/AssertionFailedError.class", - "shadow/junit/framework/ComparisonCompactor.class", - "shadow/junit/framework/ComparisonFailure.class", - "shadow/junit/framework/Protectable.class", - "shadow/junit/framework/Test.class", - "shadow/junit/framework/TestCase.class", - "shadow/junit/framework/TestFailure.class", - "shadow/junit/framework/TestListener.class", - "shadow/junit/framework/TestResult$1.class", - "shadow/junit/framework/TestResult.class", - "shadow/junit/framework/TestSuite$1.class", - "shadow/junit/framework/TestSuite.class", - ), + "META-INF/MANIFEST.MF", + "shadow/junit/textui/ResultPrinter.class", + "shadow/junit/textui/TestRunner.class", + "shadow/junit/framework/Assert.class", + "shadow/junit/framework/AssertionFailedError.class", + "shadow/junit/framework/ComparisonCompactor.class", + "shadow/junit/framework/ComparisonFailure.class", + "shadow/junit/framework/Protectable.class", + "shadow/junit/framework/Test.class", + "shadow/junit/framework/TestCase.class", + "shadow/junit/framework/TestFailure.class", + "shadow/junit/framework/TestListener.class", + "shadow/junit/framework/TestResult$1.class", + "shadow/junit/framework/TestResult.class", + "shadow/junit/framework/TestSuite$1.class", + "shadow/junit/framework/TestSuite.class", ) } @@ -73,44 +71,40 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf( - "META-INF/MANIFEST.MF", - "a/ResultPrinter.class", - "a/TestRunner.class", - "b/Assert.class", - "b/AssertionFailedError.class", - "b/ComparisonCompactor.class", - "b/ComparisonFailure.class", - "b/Protectable.class", - "b/Test.class", - "b/TestCase.class", - "b/TestFailure.class", - "b/TestListener.class", - "b/TestResult\$1.class", - "b/TestResult.class", - "b/TestSuite\$1.class", - "b/TestSuite.class", - ), + "META-INF/MANIFEST.MF", + "a/ResultPrinter.class", + "a/TestRunner.class", + "b/Assert.class", + "b/AssertionFailedError.class", + "b/ComparisonCompactor.class", + "b/ComparisonFailure.class", + "b/Protectable.class", + "b/Test.class", + "b/TestCase.class", + "b/TestFailure.class", + "b/TestListener.class", + "b/TestResult\$1.class", + "b/TestResult.class", + "b/TestSuite\$1.class", + "b/TestSuite.class", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf( - "junit/textui/ResultPrinter.class", - "junit/textui/TestRunner.class", - "junit/framework/Assert.class", - "junit/framework/AssertionFailedError.class", - "junit/framework/ComparisonCompactor.class", - "junit/framework/ComparisonFailure.class", - "junit/framework/Protectable.class", - "junit/framework/Test.class", - "junit/framework/TestCase.class", - "junit/framework/TestFailure.class", - "junit/framework/TestListener.class", - "junit/framework/TestResult\$1.class", - "junit/framework/TestResult.class", - "junit/framework/TestSuite\$1.class", - "junit/framework/TestSuite.class", - ), + "junit/textui/ResultPrinter.class", + "junit/textui/TestRunner.class", + "junit/framework/Assert.class", + "junit/framework/AssertionFailedError.class", + "junit/framework/ComparisonCompactor.class", + "junit/framework/ComparisonFailure.class", + "junit/framework/Protectable.class", + "junit/framework/Test.class", + "junit/framework/TestCase.class", + "junit/framework/TestFailure.class", + "junit/framework/TestListener.class", + "junit/framework/TestResult\$1.class", + "junit/framework/TestResult.class", + "junit/framework/TestSuite\$1.class", + "junit/framework/TestSuite.class", ) assertThat(outputShadowJar.manifest.mainAttributes.getValue("TEST-VALUE")) .isEqualTo("FOO") @@ -137,39 +131,33 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf( - "a/ResultPrinter.class", - "b/Test.class", - "b/TestCase.class", - "b/TestFailure.class", - "b/TestListener.class", - "b/TestResult\$1.class", - "b/TestResult.class", - "b/TestSuite\$1.class", - "b/TestSuite.class", - ), + "a/ResultPrinter.class", + "b/Test.class", + "b/TestCase.class", + "b/TestFailure.class", + "b/TestListener.class", + "b/TestResult\$1.class", + "b/TestResult.class", + "b/TestSuite\$1.class", + "b/TestSuite.class", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf( - "a/TestRunner.class", - "b/Assert.class", - "b/AssertionFailedError.class", - "b/ComparisonCompactor.class", - "b/ComparisonFailure.class", - "b/Protectable.class", - ), + "a/TestRunner.class", + "b/Assert.class", + "b/AssertionFailedError.class", + "b/ComparisonCompactor.class", + "b/ComparisonFailure.class", + "b/Protectable.class", ) assertThat(outputShadowJar).containsEntries( - listOf( - "junit/textui/TestRunner.class", - "junit/framework/Assert.class", - "junit/framework/AssertionFailedError.class", - "junit/framework/ComparisonCompactor.class", - "junit/framework/ComparisonFailure.class", - "junit/framework/Protectable.class", - ), + "junit/textui/TestRunner.class", + "junit/framework/Assert.class", + "junit/framework/AssertionFailedError.class", + "junit/framework/ComparisonCompactor.class", + "junit/framework/ComparisonFailure.class", + "junit/framework/Protectable.class", ) } @@ -207,18 +195,14 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf( - "shadow/ShadowTest.class", - "shadow/junit/Test.class", - "shadow/junit", - ), + "shadow/ShadowTest.class", + "shadow/junit/Test.class", + "shadow/junit", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf( - "junit/framework", - "junit/framework/Test.class", - ), + "junit/framework", + "junit/framework/Test.class", ) val classLoader = URLClassLoader( @@ -292,14 +276,12 @@ class RelocationTest : BasePluginTest() { val appOutput = jarPath("app/build/libs/app-all.jar") assertThat(appOutput).containsEntries( - listOf( - "TEST", - "APP-TEST", - "test.properties", - "app/core/Core.class", - "app/App.class", - "app/junit/framework/Test.class", - ), + "TEST", + "APP-TEST", + "test.properties", + "app/core/Core.class", + "app/App.class", + "app/junit/framework/Test.class", ) } @@ -335,18 +317,14 @@ class RelocationTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf( - "bar/Foo.class", - "bar/foo.properties", - "bar/dep.properties", - ), + "bar/Foo.class", + "bar/foo.properties", + "bar/dep.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf( - "foo/Foo.class", - "foo/foo.properties", - "foo/dep.properties", - ), + "foo/Foo.class", + "foo/foo.properties", + "foo/dep.properties", ) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index 6a044c4cf..67f71634e 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -128,10 +128,11 @@ class ShadowPluginTest : BasePluginTest() { val outputShadowJar = jarPath("build/libs/shadow.jar") assertThat(outputShadowJar).containsEntries( - listOf("shadow/Passed.class", "junit/framework/Test.class"), + "shadow/Passed.class", + "junit/framework/Test.class", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("/"), + "/", ) } @@ -142,7 +143,9 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class", "junit/framework/Test.class"), + "client/Client.class", + "server/Server.class", + "junit/framework/Test.class", ) } @@ -171,10 +174,11 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class"), + "client/Client.class", + "server/Server.class", ) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("junit/framework/Test.class"), + "junit/framework/Test.class", ) } @@ -196,10 +200,11 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("server/Server.class", "junit/framework/Test.class"), + "server/Server.class", + "junit/framework/Test.class", ) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("client/Client.class"), + "client/Client.class", ) } @@ -220,7 +225,8 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class"), + "client/Client.class", + "server/Server.class", ) } @@ -250,7 +256,9 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), + "client/Client.class", + "server/Server.class", + "junit/framework/TestCase.class", ) path("client/src/main/java/client/Client.java").writeText( @@ -264,7 +272,9 @@ class ShadowPluginTest : BasePluginTest() { // TODO: I don't think junit classes should be in the output jar, but it's the test case // from https://github.com/GradleUp/shadow/pull/420, need to investigate more... assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "server/Server.class", "junit/framework/TestCase.class"), + "client/Client.class", + "server/Server.class", + "junit/framework/TestCase.class", ) } @@ -281,10 +291,14 @@ class ShadowPluginTest : BasePluginTest() { val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).containsEntries( - listOf("impl/SimpleEntity.class", "api/Entity.class", "api/UnusedEntity.class", "lib/LibEntity.class"), + "impl/SimpleEntity.class", + "api/Entity.class", + "api/UnusedEntity.class", + "lib/LibEntity.class", ) assertThat(implOutput).doesNotContainEntries( - listOf("junit/framework/Test.class", "lib/UnusedLibEntity.class"), + "junit/framework/Test.class", + "lib/UnusedLibEntity.class", ) } @@ -310,16 +324,14 @@ class ShadowPluginTest : BasePluginTest() { val implOutput = jarPath("impl/build/libs/impl-all.jar") assertThat(implOutput).containsEntries( - listOf( - "impl/SimpleEntity.class", - "api/Entity.class", - "api/UnusedEntity.class", - "lib/LibEntity.class", - "lib/UnusedLibEntity.class", - ), + "impl/SimpleEntity.class", + "api/Entity.class", + "api/UnusedEntity.class", + "lib/LibEntity.class", + "lib/UnusedLibEntity.class", ) assertThat(implOutput).doesNotContainEntries( - listOf("junit/framework/Test.class"), + "junit/framework/Test.class", ) } @@ -331,15 +343,18 @@ class ShadowPluginTest : BasePluginTest() { val serverOutput = jarPath("server/build/libs/server-1.0.jar") assertThat(serverOutput).containsEntries( - listOf("server/Server.class"), + "server/Server.class", ) assertThat(serverOutput).doesNotContainEntries( - listOf("client/Client.class", "junit/framework/Test.class", "client/junit/framework/Test.class"), + "client/Client.class", + "junit/framework/Test.class", + "client/junit/framework/Test.class", ) val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(clientOutput).containsEntries( - listOf("client/Client.class", "client/junit/framework/Test.class"), + "client/Client.class", + "client/junit/framework/Test.class", ) } @@ -350,15 +365,18 @@ class ShadowPluginTest : BasePluginTest() { run(serverShadowJarTask) assertThat(outputServerShadowJar).containsEntries( - listOf("client/Client.class", "client/junit/framework/Test.class", "server/Server.class"), + "client/Client.class", + "client/junit/framework/Test.class", + "server/Server.class", ) assertThat(outputServerShadowJar).doesNotContainEntries( - listOf("junit/framework/Test.class"), + "junit/framework/Test.class", ) val clientOutput = jarPath("client/build/libs/client-all.jar") assertThat(clientOutput).containsEntries( - listOf("client/Client.class", "client/junit/framework/Test.class"), + "client/Client.class", + "client/junit/framework/Test.class", ) } @@ -391,10 +409,16 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("shadow/Passed.class", "a.properties", "META-INF/a.properties"), + "shadow/Passed.class", + "a.properties", + "META-INF/a.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("META-INF/INDEX.LIST", "META-INF/a.SF", "META-INF/a.DSA", "META-INF/a.RSA", "module-info.class"), + "META-INF/INDEX.LIST", + "META-INF/a.SF", + "META-INF/a.DSA", + "META-INF/a.RSA", + "module-info.class", ) } @@ -415,10 +439,11 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "a2.properties"), + "a.properties", + "a2.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("b.properties"), + "b.properties", ) } @@ -452,7 +477,10 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("api.properties", "implementation.properties", "runtimeOnly.properties", "implementation-dep.properties"), + "api.properties", + "implementation.properties", + "runtimeOnly.properties", + "implementation-dep.properties", ) } @@ -473,10 +501,11 @@ class ShadowPluginTest : BasePluginTest() { run(shadowJarTask) assertThat(outputShadowJar).containsEntries( - listOf("a.properties", "a2.properties"), + "a.properties", + "a2.properties", ) assertThat(outputShadowJar).doesNotContainEntries( - listOf("b.properties"), + "b.properties", ) } diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt index 5d7fa8fd9..323e2811e 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt @@ -280,7 +280,9 @@ class TransformersTest : BaseTransformerTest() { .isEqualTo("com.acme.foo.FooExtension,com.acme.foo.BarExtension,com.acme.bar.SomeExtension,com.acme.bar.AnotherExtension") assertThat(props.getProperty("staticExtensionClasses")) .isEqualTo("com.acme.foo.FooStaticExtension,com.acme.bar.SomeStaticExtension") - assertThat(outputShadowJar).doesNotContainEntries(listOf(ENTRY_SERVICE_EXTENSION_MODULE)) + assertThat(outputShadowJar).doesNotContainEntries( + ENTRY_SERVICE_EXTENSION_MODULE, + ) } @Test diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index b7d2186bc..9f9ab7409 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -33,13 +33,13 @@ class JarPath(val path: Path) : */ fun Assert.isRegular() = transform { it.entries().toList() }.isNotEmpty() -fun Assert.containsEntries(entries: Iterable) = transform { actual -> +fun Assert.containsEntries(vararg entries: String) = transform { actual -> entries.forEach { entry -> actual.getEntry(entry) ?: fail("Jar file ${actual.path} does not contain entry $entry") } } -fun Assert.doesNotContainEntries(entries: Iterable) = transform { actual -> +fun Assert.doesNotContainEntries(vararg entries: String) = transform { actual -> entries.forEach { entry -> actual.getEntry(entry) ?: return@forEach fail("Jar file ${actual.path} contains entry $entry")