lib/ruboto/util/setup.rb in ruboto-1.0.1 vs lib/ruboto/util/setup.rb in ruboto-1.0.2

- old
+ new

@@ -30,11 +30,11 @@ def which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") - if File.executable? exe + if File.executable?(exe) and not File.directory?(exe) exe.gsub!('\\', '/') if windows? return exe end end end @@ -77,10 +77,20 @@ def android_package_directory return ENV['ANDROID_HOME'] if ENV['ANDROID_HOME'] File.join File.expand_path('~'), windows? ? 'AppData/Local/Android/android-sdk' : "android-sdk-#{android_package_os_id}" end + def package_installer + case android_package_os_id + when LINUX + which('apt-get') or which('yum') + else + ## Error + nil + end + end + def path_setup_file case android_package_os_id when MAC_OS_X '.profile' when LINUX @@ -101,20 +111,18 @@ doc = REXML::Document.new(open(REPOSITORY_URL)) version = doc.root.elements.to_a("sdk:#{type}/sdk:revision").map do |t| major = t.elements['sdk:major'] minor = t.elements['sdk:minor'] micro = t.elements['sdk:micro'] + prev = t.elements['sdk:preview'] + next if prev version = major.text version += ".#{minor.text}" if minor version += ".#{micro.text}" if micro + version += "_rc#{prev.text}" if prev version - end.sort_by { |v| Gem::Version.new(v) }.last - - # FIXME(uwe): Temporary fix for bug in build-tools 19.0.0 - return '18.1.1' if type == 'build-tool' && version == '19.0.0' - # EMXIF - + end.compact.sort_by { |v| Gem::Version.new(v.gsub('_', '.')) }.last version end ######################################### # @@ -239,14 +247,42 @@ end end check_all(api_levels) end + def install_package(accept_all, package_name, pretty_name) + case android_package_os_id + when LINUX + puts "#{pretty_name} was not found." + installer = package_installer + if installer + unless accept_all + print 'Would you like to and install it? (Y/n): ' + a = STDIN.gets.chomp.upcase + end + 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 "sudo #{installer} install #{package_name}" + puts + end + else + puts "Package installer not found. You'll need to install #{pretty_name} manually." + end + else + raise "Unknown host os for package install: #{RbConfig::CONFIG['host_os']}" + end + end + def install_java(accept_all) case android_package_os_id when MAC_OS_X when LINUX + install_package(accept_all, 'default-jdk', 'Default Java Development Kit') when WINDOWS # FIXME(uwe): Detect and warn if we are not "elevated" with adminstrator rights. #set IS_ELEVATED=0 #whoami /groups | findstr /b /c:"Mandatory Label\High Mandatory Level" | findstr /c:"Enabled group" > nul: && set IS_ELEVATED=1 #if %IS_ELEVATED%==0 ( @@ -298,9 +334,10 @@ def install_ant(accept_all) case android_package_os_id when MAC_OS_X when LINUX + install_package(accept_all, 'ant', 'Apache ANT') when WINDOWS # FIXME(uwe): Detect and warn if we are not "elevated" with adminstrator rights. #set IS_ELEVATED=0 #whoami /groups | findstr /b /c:"Mandatory Label\High Mandatory Level" | findstr /c:"Enabled group" > nul: && set IS_ELEVATED=1 #if %IS_ELEVATED%==0 (