Class: Env
- Inherits:
-
Object
- Object
- Env
- Defined in:
- lib/calabash-android/env.rb
Class Method Summary collapse
- .adb_executable ⇒ Object
- .adb_path ⇒ Object
- .android_home_path ⇒ Object
- .android_platform_path ⇒ Object
- .ant_path ⇒ Object
- .exit_if_env_not_set_up ⇒ Object
- .exit_unless_android_sdk_is_available ⇒ Object
- .exit_unless_jdk_is_available ⇒ Object
- .find_executable_on_path(executable) ⇒ Object
- .is_windows? ⇒ Boolean
- .jarsigner_executable ⇒ Object
- .jarsigner_path ⇒ Object
- .java_executable ⇒ Object
- .java_path ⇒ Object
- .jdk_path ⇒ Object
- .keytool_executable ⇒ Object
- .keytool_path ⇒ Object
- .path_elements ⇒ Object
- .path_if_android_home(path) ⇒ Object
- .path_if_jdk(path) ⇒ Object
- .read_attribute_from_monodroid_config(element, attribute) ⇒ Object
- .read_registry(root_key, key, value) ⇒ Object
- .tools_dir ⇒ Object
- .zipalign_path ⇒ Object
Class Method Details
.adb_executable ⇒ Object
97 98 99 |
# File 'lib/calabash-android/env.rb', line 97 def self.adb_executable is_windows? ? 'adb.exe' : 'adb' end |
.adb_path ⇒ Object
117 118 119 |
# File 'lib/calabash-android/env.rb', line 117 def self.adb_path %Q("#{android_home_path}/platform-tools/#{adb_executable}") end |
.android_home_path ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/calabash-android/env.rb', line 59 def self.android_home_path path_if_android_home(ENV["ANDROID_HOME"]) || if is_windows? path_if_android_home(read_registry(::Win32::Registry::HKEY_LOCAL_MACHINE, 'SOFTWARE\\Android SDK Tools', 'Path')) || path_if_android_home("C:\\Android\\android-sdk") else path_if_android_home(read_attribute_from_monodroid_config('android-sdk', 'path')) end end |
.android_platform_path ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/calabash-android/env.rb', line 141 def self.android_platform_path Dir.chdir(android_home_path) do platforms = Dir["platforms/android-*"].sort_by { |item| '%08s' % item.split('-').last } raise "No Android SDK found in #{android_home_path}/platforms/" if platforms.empty? File.(platforms.last) end end |
.ant_path ⇒ Object
101 102 103 |
# File 'lib/calabash-android/env.rb', line 101 def self.ant_path is_windows? ? "ant.bat" : "ant" end |
.exit_if_env_not_set_up ⇒ Object
5 6 7 8 |
# File 'lib/calabash-android/env.rb', line 5 def self.exit_if_env_not_set_up exit_unless_jdk_is_available exit_unless_android_sdk_is_available end |
.exit_unless_android_sdk_is_available ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/calabash-android/env.rb', line 10 def self.exit_unless_android_sdk_is_available if android_home_path log "Android SDK found at: #{android_home_path}" return end puts "Could not find an Android SDK please make sure it is installed." puts "You can read about how Calabash-Android is searching for an Android SDK and how you can help here:" puts "https://github.com/calabash/calabash-android/blob/master/documentation/installation.md#prerequisites" exit 1 end |
.exit_unless_jdk_is_available ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/calabash-android/env.rb', line 26 def self.exit_unless_jdk_is_available jdk = jdk_path if find_executable_on_path(keytool_executable) || jdk log "JDK found on PATH." if find_executable_on_path(keytool_executable) log "JDK found at: #{jdk}" if jdk return end puts "Could not find Java Development Kit please make sure it is installed." puts "You can read about how Calabash-Android is searching for a JDK and how you can help here:" puts "https://github.com/calabash/calabash-android/blob/master/documentation/installation.md#prerequisites" exit 1 end |
.find_executable_on_path(executable) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/calabash-android/env.rb', line 69 def self.find_executable_on_path(executable) path_elements.each do |x| f = File.join(x, executable) return "\"#{f}\"" if File.exists?(f) end nil end |
.is_windows? ⇒ Boolean
105 106 107 |
# File 'lib/calabash-android/env.rb', line 105 def self.is_windows? (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) end |
.jarsigner_executable ⇒ Object
85 86 87 |
# File 'lib/calabash-android/env.rb', line 85 def self.jarsigner_executable is_windows? ? 'jarsigner.exe' : 'jarsigner' end |
.jarsigner_path ⇒ Object
39 40 41 42 |
# File 'lib/calabash-android/env.rb', line 39 def self.jarsigner_path find_executable_on_path(jarsigner_executable) || "\"#{jdk_path}/bin/#{jarsigner_executable}\"" end |
.java_executable ⇒ Object
89 90 91 |
# File 'lib/calabash-android/env.rb', line 89 def self.java_executable is_windows? ? 'java.exe' : 'java' end |
.java_path ⇒ Object
44 45 46 47 |
# File 'lib/calabash-android/env.rb', line 44 def self.java_path find_executable_on_path(java_executable) || "\"#{jdk_path}/bin/#{java_executable}\"" end |
.jdk_path ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/calabash-android/env.rb', line 49 def self.jdk_path path_if_jdk(ENV['JAVA_HOME']) || if is_windows? path_if_jdk(read_registry(::Win32::Registry::HKEY_LOCAL_MACHINE, 'SOFTWARE\\JavaSoft\\Java Development Kit\\1.7', 'JavaHome')) || path_if_jdk(read_registry(::Win32::Registry::HKEY_LOCAL_MACHINE, 'SOFTWARE\\JavaSoft\\Java Development Kit\\1.6', 'JavaHome')) else path_if_jdk(read_attribute_from_monodroid_config('java-sdk', 'path')) end end |
.keytool_executable ⇒ Object
93 94 95 |
# File 'lib/calabash-android/env.rb', line 93 def self.keytool_executable is_windows? ? 'keytool.exe' : 'keytool' end |
.keytool_path ⇒ Object
21 22 23 24 |
# File 'lib/calabash-android/env.rb', line 21 def self.keytool_path find_executable_on_path(keytool_executable) || "\"#{jdk_path}/bin/#{keytool_executable}\"" end |
.path_elements ⇒ Object
125 126 127 128 |
# File 'lib/calabash-android/env.rb', line 125 def self.path_elements return [] unless ENV['PATH'] ENV['PATH'].split (/[:;]/) end |
.path_if_android_home(path) ⇒ Object
121 122 123 |
# File 'lib/calabash-android/env.rb', line 121 def self.path_if_android_home(path) path if path && File.exists?(File.join(path, 'platform-tools', adb_executable)) end |
.path_if_jdk(path) ⇒ Object
77 78 79 |
# File 'lib/calabash-android/env.rb', line 77 def self.path_if_jdk(path) path if path && File.exists?(File.join(path, 'bin', jarsigner_executable)) end |
.read_attribute_from_monodroid_config(element, attribute) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/calabash-android/env.rb', line 130 def self.read_attribute_from_monodroid_config(element, attribute) monodroid_config_file = File.("~/.config/xbuild/monodroid-config.xml") if File.exists?(monodroid_config_file) require 'rexml/document' begin return REXML::Document.new(IO.read(monodroid_config_file)).elements["//#{element}"].attributes[attribute] rescue end end end |
.read_registry(root_key, key, value) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/calabash-android/env.rb', line 149 def self.read_registry(root_key, key, value) begin root_key.open(key)[value] rescue nil end end |
.tools_dir ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/calabash-android/env.rb', line 109 def self.tools_dir Dir.chdir(android_home_path) do dirs = Dir["build-tools/*"] + Dir["platform-tools"] raise "Could not find tools directory in #{android_home_path}" if dirs.empty? File.(dirs.first) end end |
.zipalign_path ⇒ Object
81 82 83 |
# File 'lib/calabash-android/env.rb', line 81 def self.zipalign_path %Q("#{android_home_path}/tools/zipalign") end |