From bf8bd08afb40b2c681fdd283fb98ec02e0c56a26 Mon Sep 17 00:00:00 2001 From: Arkadiusz Konopacki Date: Tue, 7 Jun 2016 23:06:57 +0200 Subject: [PATCH] Update in plist_find_device method --- lib/run_loop/detect_aut/xcode.rb | 21 +++++++++++++++++++-- lib/run_loop/plist_buddy.rb | 10 ---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/run_loop/detect_aut/xcode.rb b/lib/run_loop/detect_aut/xcode.rb index bf1dca4e..4c6070df 100644 --- a/lib/run_loop/detect_aut/xcode.rb +++ b/lib/run_loop/detect_aut/xcode.rb @@ -163,17 +163,34 @@ def pbuddy @pbuddy ||= RunLoop::PlistBuddy.new end + # @!visibility private + # @param [String] file the plist to read + # @return [String] the UDID of device + def self.plist_find_device(file) + #TODO unfortunately i can use ony this solution + file_content = `/usr/libexec/PlistBuddy -c Print "#{file}"` + .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') + if !file_content.nil? && !file_content.empty? + lines = file_content.split("\n") + lines.detect do |line| + line[/dvtdevice.*:/, 0] + end + end + end + # @!visibility private def self.detect_selected_device file_name = find_user_state_file - @pbuddy ||= RunLoop::PlistBuddy.new - selected_device = @pbuddy.plist_find_device(file_name) + selected_device = plist_find_device(file_name) if selected_device != '' && !selected_device.nil? udid = selected_device.split(':')[1] selected_device = RunLoop::Device.device_with_identifier(udid) #TODO now only returning detected device if simulator detected if selected_device.simulator? + RunLoop.log_info2("Detected simulator selected in Xcode is: #{selected_device}") + RunLoop.log_info2("If this is not desired simulator, set the DEVICE_TARGET variable") selected_device + else nil end diff --git a/lib/run_loop/plist_buddy.rb b/lib/run_loop/plist_buddy.rb index 1e0924a4..5d26209d 100644 --- a/lib/run_loop/plist_buddy.rb +++ b/lib/run_loop/plist_buddy.rb @@ -26,16 +26,6 @@ def plist_read(key, file, opts={}) end end - # @!visibility private - # @param [String] file the plist to read - # @return [String] the UDID of device - def plist_find_device(file) - `#{plist_buddy} -c Print "#{file}"` - .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') - .split("\n") - .select { |v| v =~ /dvtdevice.*:/ }[0] - end - # Checks if the key exists in plist. # @param [String] key the key to inspect (may not be nil or empty) # @param [String] file the plist to read