From 11fad5eca747dfda7f36d7873c2640a2fed34a04 Mon Sep 17 00:00:00 2001 From: "dima.avdeev" <99798741+dima-avdeev-jb@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:40:44 +0300 Subject: [PATCH] Gradle plugin delete unavailable simulator (#2413) * fix gradle plugin delete unavailable simulator * apply suggestion to simpify usage of getSimctlListData() --- .../uikit/internal/registerSimulatorTasks.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 aedab08904..148d01ff58 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 @@ -33,21 +33,22 @@ fun Project.registerSimulatorTasks( ) 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 device = getSimctlListData().devices.map { it.value }.flatten() + .firstOrNull { device: DeviceData -> + val xcode13Condition = device.state.contains("unavailable") + val xcode14Condition = device.isAvailable == false + device.name == deviceName && (xcode13Condition || xcode14Condition) + } + if (device != null) { + 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 } }