dryrun 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff3c2fe1c435df6056a21d91b2fb81b4119a05c
4
- data.tar.gz: 05e3055bec7c209db52797450c2001fd7166c054
3
+ metadata.gz: bc56acb0b83a79cdaf4d2598da0ebf3dc811f0b4
4
+ data.tar.gz: 4a2b2a5015b0481e000f7f0b69cc3118d8afe979
5
5
  SHA512:
6
- metadata.gz: 7f1de2e292dd0ff8c0eaa9f91ad884bb8e871d41309141db289b9635ebbc999514d72bb9a1035457a6fdddc4a4808a72be848196ee0fa238285abe07782dedb5
7
- data.tar.gz: 6851dfe5e5eb1e51788b3c1ce966439437890edcf56131c4535b5976c351cc1741b783646920eab6f129c29b38281b01e0ba97731b99a802933218ce3b3d78d3
6
+ metadata.gz: fa2148852009d390dedca1ce5d17f835ed288c9441a39abf99cea0f6318b55bffa2a40868b56055d31189d31574640daa3bece41cca92cd63afb1e71f4eb63b9
7
+ data.tar.gz: f4d4a20fd672de76f584b7dd7a08847e5594f4cb55569cc95bb11d1a5d42ae08c67eb50a627ba3faa1711d808e9aaf430519671021069f6233ae6f5192544621
data/lib/dryrun.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'adb-sdklib'
2
1
  require 'optparse'
3
2
  require 'colorize'
4
3
  require 'tmpdir'
@@ -8,13 +7,15 @@ require 'dryrun/version'
8
7
  require 'dryrun/android_project'
9
8
  require "highline/import"
10
9
  require 'openssl'
10
+ require 'open3'
11
+ require_relative 'dryrun/device'
11
12
 
12
13
  module Dryrun
13
14
  class MainApp
14
15
  def initialize(arguments)
15
-
16
+
16
17
  outdated_verification
17
-
18
+
18
19
  @url = ['-h', '--help', '-v', '--version'].include?(arguments.first) ? nil : arguments.shift
19
20
 
20
21
  # defaults
@@ -23,6 +24,7 @@ module Dryrun
23
24
  @flavour = ''
24
25
  @tag = nil
25
26
  @branch = "master"
27
+ @devices = Array.new
26
28
 
27
29
  # Parse Options
28
30
  arguments.push "-h" unless @url
@@ -92,77 +94,104 @@ module Dryrun
92
94
 
93
95
  def pick_device()
94
96
  if !Gem.win_platform?
95
- sdk = `echo $ANDROID_HOME`.gsub("\n",'')
96
- sdk = sdk + "/platform-tools/adb";
97
+ @@sdk = `echo $ANDROID_HOME`.gsub("\n",'')
98
+ @@sdk = @@sdk + "/platform-tools/adb";
97
99
  else
98
- sdk = `echo %ANDROID_HOME%`.gsub("\n",'')
99
- sdk = sdk + "/platform-tools/adb.exe"
100
+ @@sdk = `echo %ANDROID_HOME%`.gsub("\n",'')
101
+ @@sdk = @@sdk + "/platform-tools/adb.exe"
100
102
  end
101
103
 
102
104
  puts "Searching for devices...".yellow
103
- adb = AdbSdkLib::Adb.new(sdk)
104
- devices = adb.devices;
105
105
 
106
- if devices.empty?
106
+ run_adb("devices")
107
+
108
+ if @devices.empty?
107
109
  puts "No devices attached, but I'll run anyway"
108
110
  end
109
111
 
110
- @device = nil
112
+ @@device = nil
111
113
 
112
- if devices.size >= 2
114
+ if @devices.size >= 2
113
115
  puts "Pick your device (1,2,3...):"
114
116
 
115
- devices.each_with_index.map {|key, index| puts "#{index.to_s.green} - #{key} \n"}
117
+ @devices.each_with_index.map {|key, index| puts "#{index.to_s.green} - #{key.name} \n"}
116
118
 
117
119
  a = gets.chomp
118
120
 
119
- if a.match(/^\d+$/) && a.to_i <= (devices.length - 1) && a.to_i >= 0
120
- @device = devices.to_a.at((a.to_i))[1]
121
+ if a.match(/^\d+$/) && a.to_i <= (@devices.length - 1) && a.to_i >= 0
122
+ @@device = @devices[(a.to_i)]
121
123
  else
