Skip to content

Commit bf8bd08

Browse files
committed
Update in plist_find_device method
1 parent 68a7c1c commit bf8bd08

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

lib/run_loop/detect_aut/xcode.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,34 @@ def pbuddy
163163
@pbuddy ||= RunLoop::PlistBuddy.new
164164
end
165165

166+
# @!visibility private
167+
# @param [String] file the plist to read
168+
# @return [String] the UDID of device
169+
def self.plist_find_device(file)
170+
#TODO unfortunately i can use ony this solution
171+
file_content = `/usr/libexec/PlistBuddy -c Print "#{file}"`
172+
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
173+
if !file_content.nil? && !file_content.empty?
174+
lines = file_content.split("\n")
175+
lines.detect do |line|
176+
line[/dvtdevice.*:/, 0]
177+
end
178+
end
179+
end
180+
166181
# @!visibility private
167182
def self.detect_selected_device
168183
file_name = find_user_state_file
169-
@pbuddy ||= RunLoop::PlistBuddy.new
170-
selected_device = @pbuddy.plist_find_device(file_name)
184+
selected_device = plist_find_device(file_name)
171185
if selected_device != '' && !selected_device.nil?
172186
udid = selected_device.split(':')[1]
173187
selected_device = RunLoop::Device.device_with_identifier(udid)
174188
#TODO now only returning detected device if simulator detected
175189
if selected_device.simulator?
190+
RunLoop.log_info2("Detected simulator selected in Xcode is: #{selected_device}")
191+
RunLoop.log_info2("If this is not desired simulator, set the DEVICE_TARGET variable")
176192
selected_device
193+
177194
else
178195
nil
179196
end

lib/run_loop/plist_buddy.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ def plist_read(key, file, opts={})
2626
end
2727
end
2828

29-
# @!visibility private
30-
# @param [String] file the plist to read
31-
# @return [String] the UDID of device
32-
def plist_find_device(file)
33-
`#{plist_buddy} -c Print "#{file}"`
34-
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
35-
.split("\n")
36-
.select { |v| v =~ /dvtdevice.*:/ }[0]
37-
end
38-
3929
# Checks if the key exists in plist.
4030
# @param [String] key the key to inspect (may not be nil or empty)
4131
# @param [String] file the plist to read

0 commit comments

Comments
 (0)