Skip to content

Commit

Permalink
Update in plist_find_device method
Browse files Browse the repository at this point in the history
  • Loading branch information
ark-konopacki committed Jun 7, 2016
1 parent 68a7c1c commit bf8bd08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
21 changes: 19 additions & 2 deletions lib/run_loop/detect_aut/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions lib/run_loop/plist_buddy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf8bd08

Please sign in to comment.