122
- @device = devices.first
124
+ @@device = @devices.first
123
125
  end
124
126
  else
125
- @device = devices.first
127
+ @@device = @devices.first
126
128
  end
127
129
 
128
- puts "Picked #{@device.to_s.green}" if @device
130
+ puts "Picked #{@@device.name.to_s.green}" if @@device != nil
129
131
  end
130
132
 
133
+ def run_adb(args, adb_opts = {}, &block) # :yields: stdout
134
+ path = "#{@@sdk} #{args}"
135
+ last_command = path
136
+ run(path, &block)
137
+ end
131
138
 
132
- def android_home_is_defined
133
- if !Gem.win_platform?
134
- sdk = `echo $ANDROID_HOME`.gsub("\n",'')
135
- else
136
- sdk = `echo %ANDROID_HOME%`.gsub("\n",'')
139
+ def run(path, &block)
140
+ @last_command = path
141
+ Open3.popen3(path) do |stdin, stdout, stderr, wait_thr|
142
+ stdout.each do |line|
143
+ line = line.strip
144
+ if (!line.empty? && line !~ /^List of devices/)
145
+ parts = line.split
146
+ device = AdbDevice::Device.new(parts[0], parts[1])
147
+ @devices << device
148
+ end
137
149
  end
138
- !sdk.empty?
139
150
  end
151
+ end
140
152
 
141
- def call
142
- unless android_home_is_defined
143
- puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n"
144
- puts "\nhint: in your #{'~/.bashrc'.yellow} or #{'~/.bash_profile'.yellow} add:\n #{"export ANDROID_HOME=\"/Users/cesarferreira/Library/Android/sdk/\"".yellow}"
145
- puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n"
146
- exit 1
147
- end
153
+ def self.getSDK # :yields: stdout
154
+ @@sdk
155
+ end
148
156
 
149
- @url = @url.split("?").first
150
- @url.chop! if @url.end_with? '/'
157
+ def self.getDevice # :yields: stdout
158
+ @@device
159
+ end
151
160
 
161
+ def android_home_is_defined
162
+ if !Gem.win_platform?
163
+ sdk = `echo $ANDROID_HOME`.gsub("\n",'')
164
+ else
165
+ sdk = `echo %ANDROID_HOME%`.gsub("\n",'')
166
+ end
167
+ !sdk.empty?
168
+ end
152
169
 
153
- pick_device()
170
+ def call
171
+ unless android_home_is_defined
172
+ puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n"
173
+ puts "\nhint: in your #{'~/.bashrc'.yellow} or #{'~/.bash_profile'.yellow} add:\n #{"export ANDROID_HOME=\"/Users/cesarferreira/Library/Android/sdk/\"".yellow}"
174
+ puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n"
175
+ exit 1
176
+ end
154
177
 
155
- github = Github.new(@url)
178
+ @url = @url.split("?").first
179
+ @url.chop! if @url.end_with? '/'
156
180
 
157
- unless github.is_valid
158
- puts "#{@url.red} is not a valid git @url"
159
- exit 1
160
- end
181
+
182
+ pick_device()
183
+
184
+ github = Github.new(@url)
185
+
186
+ unless github.is_valid
187
+ puts "#{@url.red} is not a valid git @url"
188
+ exit 1
189
+ end
161
190
 
162
191
  # clone the repository
163
192
  repository_path = github.clone(@branch, @tag)
164
193
 
165
- android_project = AndroidProject.new(repository_path, @app_path, @custom_module, @flavour, @device)
194
+ android_project = AndroidProject.new(repository_path, @app_path, @custom_module, @flavour)
166
195
 
167
196
  # is a valid android project?
168
197
  unless android_project.is_valid
@@ -7,13 +7,12 @@ require_relative 'dryrun_utils'
7
7
 
8
8
  module Dryrun
9
9
  class AndroidProject
10
- def initialize(path, custom_app_path, custom_module, flavour, device)
10
+ def initialize(path, custom_app_path, custom_module, flavour)
11
11
 
12
12
  @custom_app_path = custom_app_path
13
13
  @custom_module = custom_module
14
14
  @base_path = @custom_app_path? File.join(path, @custom_app_path) : path
15
15
  @flavour = flavour
16
- @device = device
17
16
 
18
17
  @settings_gradle_path = settings_gradle_file
19
18
  @main_gradle_file = main_gradle_file
@@ -125,7 +124,7 @@ module Dryrun
125
124
  puts "Installing #{@package.green}...\n"
