Browse Source

Fix custom JDK tests on Linux

release/1.2.2
Alexey Tsvetkov 2 years ago committed by Igor Demin
parent
commit
fa74ec7aff
  1. 49
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt
  2. 12
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
  3. 1
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt
  4. 34
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle
  5. 11
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle
  6. 18
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt

49
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()

12
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()

1
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"
}

34
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle

@ -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
}
}
}

11
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle

@ -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"

18
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt

@ -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)
}
}
}
Loading…
Cancel
Save