Browse Source

Fix caching for checking runtime properties (#2438)

Resolves #2329
pull/2442/head
Alexey Tsvetkov 2 years ago committed by GitHub
parent
commit
083e51feb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt
  2. 12
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt
  3. 26
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt
  4. 25
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt

1
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt

@ -58,7 +58,6 @@ private fun JvmApplicationContext.configureCommonJvmDesktopTasks(): CommonJvmDes
taskNameObject = "runtime"
) {
javaHome.set(app.javaHomeProvider)
javaRuntimePropertiesFile.set(jvmTmpDirForTask().file("properties.bin"))
}
val suggestRuntimeModules = tasks.register<AbstractSuggestModulesTask>(

12
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt

@ -6,6 +6,7 @@
package org.jetbrains.compose.desktop.application.tasks
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
@ -23,14 +24,17 @@ internal const val MIN_JAVA_RUNTIME_VERSION = 15
@CacheableTask
abstract class AbstractCheckNativeDistributionRuntime : AbstractComposeDesktopTask() {
@get:Input
@get:PathSensitive(PathSensitivity.ABSOLUTE)
@get:InputDirectory
val javaHome: Property<String> = objects.notNullProperty()
private val taskDir = project.layout.buildDirectory.dir("compose/tmp/$name")
@get:OutputFile
val javaRuntimePropertiesFile: RegularFileProperty = objects.fileProperty()
val javaRuntimePropertiesFile: Provider<RegularFile> = taskDir.map { it.file("properties.bin") }
@get:LocalState
val workingDir: Provider<Directory> = project.layout.buildDirectory.dir("compose/tmp/$name")
val workingDir: Provider<Directory> = taskDir.map { it.dir("localState") }
private val javaExec: File
get() = getTool("java")
@ -47,6 +51,8 @@ abstract class AbstractCheckNativeDistributionRuntime : AbstractComposeDesktopTa
@TaskAction
fun run() {
taskDir.ioFile.mkdirs()
val javaRuntimeVersion = try {
getJavaRuntimeVersionUnsafe()?.toIntOrNull() ?: -1
} catch (e: Exception) {

26
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt

@ -122,6 +122,32 @@ class DesktopApplicationTest : GradlePluginTestBase() {
testPackageJvmDistributions()
}
@Test
fun gradleBuildCache() = with(testProject(TestProjects.jvm)) {
modifyGradleProperties {
setProperty("org.gradle.caching", "true")
}
modifyTextFile("settings.gradle") {
it + "\n" + """
buildCache {
local {
directory = new File(rootDir, 'build-cache')
}
}
""".trimIndent()
}
val packagingTask = ":packageDistributionForCurrentOS"
gradle(packagingTask).build().checks { check ->
check.taskOutcome(packagingTask, TaskOutcome.SUCCESS)
}
gradle("clean", packagingTask).build().checks { check ->
check.taskOutcome(":checkRuntime", TaskOutcome.FROM_CACHE)
check.taskOutcome(packagingTask, TaskOutcome.SUCCESS)
}
}
@Test
fun packageMpp() = with(testProject(TestProjects.mpp)) {
testPackageJvmDistributions()

25
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt

@ -8,6 +8,7 @@ package org.jetbrains.compose.test.utils
import org.gradle.testkit.runner.GradleRunner
import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import java.io.File
import java.util.Properties
data class TestEnvironment(
val workingDir: File,
@ -77,5 +78,29 @@ class TestProject(
fun file(path: String): File =
testEnvironment.workingDir.resolve(path)
fun modifyTextFile(path: String, fn: (String) -> String) {
val file = file(path)
val oldContent = file.readText()
val newContent = fn(oldContent)
file.writeText(newContent)
}
fun modifyGradleProperties(fn: Properties.() -> Unit) {
val propertiesFile = file("gradle.properties")
val properties = Properties()
if (propertiesFile.exists()) {
propertiesFile.bufferedReader().use { reader ->
properties.load(reader)
}
}
fn(properties)
propertiesFile.delete()
if (properties.isNotEmpty()) {
propertiesFile.bufferedWriter().use { writer ->
properties.store(writer, null)
}
}
}
}

Loading…
Cancel
Save