126
125
  puts "executing: #{execute_line.green}\n"
127
126
 
128
- @device.shell("#{execute_line}")
127
+ DryrunUtils.run_adb("shell #{execute_line}")
129
128
  end
130
129
 
131
130
  def is_gradle_wrapped
@@ -155,11 +154,11 @@ module Dryrun
155
154
  end
156
155
 
157
156
  def clear_app_data
158
- @device.shell("pm clear #{@package}")
157
+ DryrunUtils.run_adb("shell pm clear #{@package}")
159
158
  end
160
159
 
161
160
  def uninstall_application
162
- @device.shell("pm uninstall #{@package}")
161
+ DryrunUtils.run_adb("shell pm uninstall #{@package}")
163
162
  end
164
163
 
165
164
  def get_execution_line_command(path_to_sample)
@@ -0,0 +1,11 @@
1
+ module AdbDevice
2
+ class Device
3
+ attr_accessor :name, :id
4
+
5
+ def initialize(name, id)
6
+ @name = name
7
+ @id = id
8
+ end
9
+ end
10
+ end
11
+
@@ -1,40 +1,55 @@
1
1
  require 'open-uri'
2
2
  require 'dryrun/version'
3
+ require 'open3'
3
4
 
4
5
  module Dryrun
5
6
  class DryrunUtils
6
7
 
7
8
  def self.execute(command)
8
9
  is_success = system command
9
- unless is_success
10
- puts "\n\n======================================================\n\n"
11
- puts " Something went wrong while executing this:".red
12
- puts " $ #{command}\n".yellow
13
- puts "======================================================\n\n"
14
- exit 1
15
- end
10
+ unless is_success
11
+ puts "\n\n======================================================\n\n"
12
+ puts " Something went wrong while executing this:".red
13
+ puts " $ #{command}\n".yellow
14
+ puts "======================================================\n\n"
15
+ exit 1
16
+ end
16
17
  end
17
18
 
18
19
  def self.get_latest_version
19
- url = 'https://raw.githubusercontent.com/cesarferreira/dryrun/master/lib/dryrun/version.rb'
20
- page_string = nil
20
+ url = 'https://raw.githubusercontent.com/cesarferreira/dryrun/master/lib/dryrun/version.rb'
21
+ page_string = nil
21
22
 
22
- if Gem.win_platform?
23
+ if Gem.win_platform?
23
24
  open(url, {ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}) do |f|
24
- page_string = f.read
25
- end
25
+ page_string = f.read
26
+ end
26
27
  else
27
28
  open(url) do |f|
28
- page_string = f.read
29
- end
30
- end
29
+ page_string = f.read
30
+ end
31
+ end
31
32
 
32
- page_string[/#{Regexp.escape('\'')}(.*?)#{Regexp.escape('\'')}/m, 1]
33
+ page_string[/#{Regexp.escape('\'')}(.*?)#{Regexp.escape('\'')}/m, 1]
33
34
  end
34
35
 
35
36
  def self.is_up_to_date
36
- latest = get_latest_version
37
- latest.to_s <= Dryrun::VERSION.to_s
37
+ latest = get_latest_version
38
+ latest.to_s <= Dryrun::VERSION.to_s
39
+ end
40
+
41
+ def self.run_adb(args, adb_opts = {}, &block) # :yields: stdout
42
+ adb_arg = ""
43
+ adb_arg += " -s #{Dryrun::MainApp.getDevice.name}"
44
+ path = "#{Dryrun::MainApp.getSDK} #{adb_arg} #{args} "
45
+ last_command = path
46
+ run(path, &block)
47
+ end
48
+
49
+ def self.run(path, &block)
50
+ @last_command = path
51
+ Open3.popen3(path) do |stdin, stdout, stderr, wait_thr|
52
+ end
38
53
  end
39
54
  end
40
55
  end
@@ -1,3 +1,3 @@
1
1
  module Dryrun
2
- VERSION = '0.7.8'
2
+ VERSION = '0.7.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dryrun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - cesar ferreira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-17 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -162,6 +162,7 @@ files:
162
162
  - extras/usage_v4.gif
163
163
  - lib/dryrun.rb
164
164
  - lib/dryrun/android_project.rb
165
+ - lib/dryrun/device.rb
165
166
  - lib/dryrun/dryrun_utils.rb
166
167
  - lib/dryrun/github.rb
167
168
  - lib/dryrun/version.rb