Class: SimulatorUtil
- Inherits:
-
Object
- Object
- SimulatorUtil
- Defined in:
- lib/jenkins_util/simulator_util.rb
Constant Summary collapse
- DEVICE_STATE_INVALID =
159
- DEVICE_ALREADY_SHUTDOWN =
163
Class Method Summary collapse
- .boot_device(udid) ⇒ Object
- .devices ⇒ Object
- .devices_by_os ⇒ Object
- .devices_by_udid ⇒ Object
- .reset_all_simulators ⇒ Object
- .reset_device(udid) ⇒ Object
- .shutdown_device(udid) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ SimulatorUtil
constructor
A new instance of SimulatorUtil.
Constructor Details
#initialize ⇒ SimulatorUtil
Returns a new instance of SimulatorUtil.
24 25 |
# File 'lib/jenkins_util/simulator_util.rb', line 24 def initialize end |
Class Method Details
.boot_device(udid) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/jenkins_util/simulator_util.rb', line 62 def self.boot_device(udid) process = CommandLineScript.new("xcrun simctl boot #{udid}") LoggerUtil.fatal("Could not boot up device: #{udid}") if process.exit_status.nonzero? && process.exit_status != DEVICE_STATE_INVALID end |
.devices ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jenkins_util/simulator_util.rb', line 39 def self.devices flattened_devices = [] devices_by_os.each do |os, devices| devices.each do |device| device['os'] = os flattened_devices << device end end flattened_devices end |
.devices_by_os ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jenkins_util/simulator_util.rb', line 27 def self.devices_by_os process = CommandLineScript.new('xcrun simctl list --json devices') json_string = '' process.stdout.each do |fragment| json_string += fragment end json = JSON.parse(json_string) json['devices'] end |
.devices_by_udid ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/jenkins_util/simulator_util.rb', line 52 def self.devices_by_udid devices_by_udid = {} devices.each do |device| devices_by_udid[device['udid']] = device end devices_by_udid end |
.reset_all_simulators ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jenkins_util/simulator_util.rb', line 84 def self.reset_all_simulators CommandLineScript.new('killall "Simulator"') CommandLineScript.new('killall "Simulator (Watch)"') process = CommandLineScript.new('xcrun simctl shutdown all') LoggerUtil.fatal('Could not shutdown all simulators') if process.exit_status.nonzero? process = CommandLineScript.new('xcrun simctl erase all') LoggerUtil.fatal('Could not erase all simulators') if process.exit_status.nonzero? end |
.reset_device(udid) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/jenkins_util/simulator_util.rb', line 77 def self.reset_device(udid) process = CommandLineScript.new("xcrun simctl erase #{udid}") LoggerUtil.fatal("Could not reset device: #{udid}") if process.exit_status.nonzero? && process.exit_status != DEVICE_STATE_INVALID end |
.shutdown_device(udid) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/jenkins_util/simulator_util.rb', line 69 def self.shutdown_device(udid) process = CommandLineScript.new("xcrun simctl shutdown #{udid}") LoggerUtil.fatal("Could not shutdown device: #{udid}") if process.exit_status.nonzero? && process.exit_status != DEVICE_STATE_INVALID && process.exit_status != DEVICE_ALREADY_SHUTDOWN end |