Skip to content

Commit

Permalink
Fix issue 2114. Gradle plugin with xcode 13.4. Add default null value…
Browse files Browse the repository at this point in the history
…s for unused json params. (#2131)
  • Loading branch information
dima-avdeev-jb authored Jun 20, 2022
1 parent 85a7e6c commit 586ec43
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,52 @@ import kotlinx.serialization.Serializable

@Serializable
internal class SimctlListData(
val devicetypes: List<DeviceTypeData>,
val devicetypes: List<DeviceTypeData> = emptyList(),
val runtimes: List<RuntimeData>,
val devices: Map<String, List<DeviceData>>,
val pairs: Map<String, WatchAndPhonePairData>,
val pairs: Map<String, WatchAndPhonePairData> = 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<SupportedDeviceTypeData>
)

@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,
)

Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,24 @@ fun Project.registerSimulatorTasks(
taskInstallXcodeGen = taskInstallXcodeGen,
)

val taskSimulatorDeleteUnavailable = tasks.composeIosTask<AbstractComposeIosTask>("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<AbstractComposeIosTask>("iosSimulatorCreate$id") {
dependsOn(taskSimulatorDeleteUnavailable)
onlyIf { getSimctlListData().devices.map { it.value }.flatten().none { it.name == deviceName } }
doFirst {
val availableRuntimes = getSimctlListData().runtimes.filter { runtime ->
Expand All @@ -49,10 +66,10 @@ fun Project.registerSimulatorTasks(
}

val taskBootSimulator = tasks.composeIosTask<AbstractComposeIosTask>("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")
Expand Down

0 comments on commit 586ec43

Please sign in to comment.