lib/ruboto/util/setup.rb in ruboto-1.0.3 vs lib/ruboto/util/setup.rb in ruboto-1.1.0
- old
+ new
@@ -5,10 +5,11 @@
module Util
module Setup
include Ruboto::Util::Verify
REPOSITORY_BASE = 'http://dl-ssl.google.com/android/repository'
REPOSITORY_URL = "#{REPOSITORY_BASE}/repository-8.xml"
+ SDK_DOWNLOAD_PAGE = 'http://developer.android.com/sdk/index.html?hl=sk'
RUBOTO_GEM_ROOT = File.expand_path '../../../..', __FILE__
WINDOWS_ELEVATE_CMD = "#{RUBOTO_GEM_ROOT}/bin/elevate_32.exe -c -w"
#########################################
@@ -122,10 +123,34 @@
version
end.compact.sort_by { |v| Gem::Version.new(v.gsub('_', '.')) }.last
version
end
+ def get_android_sdk_version
+ require 'net/http'
+ require 'uri'
+
+ # Get's the Page to Scrape
+ page_content = Net::HTTP.get(URI.parse(SDK_DOWNLOAD_PAGE))
+
+ case android_package_os_id
+ when MAC_OS_X
+ regex = '(\>android-sdk.*macosx.zip)'
+ when LINUX
+ regex = '(\>android-sdk.*.tgz)'
+ when WINDOWS
+ regex = '(\>installer_.*.exe)'
+ else #Error
+ nil
+ end
+
+ link = page_content.scan(/#{regex}/).to_s
+ version = link.match( /(\d+).(\d+).(\d+)/ )[0]
+
+ version
+ end
+
#########################################
#
# Check Methods
#
@@ -162,23 +187,21 @@
when MAC_OS_X
@haxm_kext_loc = '/System/Library/Extensions/intelhaxm.kext'
found = File.exists?(@haxm_kext_loc)
@haxm_kext_loc = nil unless found
puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? 'Found' : 'Not found')}"
- @haxm_installer_loc = File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHAXM.dmg')
- @haxm_installer_loc = nil unless File.exists?(@haxm_installer_loc)
+ @haxm_installer_loc = Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHAXM*.dmg')].first
when LINUX
@haxm_installer_loc = 'Not supported, yet.'
@haxm_kext_loc = 'Not supported, yet.'
return
when WINDOWS
@haxm_kext_loc = `sc query intelhaxm`
found = ($? == 0)
@haxm_kext_loc = nil unless found
puts "#{'%-25s' % 'Intel HAXM'}: #{(found ? 'Found' : 'Not found')}"
- @haxm_installer_loc = File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHaxm.exe')
- @haxm_installer_loc = nil unless File.exists?(@haxm_installer_loc)
+ @haxm_installer_loc = Dir[File.join(android_package_directory, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', 'IntelHaxm*.exe')].first
return
end
end
def check_for_platform_tools
@@ -262,11 +285,11 @@
if accept_all || a == 'Y' || a.empty?
puts "sudo #{installer} install -y #{package_name}"
`sudo #{installer} install -y #{package_name}`
else
puts
- puts 'You can install #{pretty_name} manually by:'
+ puts "You can install #{pretty_name} manually by:"
puts "sudo #{installer} install #{package_name}"
puts
end
else
puts "Package installer not found. You'll need to install #{pretty_name} manually."
@@ -449,16 +472,16 @@
end
if accept_all || a == 'Y' || a.empty?
Dir.chdir File.expand_path('~/') do
case android_package_os_id
when MAC_OS_X
- asdk_file_name = "android-sdk_r#{get_tools_version}-#{android_package_os_id}.zip"
+ asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.zip"
download(asdk_file_name)
unzip(accept_all, asdk_file_name)
FileUtils.rm_f asdk_file_name
when LINUX
- asdk_file_name = "android-sdk_r#{get_tools_version}-#{android_package_os_id}.tgz"
+ asdk_file_name = "android-sdk_r#{get_android_sdk_version}-#{android_package_os_id}.tgz"
download asdk_file_name
system "tar -xzf #{asdk_file_name}"
FileUtils.rm_f asdk_file_name
when WINDOWS
# FIXME(uwe): Detect and warn if we are not "elevated" with adminstrator rights.
@@ -467,11 +490,11 @@
#if %IS_ELEVATED%==0 (
# echo You must run the command prompt as administrator to install.
# exit /b 1
#)
- asdk_file_name = "installer_r#{get_tools_version}-#{android_package_os_id}.exe"
+ asdk_file_name = "installer_r#{get_android_sdk_version}-#{android_package_os_id}.exe"
download(asdk_file_name)
puts "Installing #{asdk_file_name}..."
system "#{WINDOWS_ELEVATE_CMD} #{asdk_file_name}"
raise "Unexpected exit code while installing the Android SDK: #{$?.exitstatus}" unless $? == 0
FileUtils.rm_f asdk_file_name
@@ -546,18 +569,17 @@
end
if accept_all || a == 'Y' || a.empty?
case android_package_os_id
when MAC_OS_X
system "hdiutil attach #{@haxm_installer_loc}"
- # FIXME(uwe): Detect volume
- # FIXME(uwe): Detect mpkg file with correct version.
- system 'sudo -S installer -pkg /Volumes/IntelHAXM_1.0.6/IntelHAXM_1.0.6.mpkg -target /'
+ fileName = Dir['/Volumes/IntelHAXM*/IntelHAXM*.mpkg'][0]
+ system "sudo -S installer -pkg #{fileName} -target /"
when LINUX
puts ' HAXM installation on Linux is not supported, yet.'
return
when WINDOWS
cmd = @haxm_installer_loc.gsub('/', "\\")
- puts "Running the HAXM installer"
+ puts 'Running the HAXM installer'
system %Q{#{WINDOWS_ELEVATE_CMD} "#{cmd}"}
raise "Unexpected return code: #{$?.exitstatus}" unless $? == 0
return
end
end