From 3a9bb519487591d478237a5b8d0dfe1f8a7ed4da Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:15:26 +0800 Subject: [PATCH 01/14] Move doesNotErrorWhenUsingApplicationMainClassProperty and checkLargeZipFilesWithZip64Enabled --- .../gradle/plugins/shadow/ApplicationTest.kt | 102 ++++++++++++++++++ .../gradle/plugins/shadow/ShadowPluginTest.kt | 101 ----------------- 2 files changed, 102 insertions(+), 101 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 8f3ea3e97..b9c56d74d 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -6,6 +6,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.Issue import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr import com.github.jengelman.gradle.plugins.shadow.util.isRegular @@ -13,6 +14,7 @@ import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText import org.apache.tools.zip.ZipFile +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test class ApplicationTest : BasePluginTest() { @@ -99,6 +101,106 @@ class ApplicationTest : BasePluginTest() { assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular() } + @Issue( + "https://github.com/GradleUp/shadow/issues/609", + ) + @Test + fun doesNotErrorWhenUsingApplicationMainClassProperty() { + projectScriptPath.appendText( + """ + apply plugin: 'application' + + application { + mainClass = 'myapp.Main' + } + $runShadow { + args 'foo' + } + """.trimIndent(), + ) + + path("src/main/java/myapp/Main.java").writeText( + """ + package myapp; + public class Main { + public static void main(String[] args) { + System.out.println("TestApp: Hello World! (" + args[0] + ")"); + } + } + """.trimIndent(), + ) + + val result = run(runShadowTask) + + assertThat(result.output).contains("TestApp: Hello World! (foo)") + } + + /** + * This spec requires > 15 minutes and > 8GB of disk space to run + */ + @Issue( + "https://github.com/GradleUp/shadow/issues/143", + ) + @Disabled + @Test + fun checkLargeZipFilesWithZip64Enabled() { + path("src/main/java/myapp/Main.java").writeText( + """ + package myapp; + public class Main { + public static void main(String[] args) { + System.out.println("TestApp: Hello World! (" + args[0] + ")"); + } + } + """.trimIndent(), + ) + + settingsScriptPath.appendText("rootProject.name = 'myapp'") + projectScriptPath.appendText( + """ + apply plugin: 'application' + + application { + mainClass = 'myapp.Main' + } + dependencies { + implementation 'shadow:a:1.0' + } + def generatedResourcesDir = new File(project.layout.buildDirectory.asFile.get(), "generated-resources") + def generateResources = tasks.register('generateResources') { + doLast { + def rnd = new Random() + def buf = new byte[128 * 1024] + for (x in 0..255) { + def dir = new File(generatedResourcesDir, x.toString()) + dir.mkdirs() + for (y in 0..255) { + def file = new File(dir, y.toString()) + rnd.nextBytes(buf) + file.bytes = buf + } + } + } + } + sourceSets { + main { + output.dir(generatedResourcesDir, builtBy: generateResources) + } + } + $shadowJar { + zip64 = true + } + $runShadow { + args 'foo' + } + """.trimIndent(), + ) + + val result = run(runShadowTask) + + assertThat(result.output).contains("TestApp: Hello World! (foo)") + } + private fun prepare( projectBlock: String = "", settingsBlock: String = "", diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt index d73eee5b4..7a3cda9cb 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt @@ -25,7 +25,6 @@ import org.gradle.testfixtures.ProjectBuilder import org.gradle.testkit.runner.TaskOutcome.FAILED import org.gradle.testkit.runner.TaskOutcome.SUCCESS import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.condition.EnabledForJreRange import org.junit.jupiter.api.condition.JRE @@ -639,106 +638,6 @@ class ShadowPluginTest : BasePluginTest() { assertThat(outputShadowJar).isRegular() } - /** - * This spec requires > 15 minutes and > 8GB of disk space to run - */ - @Issue( - "https://github.com/GradleUp/shadow/issues/143", - ) - @Disabled - @Test - fun checkLargeZipFilesWithZip64Enabled() { - path("src/main/java/myapp/Main.java").writeText( - """ - package myapp; - public class Main { - public static void main(String[] args) { - System.out.println("TestApp: Hello World! (" + args[0] + ")"); - } - } - """.trimIndent(), - ) - - settingsScriptPath.appendText("rootProject.name = 'myapp'") - projectScriptPath.appendText( - """ - apply plugin: 'application' - - application { - mainClass = 'myapp.Main' - } - dependencies { - implementation 'shadow:a:1.0' - } - def generatedResourcesDir = new File(project.layout.buildDirectory.asFile.get(), "generated-resources") - def generateResources = tasks.register('generateResources') { - doLast { - def rnd = new Random() - def buf = new byte[128 * 1024] - for (x in 0..255) { - def dir = new File(generatedResourcesDir, x.toString()) - dir.mkdirs() - for (y in 0..255) { - def file = new File(dir, y.toString()) - rnd.nextBytes(buf) - file.bytes = buf - } - } - } - } - sourceSets { - main { - output.dir(generatedResourcesDir, builtBy: generateResources) - } - } - $shadowJar { - zip64 = true - } - $runShadow { - args 'foo' - } - """.trimIndent(), - ) - - val result = run(runShadowTask) - - assertThat(result.output).contains("TestApp: Hello World! (foo)") - } - - @Issue( - "https://github.com/GradleUp/shadow/issues/609", - ) - @Test - fun doesNotErrorWhenUsingApplicationMainClassProperty() { - projectScriptPath.appendText( - """ - apply plugin: 'application' - - application { - mainClass = 'myapp.Main' - } - $runShadow { - args 'foo' - } - """.trimIndent(), - ) - - path("src/main/java/myapp/Main.java").writeText( - """ - package myapp; - public class Main { - public static void main(String[] args) { - System.out.println("TestApp: Hello World! (" + args[0] + ")"); - } - } - """.trimIndent(), - ) - - val result = run(runShadowTask) - - assertThat(result.output).contains("TestApp: Hello World! (foo)") - } - @Issue( "https://github.com/GradleUp/shadow/issues/459", "https://github.com/GradleUp/shadow/issues/852", From ccc93d2e6fb2ceac4497e490e8951cd299bde1e5 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:19:39 +0800 Subject: [PATCH 02/14] Simplify doesNotErrorWhenUsingApplicationMainClassProperty --- .../gradle/plugins/shadow/ApplicationTest.kt | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index b9c56d74d..e24d30618 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -106,29 +106,7 @@ class ApplicationTest : BasePluginTest() { ) @Test fun doesNotErrorWhenUsingApplicationMainClassProperty() { - projectScriptPath.appendText( - """ - apply plugin: 'application' - - application { - mainClass = 'myapp.Main' - } - $runShadow { - args 'foo' - } - """.trimIndent(), - ) - - path("src/main/java/myapp/Main.java").writeText( - """ - package myapp; - public class Main { - public static void main(String[] args) { - System.out.println("TestApp: Hello World! (" + args[0] + ")"); - } - } - """.trimIndent(), - ) + prepare() val result = run(runShadowTask) From 8b3eab005261cd78961f470099dd63e345410dfd Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:22:44 +0800 Subject: [PATCH 03/14] Simplify checkLargeZipFilesWithZip64Enabled --- .../gradle/plugins/shadow/ApplicationTest.kt | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index e24d30618..4b3efa6bc 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -122,28 +122,8 @@ class ApplicationTest : BasePluginTest() { @Disabled @Test fun checkLargeZipFilesWithZip64Enabled() { - path("src/main/java/myapp/Main.java").writeText( - """ - package myapp; - public class Main { - public static void main(String[] args) { - System.out.println("TestApp: Hello World! (" + args[0] + ")"); - } - } - """.trimIndent(), - ) - - settingsScriptPath.appendText("rootProject.name = 'myapp'") - projectScriptPath.appendText( - """ - apply plugin: 'application' - - application { - mainClass = 'myapp.Main' - } - dependencies { - implementation 'shadow:a:1.0' - } + prepare( + projectBlock = """ def generatedResourcesDir = new File(project.layout.buildDirectory.asFile.get(), "generated-resources") def generateResources = tasks.register('generateResources') { doLast { @@ -168,9 +148,6 @@ class ApplicationTest : BasePluginTest() { $shadowJar { zip64 = true } - $runShadow { - args 'foo' - } """.trimIndent(), ) From 9440ee9d16377e29c46fdee9a724fd58a9fc09d7 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:25:31 +0800 Subject: [PATCH 04/14] Remove checkLargeZipFilesWithZip64Enabled as it's disabled --- .../gradle/plugins/shadow/ApplicationTest.kt | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 4b3efa6bc..61575ebd3 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -14,7 +14,6 @@ import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText import org.apache.tools.zip.ZipFile -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test class ApplicationTest : BasePluginTest() { @@ -113,49 +112,6 @@ class ApplicationTest : BasePluginTest() { assertThat(result.output).contains("TestApp: Hello World! (foo)") } - /** - * This spec requires > 15 minutes and > 8GB of disk space to run - */ - @Issue( - "https://github.com/GradleUp/shadow/issues/143", - ) - @Disabled - @Test - fun checkLargeZipFilesWithZip64Enabled() { - prepare( - projectBlock = """ - def generatedResourcesDir = new File(project.layout.buildDirectory.asFile.get(), "generated-resources") - def generateResources = tasks.register('generateResources') { - doLast { - def rnd = new Random() - def buf = new byte[128 * 1024] - for (x in 0..255) { - def dir = new File(generatedResourcesDir, x.toString()) - dir.mkdirs() - for (y in 0..255) { - def file = new File(dir, y.toString()) - rnd.nextBytes(buf) - file.bytes = buf - } - } - } - } - sourceSets { - main { - output.dir(generatedResourcesDir, builtBy: generateResources) - } - } - $shadowJar { - zip64 = true - } - """.trimIndent(), - ) - - val result = run(runShadowTask) - - assertThat(result.output).contains("TestApp: Hello World! (foo)") - } - private fun prepare( projectBlock: String = "", settingsBlock: String = "", From 78f396b519fc0e0dc3f343859e2d9c5ae381b523 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:34:21 +0800 Subject: [PATCH 05/14] Add dependenciesBlock slot in prepare --- .../jengelman/gradle/plugins/shadow/ApplicationTest.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 61575ebd3..8d85c62c8 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -72,11 +72,7 @@ class ApplicationTest : BasePluginTest() { @Test fun shadowApplicationDistributionsShouldUseShadowJar() { prepare( - projectBlock = """ - dependencies { - shadow 'shadow:a:1.0' - } - """.trimIndent(), + dependenciesBlock = " shadow 'shadow:a:1.0'", ) run("shadowDistZip") @@ -115,6 +111,7 @@ class ApplicationTest : BasePluginTest() { private fun prepare( projectBlock: String = "", settingsBlock: String = "", + dependenciesBlock: String = "implementation 'shadow:a:1.0'", runShadowBlock: String = "", ) { path("src/main/java/myapp/Main.java").appendText( @@ -135,7 +132,7 @@ class ApplicationTest : BasePluginTest() { mainClass = 'myapp.Main' } dependencies { - implementation 'shadow:a:1.0' + $dependenciesBlock } $runShadow { args 'foo' From 5dd314e949380f1e5858dadae4ad02ac2a76b441 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:39:17 +0800 Subject: [PATCH 06/14] Use containsExactly for shadowApplicationDistributionsShouldUseShadowJar --- .../github/jengelman/gradle/plugins/shadow/ApplicationTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 8d85c62c8..6769eb447 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -3,7 +3,7 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.all import assertk.assertThat import assertk.assertions.contains -import assertk.assertions.containsAtLeast +import assertk.assertions.containsExactly import assertk.assertions.exists import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.util.Issue @@ -81,7 +81,7 @@ class ApplicationTest : BasePluginTest() { assertThat(zip).exists() val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name } - assertThat(entries).containsAtLeast( + assertThat(entries.filter { it.endsWith(".jar") }).containsExactly( "myapp-shadow-1.0/lib/myapp-1.0-all.jar", "myapp-shadow-1.0/lib/a-1.0.jar", ) From a2357e107804bcf2840fac1c939c6c9ca43237ed Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:49:02 +0800 Subject: [PATCH 07/14] Remove doesNotErrorWhenUsingApplicationMainClassProperty as it's redundant --- .../gradle/plugins/shadow/ApplicationTest.kt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 6769eb447..0f4df4d98 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -6,7 +6,6 @@ import assertk.assertions.contains import assertk.assertions.containsExactly 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.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr import com.github.jengelman.gradle.plugins.shadow.util.isRegular @@ -96,18 +95,6 @@ class ApplicationTest : BasePluginTest() { assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular() } - @Issue( - "https://github.com/GradleUp/shadow/issues/609", - ) - @Test - fun doesNotErrorWhenUsingApplicationMainClassProperty() { - prepare() - - val result = run(runShadowTask) - - assertThat(result.output).contains("TestApp: Hello World! (foo)") - } - private fun prepare( projectBlock: String = "", settingsBlock: String = "", From d6e766020d4a7daf541f264d1ead5e2e73fa0af9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 10:52:44 +0800 Subject: [PATCH 08/14] Inline runShadow values --- .../jengelman/gradle/plugins/shadow/ApplicationTest.kt | 10 ++++++++-- .../jengelman/gradle/plugins/shadow/BasePluginTest.kt | 7 ------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt index 0f4df4d98..4b9e87875 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt @@ -6,6 +6,8 @@ import assertk.assertions.contains import assertk.assertions.containsExactly import assertk.assertions.exists import assertk.assertions.isEqualTo +import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_INSTALL_TASK_NAME +import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr import com.github.jengelman.gradle.plugins.shadow.util.isRegular @@ -36,7 +38,7 @@ class ApplicationTest : BasePluginTest() { """.trimIndent(), ) - val result = run(runShadowTask) + val result = run(SHADOW_RUN_TASK_NAME) assertThat(result.output).contains( "Running application with JDK 17", @@ -90,7 +92,7 @@ class ApplicationTest : BasePluginTest() { fun installShadowDoesNotExecuteDependentShadowTask() { prepare() - run(ShadowApplicationPlugin.SHADOW_INSTALL_TASK_NAME) + run(SHADOW_INSTALL_TASK_NAME) assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular() } @@ -134,4 +136,8 @@ class ApplicationTest : BasePluginTest() { ), ) } + + private companion object { + val runShadow = "tasks.named('$SHADOW_RUN_TASK_NAME')".trim() + } } diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt index 2564ddfa3..1eabb1171 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/BasePluginTest.kt @@ -6,9 +6,7 @@ import assertk.assertThat import assertk.assertions.doesNotContain import assertk.assertions.isEqualTo import assertk.assertions.isNotNull -import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHADOW_JAR_TASK_NAME -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.transformers.Transformer import com.github.jengelman.gradle.plugins.shadow.util.AppendableMavenRepository @@ -81,7 +79,6 @@ abstract class BasePluginTest { } open val shadowJarTask = ":$SHADOW_JAR_TASK_NAME" - open val runShadowTask = ":$SHADOW_RUN_TASK_NAME" val serverShadowJarTask = ":server:$SHADOW_JAR_TASK_NAME" val projectScriptPath: Path get() = path("build.gradle") @@ -323,10 +320,6 @@ abstract class BasePluginTest { tasks.named('$SHADOW_JAR_TASK_NAME', ${ShadowJar::class.java.name}) """.trimIndent() - val runShadow = """ - tasks.named('$SHADOW_RUN_TASK_NAME', ${JavaJarExec::class.java.name}) - """.trimIndent() - val commonArguments = listOf( "--warning-mode=fail", "--configuration-cache", From 8a772496f3ee4b90c75c48165087b3eda4d68c0b Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:01:02 +0800 Subject: [PATCH 09/14] Rename ShadowPluginTest to JavaPluginTest --- .../plugins/shadow/{ShadowPluginTest.kt => JavaPluginTest.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/{ShadowPluginTest.kt => JavaPluginTest.kt} (99%) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginTest.kt similarity index 99% rename from src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt rename to src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginTest.kt index 3ca091208..2171debe3 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/JavaPluginTest.kt @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.condition.DisabledForJreRange import org.junit.jupiter.api.condition.JRE -class ShadowPluginTest : BasePluginTest() { +class JavaPluginTest : BasePluginTest() { @Test fun applyPlugin() { val projectName = "my-shadow" From ebf617645dfcb6201201fae7236853019df0675d Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:01:17 +0800 Subject: [PATCH 10/14] Rename ApplicationTest to ApplicationPluginTest --- .../shadow/{ApplicationTest.kt => ApplicationPluginTest.kt} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/{ApplicationTest.kt => ApplicationPluginTest.kt} (98%) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt similarity index 98% rename from src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt rename to src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt index 4b9e87875..4e82e1bb4 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt @@ -17,7 +17,7 @@ import kotlin.io.path.writeText import org.apache.tools.zip.ZipFile import org.junit.jupiter.api.Test -class ApplicationTest : BasePluginTest() { +class ApplicationPluginTest : BasePluginTest() { @Test fun integrationWithApplicationPluginAndJavaToolchains() { prepare( From 8479d2cac55b8895dc3c9a2a4e43230a3b4bc90a Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:04:07 +0800 Subject: [PATCH 11/14] Bump org.gradle.toolchains.foojay-resolver-convention to 0.9.0 --- .../jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt index 4e82e1bb4..cefac44d9 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt @@ -28,7 +28,7 @@ class ApplicationPluginTest : BasePluginTest() { """.trimIndent(), settingsBlock = """ plugins { - id('org.gradle.toolchains.foojay-resolver-convention') version '0.7.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0' } """.trimIndent(), runShadowBlock = """ From ce6d3051bc4d97db782af054fe780de6a7226c5b Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:20:25 +0800 Subject: [PATCH 12/14] Assert more entries in shadowApplicationDistributionsShouldUseShadowJar --- .../plugins/shadow/ApplicationPluginTest.kt | 31 +++++++++++++------ .../gradle/plugins/shadow/util/JarPath.kt | 6 ++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt index cefac44d9..35828b572 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt @@ -3,18 +3,19 @@ package com.github.jengelman.gradle.plugins.shadow import assertk.all import assertk.assertThat import assertk.assertions.contains -import assertk.assertions.containsExactly +import assertk.assertions.containsOnly import assertk.assertions.exists import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_INSTALL_TASK_NAME import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME import com.github.jengelman.gradle.plugins.shadow.util.containsEntries +import com.github.jengelman.gradle.plugins.shadow.util.getContent import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr import com.github.jengelman.gradle.plugins.shadow.util.isRegular +import java.util.zip.ZipFile import kotlin.io.path.appendText import kotlin.io.path.readText import kotlin.io.path.writeText -import org.apache.tools.zip.ZipFile import org.junit.jupiter.api.Test class ApplicationPluginTest : BasePluginTest() { @@ -73,19 +74,29 @@ class ApplicationPluginTest : BasePluginTest() { @Test fun shadowApplicationDistributionsShouldUseShadowJar() { prepare( - dependenciesBlock = " shadow 'shadow:a:1.0'", + dependenciesBlock = "shadow 'shadow:a:1.0'", ) run("shadowDistZip") - val zip = path("build/distributions/myapp-shadow-1.0.zip") - assertThat(zip).exists() + ZipFile(path("build/distributions/myapp-shadow-1.0.zip").toFile()).use { zip -> + val fileEntries = zip.entries().toList().map { it.name }.filter { !it.endsWith("/") } + assertThat(fileEntries).containsOnly( + "myapp-shadow-1.0/bin/myapp", + "myapp-shadow-1.0/bin/myapp.bat", + "myapp-shadow-1.0/lib/myapp-1.0-all.jar", + "myapp-shadow-1.0/lib/a-1.0.jar", + ) - val entries = ZipFile(zip.toFile()).use { it.entries }.toList().map { it.name } - assertThat(entries.filter { it.endsWith(".jar") }).containsExactly( - "myapp-shadow-1.0/lib/myapp-1.0-all.jar", - "myapp-shadow-1.0/lib/a-1.0.jar", - ) + assertThat(zip.getContent("myapp-shadow-1.0/bin/myapp")).contains( + "CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar", + "-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"", + "exec \"\$JAVACMD\" \"\$@\"", + ) + assertThat(zip.getContent("myapp-shadow-1.0/bin/myapp.bat")).contains( + "set CLASSPATH=%APP_HOME%\\lib\\myapp-1.0-all.jar", + ) + } } @Test diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 9e10f3395..87ebb99da 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -6,6 +6,7 @@ import assertk.assertions.isNotEmpty import assertk.fail import java.nio.file.Path import java.util.jar.JarFile +import java.util.zip.ZipFile /** * A wrapper for [JarFile] that also implements [Path]. @@ -27,6 +28,11 @@ class JarPath(val path: Path) : } } +fun ZipFile.getContent(entryName: String): String { + val entry = getEntry(entryName) ?: error("Entry not found: $entryName") + return getInputStream(entry).bufferedReader().use { it.readText() } +} + /** * Common regular assertions for [JarPath]. */ From 9e71ddf8ba1d070f694a24a2b28db5747f420318 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:21:59 +0800 Subject: [PATCH 13/14] Reuse ZipFile.getContent and remove libs.apache.ant --- build.gradle.kts | 1 - .../plugins/shadow/transformers/AppendingTransformerTest.kt | 1 + .../transformers/GroovyExtensionModuleTransformerTest.kt | 1 + .../shadow/transformers/XmlAppendingTransformerTest.kt | 1 + .../github/jengelman/gradle/plugins/shadow/util/JarPath.kt | 5 ----- 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9fa451fde..ff1cb6d97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -100,7 +100,6 @@ testing.suites { dependencies { // Seems we can't ref project() here due to some limitations of rootProject. implementation(sourceSets.main.get().output) - implementation(libs.apache.ant) implementation(libs.apache.maven.modelBuilder) implementation(libs.moshi) implementation(libs.moshi.kotlin) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt index 04807f7f4..a32a8aa9b 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/AppendingTransformerTest.kt @@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo +import com.github.jengelman.gradle.plugins.shadow.util.getContent import kotlin.io.path.appendText import org.junit.jupiter.api.Test diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt index c373895f5..a13a43dbb 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt @@ -10,6 +10,7 @@ import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionMo import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.MERGED_MODULE_VERSION import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR +import com.github.jengelman.gradle.plugins.shadow.util.getContent import java.nio.file.Path import kotlin.io.path.appendText import org.junit.jupiter.api.Test diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt index dded30087..41f215257 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/XmlAppendingTransformerTest.kt @@ -2,6 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import assertk.assertThat import assertk.assertions.isEqualTo +import com.github.jengelman.gradle.plugins.shadow.util.getContent import kotlin.io.path.appendText import org.junit.jupiter.api.Test diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 87ebb99da..9c9e8afb7 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -21,11 +21,6 @@ class JarPath(val path: Path) : fun getMainAttr(name: String): String? { return manifest.mainAttributes.getValue(name) } - - fun getContent(entryName: String): String { - val entry = getEntry(entryName) ?: error("Entry not found: $entryName") - return getInputStream(entry).bufferedReader().use { it.readText() } - } } fun ZipFile.getContent(entryName: String): String { From 6c1eeeb649a74550766dd4400ee0a038f20e2069 Mon Sep 17 00:00:00 2001 From: Goooler Date: Mon, 13 Jan 2025 11:34:31 +0800 Subject: [PATCH 14/14] Add commonAssertions --- .../plugins/shadow/ApplicationPluginTest.kt | 30 ++++++++++++------- .../gradle/plugins/shadow/util/JarPath.kt | 7 ++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt index 35828b572..720df401b 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/ApplicationPluginTest.kt @@ -8,12 +8,14 @@ import assertk.assertions.exists import assertk.assertions.isEqualTo import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_INSTALL_TASK_NAME import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.SHADOW_RUN_TASK_NAME +import com.github.jengelman.gradle.plugins.shadow.util.JarPath import com.github.jengelman.gradle.plugins.shadow.util.containsEntries import com.github.jengelman.gradle.plugins.shadow.util.getContent import com.github.jengelman.gradle.plugins.shadow.util.getMainAttr -import com.github.jengelman.gradle.plugins.shadow.util.isRegular +import com.github.jengelman.gradle.plugins.shadow.util.getStream import java.util.zip.ZipFile import kotlin.io.path.appendText +import kotlin.io.path.outputStream import kotlin.io.path.readText import kotlin.io.path.writeText import org.junit.jupiter.api.Test @@ -46,14 +48,7 @@ class ApplicationPluginTest : BasePluginTest() { "TestApp: Hello World! (foo)", ) - assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).useAll { - containsEntries( - "a.properties", - "a2.properties", - "myapp/Main.class", - ) - getMainAttr("Main-Class").isEqualTo("myapp.Main") - } + commonAssertions(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")) assertThat(path("build/install/myapp-shadow/bin/myapp")).all { exists() @@ -88,6 +83,11 @@ class ApplicationPluginTest : BasePluginTest() { "myapp-shadow-1.0/lib/a-1.0.jar", ) + val extractedJar = path("extracted/myapp-1.0-all.jar") + zip.getStream("myapp-shadow-1.0/lib/myapp-1.0-all.jar") + .use { it.copyTo(extractedJar.outputStream()) } + commonAssertions(JarPath(extractedJar), entriesContained = arrayOf("myapp/Main.class")) + assertThat(zip.getContent("myapp-shadow-1.0/bin/myapp")).contains( "CLASSPATH=\$APP_HOME/lib/myapp-1.0-all.jar", "-jar \"\\\"\$CLASSPATH\\\"\" \"\$APP_ARGS\"", @@ -105,7 +105,7 @@ class ApplicationPluginTest : BasePluginTest() { run(SHADOW_INSTALL_TASK_NAME) - assertThat(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")).isRegular() + commonAssertions(jarPath("build/install/myapp-shadow/lib/myapp-1.0-all.jar")) } private fun prepare( @@ -148,6 +148,16 @@ class ApplicationPluginTest : BasePluginTest() { ) } + private fun commonAssertions( + jarPath: JarPath, + entriesContained: Array = arrayOf("a.properties", "a2.properties", "myapp/Main.class"), + ) { + assertThat(jarPath).useAll { + containsEntries(*entriesContained) + getMainAttr("Main-Class").isEqualTo("myapp.Main") + } + } + private companion object { val runShadow = "tasks.named('$SHADOW_RUN_TASK_NAME')".trim() } diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt index 9c9e8afb7..ec66a9136 100644 --- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt +++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarPath.kt @@ -4,6 +4,7 @@ import assertk.Assert import assertk.all import assertk.assertions.isNotEmpty import assertk.fail +import java.io.InputStream import java.nio.file.Path import java.util.jar.JarFile import java.util.zip.ZipFile @@ -24,8 +25,12 @@ class JarPath(val path: Path) : } fun ZipFile.getContent(entryName: String): String { + return getStream(entryName).bufferedReader().use { it.readText() } +} + +fun ZipFile.getStream(entryName: String): InputStream { val entry = getEntry(entryName) ?: error("Entry not found: $entryName") - return getInputStream(entry).bufferedReader().use { it.readText() } + return getInputStream(entry) } /**