From fa74ec7aff81c24e6486537b1f6f4c2af77fe8af Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 4 Nov 2022 17:22:42 +0100 Subject: [PATCH] Fix custom JDK tests on Linux --- .../integration/DesktopApplicationTest.kt | 49 +++++++++++-------- .../compose/test/utils/TestProject.kt | 12 +++-- .../compose/test/utils/TestProjects.kt | 1 - .../application/customJavaHome/build.gradle | 34 ------------- .../customJavaHome/settings.gradle | 11 ----- .../customJavaHome/src/main/kotlin/main.kt | 18 ------- 6 files changed, 37 insertions(+), 88 deletions(-) delete mode 100644 gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle delete mode 100644 gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle delete mode 100644 gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt index a567fdc31b..7571e4a9b2 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt @@ -127,7 +127,7 @@ class DesktopApplicationTest : GradlePluginTestBase() { modifyGradleProperties { setProperty("org.gradle.caching", "true") } - modifyTextFile("settings.gradle") { + modifyText("settings.gradle") { it + "\n" + """ buildCache { local { @@ -153,26 +153,6 @@ class DesktopApplicationTest : GradlePluginTestBase() { testPackageJvmDistributions() } - private fun customJavaHomeProject(javaVersion: Int): TestProject = - testProject( - TestProjects.customJavaHome, - defaultTestEnvironment.copy(customJavaToolchainVersion = javaVersion) - ) - - @Test - fun testJdk15() = with(customJavaHomeProject(15)) { - testPackageJvmDistributions() - } - @Test - fun testJdk18() = with(customJavaHomeProject(18)) { - testPackageJvmDistributions() - } - - @Test - fun testJdk19() = with(customJavaHomeProject(19)) { - testPackageJvmDistributions() - } - private fun TestProject.testPackageJvmDistributions() { val result = gradle(":packageDistributionForCurrentOS").build() val ext = when (currentOS) { @@ -201,6 +181,33 @@ class DesktopApplicationTest : GradlePluginTestBase() { assertEquals(TaskOutcome.SUCCESS, result.task(":packageDistributionForCurrentOS")?.outcome) } + @Test + fun testJdk15() = with(customJdkProject(15)) { + testPackageJvmDistributions() + } + @Test + fun testJdk18() = with(customJdkProject(18)) { + testPackageJvmDistributions() + } + + @Test + fun testJdk19() = with(customJdkProject(19)) { + testPackageJvmDistributions() + } + + private fun customJdkProject(javaVersion: Int): TestProject = + testProject(TestProjects.jvm).apply { + appendText("build.gradle") { + """ + compose.desktop.application { + javaHome = javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of($javaVersion)) + }.get().metadata.installationPath.asFile.absolutePath + } + """.trimIndent() + } + } + @Test fun packageUberJarForCurrentOSJvm() = with(testProject(TestProjects.jvm)) { testPackageUberJarForCurrentOS() diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt index 8b03870f42..47cecdd1ce 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt @@ -15,13 +15,11 @@ data class TestEnvironment( val kotlinVersion: String = TestKotlinVersions.Default, val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion, val composeCompilerArtifact: String? = null, - val customJavaToolchainVersion: Int? = null ) { private val placeholders = linkedMapOf( "COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER" to composeGradlePluginVersion, "KOTLIN_VERSION_PLACEHOLDER" to kotlinVersion, "COMPOSE_COMPILER_ARTIFACT_PLACEHOLDER" to composeCompilerArtifact, - "CUSTOM_JAVA_TOOLCHAIN_VERSION_PLACEHOLDER" to customJavaToolchainVersion?.toString() ) fun replacePlaceholdersInFile(file: File) { @@ -79,12 +77,20 @@ class TestProject( fun file(path: String): File = testEnvironment.workingDir.resolve(path) - fun modifyTextFile(path: String, fn: (String) -> String) { + fun modifyText(path: String, fn: (String) -> String) { val file = file(path) val oldContent = file.readText() val newContent = fn(oldContent) file.writeText(newContent) } + + fun appendText(path: String, fn: () -> String) { + val file = file(path) + val oldContent = file.readText() + val newContent = oldContent + "\n" + fn() + file.writeText(newContent) + } + fun modifyGradleProperties(fn: Properties.() -> Unit) { val propertiesFile = file("gradle.properties") val properties = Properties() diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt index 30e0226a82..1a6863e839 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt @@ -20,7 +20,6 @@ object TestProjects { const val defaultArgsOverride = "application/defaultArgsOverride" const val unpackSkiko = "application/unpackSkiko" const val resources = "application/resources" - const val customJavaHome = "application/customJavaHome" const val jsMpp = "misc/jsMpp" const val jvmPreview = "misc/jvmPreview" } \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle b/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle deleted file mode 100644 index c12de0415e..0000000000 --- a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -import org.jetbrains.compose.desktop.application.dsl.TargetFormat - -plugins { - id "org.jetbrains.kotlin.jvm" - id "org.jetbrains.compose" -} - -repositories { - jetbrainsCompose() -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" - implementation compose.desktop.currentOs -} - -compose.desktop { - application { - mainClass = "MainKt" - nativeDistributions { - targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) - - packageVersion = "1.0.0" - packageName = "TestPackage" - description = "Test description" - copyright = "Test Copyright Holder" - vendor = "Test Vendor" - - javaHome = javaToolchains.launcherFor { - languageVersion.set(JavaLanguageVersion.of(CUSTOM_JAVA_TOOLCHAIN_VERSION_PLACEHOLDER)) - }.get().metadata.installationPath.asFile.absolutePath - } - } -} diff --git a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle b/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle deleted file mode 100644 index 43d540efb8..0000000000 --- a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle +++ /dev/null @@ -1,11 +0,0 @@ -pluginManagement { - plugins { - id 'org.jetbrains.kotlin.jvm' version 'KOTLIN_VERSION_PLACEHOLDER' - id 'org.jetbrains.compose' version 'COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER' - } - repositories { - mavenLocal() - gradlePluginPortal() - } -} -rootProject.name = "simple" \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt b/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt deleted file mode 100644 index 6b688cf95e..0000000000 --- a/gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt +++ /dev/null @@ -1,18 +0,0 @@ -import androidx.compose.material.Text -import androidx.compose.material.Button -import androidx.compose.material.MaterialTheme -import androidx.compose.ui.window.singleWindowApplication -import androidx.compose.runtime.* - -fun main() = singleWindowApplication { - val scope = rememberCoroutineScope() - var text by remember { mutableStateOf("Hello, World!") } - - MaterialTheme { - Button(onClick = { - text = "Hello, Desktop!" - }) { - Text(text) - } - } -} \ No newline at end of file