cordova-android/lib/run.rb

68 lines
1.5 KiB
Ruby
Raw Normal View History

2010-08-31 06:57:07 +08:00
#
# Run
# ---
#
# A handy machine that does the following:
#
2010-09-01 07:50:39 +08:00
# - runs ant_debug
2010-08-31 06:57:07 +08:00
# - if there is no device attached it will start an emulator with the first avd found
2010-09-01 07:50:39 +08:00
# - runs ant_install
2010-08-31 06:57:07 +08:00
#
class Run
# if no path is supplied uses current directory for project
2010-09-01 07:50:39 +08:00
def initialize
@path = FileUtils.pwd
build
start_emulator if first_device.nil?
install
2010-08-31 06:57:07 +08:00
end
2010-09-01 07:50:39 +08:00
def build
Dir.chdir(@path)
`ant debug`
2010-08-31 06:57:07 +08:00
end
2010-09-01 07:50:39 +08:00
def install
Dir.chdir(@path)
`ant install`
2010-08-31 06:57:07 +08:00
end
def start_emulator
puts "No devices attached. Starting emulator w/ first avd...\n"
$stdout.sync = true
avd = first_avd
if (avd.nil? || avd == "")
puts "No Android Virtual Device (AVD) could be found. Please create one with the Android SDK."
return
end
IO.popen("emulator -avd #{ avd } -logcat all") do |f|
2010-08-31 06:57:07 +08:00
until f.eof?
puts f.gets
if f.gets.include? 'Boot is finished'
#IO.popen("cd #{ @pkg.path }; ant install;") do |f|
# puts f.gets
#end
puts "\n\nEMULATOR IS NOW RUNNING!\n\n"
puts "install your app by running: "
puts "cd #{ @pkg.path }; ant install;"
end
end
end
end
# helpers
def first_device
fd = `adb devices`.split("\n").pop()
if fd == 'List of devices attached '
nil
else
fd.gsub('device','')
end
end
def first_avd
`android list avd | grep "Name: "`.gsub('Name: ','').strip
end
#
end