android-sdk-installer 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/android-sdk-installer.rb +52 -26
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f656e032c4d07ee26c4e5ef56c28b6652c93d36e
4
- data.tar.gz: a3e55863486002d1fd308b0208dfbacc68c2b892
3
+ metadata.gz: 1f5d87a5a604492d69f91929b62b0503dc607ca7
4
+ data.tar.gz: 4cca1af8013343f49bf9ed8609cbf442972abc98
5
5
  SHA512:
6
- metadata.gz: 5ba1729a3f71db078bb106f9b87dfd12d707d7f193f8e16d723aa174bfaf3fadc1ef5b3f4b91852f560e21d437da3eaacfbd779b0b3080cad7b4888ee18c2758
7
- data.tar.gz: 34beb0fd5e6b7a41f91805449f054d367853d72c968e13e3aae1b802995267aa3c4bc1201c775ad10393c757148c923b6e604c0d2af1372dac391a9436528776
6
+ metadata.gz: 32d95334a68b81625f7ae32a054ab8bf1cc914cd4b1bfca2b198f237fbef324f012ec3bd3e202f19fc8b1fb9b87f81cb50de887e10096c74731cb53118724aed
7
+ data.tar.gz: 3151b64ea06f0572bc918789d779bddfe91459063de320fd218850c7e34148ad0cf57076929f5d8e38a1a95a96f7e2fa15ef4842085bfbcf29b40fb219d18608
@@ -1,4 +1,4 @@
1
- require 'yaml'
1
+ require 'psych'
2
2
  require 'logger'
3
3
 
4
4
  module AndroidInstaller
@@ -6,23 +6,42 @@ module AndroidInstaller
6
6
  # noinspection RubyClassVariableUsageInspection
7
7
  class Installer
8
8
 
9
+ KEY_SDK_TOOLS = '{ANDROID_SDK_TOOLS}'
10
+ KEY_PLATFORM = '{PLATFORM}'
11
+ SDK_URL = 'https://dl.google.com'
12
+ SDK_PATH = '/android/repository/sdk-tools-' + KEY_PLATFORM + '-' + KEY_SDK_TOOLS + '.zip'
13
+ CONFIG_FILE = 'android-sdk-installer.yml'
14
+
9
15
  def initialize
10
16
  @@logger = Logger.new(STDOUT)
11
17
  @@logger.level = Logger::WARN
12
18
  end
13
19
 
20
+ def install_command_line_sdk(platform, version)
21
+ sdk_path = SDK_PATH
22
+ sdk_path[KEY_SDK_TOOLS] = version
23
+ sdk_path[KEY_PLATFORM] = platform
24
+ url = SDK_URL + sdk_path
25
+ @@logger.debug('Downloading version ' + version + ' for platform ' + platform + ' with url ' + url)
26
+ `wget --quiet --output-document=android-sdk.zip #{url}`
27
+ # TODO: error out here if file not found
28
+ unless File.file?('android-sdk.zip')
29
+ puts "\nAndroid SDK not found at url #{url}. Make sure you have the right values in your #{CONFIG_FILE}\n"
30
+ exit(1)
31
+ end
32
+ @@logger.debug('Unzipping android-sdk.zip')
33
+ `unzip -q android-sdk.zip -d $PWD/android-sdk`
34
+ `rm android-sdk.zip`
35
+ `export ANDROID_HOME=$PWD/android-sdk`
36
+ end
37
+
14
38
  def install
15
- # Why is it formatted like this?
16
- key_sdk_tools = '{ANDROID_SDK_TOOLS}'
17
- key_platform = '{PLATFORM}'
18
- sdk_url = 'https://dl.google.com'
19
- sdk_path = '/android/repository/sdk-tools-' + key_platform + '-' + key_sdk_tools + '.zip'
20
39
  # Validation
21
- unless File.file?('android-sdk-installer.yml')
22
- puts "\nNo config file found. You need a file called `android-sdk-installer.yml` with the configuration. See the README for details\n\n"
23
- exit(1)
40
+ if File.file?('android-sdk.zip')
41
+ config = Psych.load_file CONFIG_FILE
42
+ else
43
+ config = Psych.load("foo: true\nbar: false")
24
44
  end
25
- config = YAML.load_file('android-sdk-installer.yml')
26
45
  version = '3859397'
27
46
  if config.has_key?('version')
28
47
  version = config['version']
@@ -36,23 +55,30 @@ module AndroidInstaller
36
55
  if config.has_key?('platform')
37
56
  platform = config['platform']
38
57
  end
39
- sdk_path[key_sdk_tools] = version
40
- sdk_path[key_platform] = platform
41
- @@logger.debug('Downloading version ' + version + ' for platform ' + platform + ' with url ' + sdk_url + sdk_path)
42
- `wget --quiet --output-document=android-sdk.zip #{sdk_url + sdk_path}`
43
- # TODO: error out here if file not found
44
- @@logger.debug('Unzipping android-sdk.zip')
45
- `unzip -q android-sdk.zip -d $PWD/android-sdk`
46
- `rm android-sdk.zip`
47
- `export ANDROID_HOME=$PWD/android-sdk`
58
+
59
+ ignore_existing = false
60
+ if config.has_key?('ignore_existing')
61
+ ignore_existing = config['ignore_existing']
62
+ @@logger.debug("Ignore existing set to #{ignore_existing}")
63
+ end
64
+
65
+ should_install = ENV['ANDROID_HOME'].nil? || ignore_existing
66
+ if should_install
67
+ install_command_line_sdk(platform, version)
68
+ else
69
+ @@logger.debug('ANDROID_HOME already set. Skipping command line tools install')
70
+ end
71
+
48
72
  components = config['components']
49
- components.each do |component|
50
- @@logger.debug('Installing component ' + component)
51
- output = `echo y | $ANDROID_HOME/tools/bin/sdkmanager "#{component}"`
52
- @@logger.debug(output)
53
- if output.include? 'Warning'
54
- puts "\nError installing component " + component + "\n"
55
- puts output
73
+ if components != nil
74
+ components.each do |component|
75
+ @@logger.debug('Installing component ' + component)
76
+ output = `echo y | $ANDROID_HOME/tools/bin/sdkmanager "#{component}"`
77
+ @@logger.debug(output)
78
+ if output.include? 'Warning'
79
+ puts "\nError installing component " + component + "\n"
80
+ puts output
81
+ end
56
82
  end
57
83
  end
58
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: android-sdk-installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Commit 451