Class: Screengrab::DependencyChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/screengrab/dependency_checker.rb

Class Method Summary collapse

Class Method Details

.check(android_env) ⇒ Object



3
4
5
6
7
8
# File 'lib/screengrab/dependency_checker.rb', line 3

def self.check(android_env)
  return if Helper.test?

  check_adb(android_env)
  check_aapt(android_env)
end

.check_aapt(android_env) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/screengrab/dependency_checker.rb', line 31

def self.check_aapt(android_env)
  android_home = android_env.android_home
  aapt_path = android_env.aapt_path

  warn_if_command_path_not_relative_to_android_home('aapt', android_home, aapt_path)
  # aapt is not required in order to function, so we'll only warn if we can't find it.
  warn_missing_aapt(android_home) unless aapt_path
end

.check_adb(android_env) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/screengrab/dependency_checker.rb', line 10

def self.check_adb(android_env)
  android_home = android_env.android_home
  adb_path = android_env.adb_path

  warn_if_command_path_not_relative_to_android_home('adb', android_home, adb_path)
  # adb is required to function, so we'll quit noisily if we couldn't find it
  raise_missing_adb(android_home) unless adb_path
end

.raise_missing_adb(android_home) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/screengrab/dependency_checker.rb', line 19

def self.raise_missing_adb(android_home)
  if android_home
    UI.error "The `adb` command could not be found relative to your provided ANDROID_HOME at #{android_home}"
    UI.error "Please ensure that the Android SDK is installed and the platform-tools directory is present"
  else
    UI.error 'The `adb` command could not be found on your PATH'
    UI.error 'Please ensure that the Android SDK is installed and the platform-tools directory is present and on your PATH'
  end

  UI.user_error!('adb command not found')
end

.warn_if_command_path_not_relative_to_android_home(cmd_name, android_home, cmd_path) ⇒ Object



50
51
52
53
54
# File 'lib/screengrab/dependency_checker.rb', line 50

def self.warn_if_command_path_not_relative_to_android_home(cmd_name, android_home, cmd_path)
  if android_home && cmd_path && !cmd_path.start_with?(android_home)
    UI.important "Using `#{cmd_name}` found at #{cmd_path} which is not within the specified ANDROID_HOME at #{android_home}"
  end
end

.warn_missing_aapt(android_home) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/screengrab/dependency_checker.rb', line 40

def self.warn_missing_aapt(android_home)
  if android_home
    UI.important "The `aapt` command could not be found relative to your provided ANDROID_HOME at #{android_home}"
    UI.important "Please ensure that the Android SDK is installed and you have the build tools downloaded"
  else
    UI.important "The `aapt` command could not be found on your PATH"
    UI.important "Please ensure that the Android SDK is installed and you have the build tools downloaded and present on your PATH"
  end
end