Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix caching for checking runtime properties #2438

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -47,6 +51,8 @@ abstract class AbstractCheckNativeDistributionRuntime : AbstractComposeDesktopTa

@TaskAction
fun run() {
taskDir.ioFile.mkdirs()

val javaRuntimeVersion = try {
getJavaRuntimeVersionUnsafe()?.toIntOrNull() ?: -1
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -67,5 +68,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)
}
}
}
}