From 586ec4310008ce6d3379030649bf256573e4f0ff Mon Sep 17 00:00:00 2001 From: "dima.avdeev" <99798741+dima-avdeev-jb@users.noreply.github.com> Date: Mon, 20 Jun 2022 18:29:56 +0300 Subject: [PATCH] Fix issue 2114. Gradle plugin with xcode 13.4. Add default null values for unused json params. (#2131) --- .../uikit/internal/SimctlListData.kt | 52 +++++++++---------- .../uikit/internal/registerSimulatorTasks.kt | 19 ++++++- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/SimctlListData.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/SimctlListData.kt index b999f9c60d..2a765e197e 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/SimctlListData.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/SimctlListData.kt @@ -11,52 +11,52 @@ import kotlinx.serialization.Serializable @Serializable internal class SimctlListData( - val devicetypes: List, + val devicetypes: List = emptyList(), val runtimes: List, val devices: Map>, - val pairs: Map, + val pairs: Map = emptyMap(), ) @Serializable internal class DeviceTypeData( - val name: String, - val minRuntimeVersion: Long, - val bundlePath: String, - val maxRuntimeVersion: Long, - val identifier: String, - val productFamily: String + val name: String? = null, + val minRuntimeVersion: Long? = null, + val bundlePath: String? = null, + val maxRuntimeVersion: Long? = null, + val identifier: String? = null, + val productFamily: String? = null ) @Serializable internal class RuntimeData( - val name: String, - val bundlePath: String, - val buildversion: String, - val runtimeRoot: String, + val name: String? = null, + val bundlePath: String? = null, + val buildversion: String? = null, + val runtimeRoot: String? = null, val identifier: String, val version: String, - val isAvailable: Boolean, + val isAvailable: Boolean? = null, val supportedDeviceTypes: List ) @Serializable internal class SupportedDeviceTypeData( - val bundlePath: String, - val name: String, + val bundlePath: String? = null, + val name: String? = null, val identifier: String, - val productFamily: String + val productFamily: String? = null ) @Serializable internal class DeviceData( val name: String, val availabilityError: String? = null, - val dataPath: String, - val dataPathSize: Long, - val logPath: String, + val dataPath: String? = null, + val dataPathSize: Long? = null, + val logPath: String? = null, val udid: String, - val isAvailable: Boolean, - val deviceTypeIdentifier: String, + val isAvailable: Boolean? = null, + val deviceTypeIdentifier: String? = null, val state: String, ) @@ -65,13 +65,13 @@ internal val DeviceData.booted: Boolean @Serializable internal class WatchAndPhonePairData( - val watch: DeviceInPairData, - val phone: DeviceInPairData + val watch: DeviceInPairData? = null, + val phone: DeviceInPairData? = null ) @Serializable internal class DeviceInPairData( - val name: String, - val udid: String, - val state: String, + val name: String? = null, + val udid: String? = null, + val state: String? = null, ) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerSimulatorTasks.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerSimulatorTasks.kt index 04253433c5..fda96082e1 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerSimulatorTasks.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/experimental/uikit/internal/registerSimulatorTasks.kt @@ -34,7 +34,24 @@ fun Project.registerSimulatorTasks( taskInstallXcodeGen = taskInstallXcodeGen, ) + val taskSimulatorDeleteUnavailable = tasks.composeIosTask("iosSimulatorDeleteUnavailable$id") { + val condition = { device: DeviceData -> device.name == deviceName && device.state.contains("unavailable") } + onlyIf { + getSimctlListData().devices.map { it.value }.flatten().any(condition) + } + doLast { + val device = getSimctlListData().devices.map { it.value }.flatten().first(condition) + + runExternalTool( + MacUtils.xcrun, + listOf("simctl", "delete", device.udid) + ) + } + } + + val taskCreateSimulator = tasks.composeIosTask("iosSimulatorCreate$id") { + dependsOn(taskSimulatorDeleteUnavailable) onlyIf { getSimctlListData().devices.map { it.value }.flatten().none { it.name == deviceName } } doFirst { val availableRuntimes = getSimctlListData().runtimes.filter { runtime -> @@ -49,10 +66,10 @@ fun Project.registerSimulatorTasks( } val taskBootSimulator = tasks.composeIosTask("iosSimulatorBoot$id") { + dependsOn(taskCreateSimulator) onlyIf { getSimctlListData().devices.map { it.value }.flatten().any { it.name == deviceName && it.booted.not() } } - dependsOn(taskCreateSimulator) doLast { val device = getSimctlListData().devices.map { it.value }.flatten().firstOrNull { it.name == deviceName } ?: error("device '$deviceName' not found")