dryrun 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +26 -0
- data/README.md +9 -7
- data/Rakefile +1 -1
- data/bin/dryrun +1 -1
- data/dryrun.gemspec +15 -17
- data/extras/logo.png +0 -0
- data/lib/dryrun.rb +83 -94
- data/lib/dryrun/android_project.rb +58 -54
- data/lib/dryrun/device.rb +1 -2
- data/lib/dryrun/dryrun_utils.rb +58 -50
- data/lib/dryrun/github.rb +34 -36
- data/lib/dryrun/version.rb +2 -2
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d6c17c4daa6f07ff66e42bbb93fee0f301e159e
|
4
|
+
data.tar.gz: 9a822a3cb7961d64e0127776a549cc5f503f2ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22ed812fc2e7bbb4bcb621915e0a64f550f899da8de52fdeab807c2ef111b37c5bdce6a0783b6a6219eb53935e8c320d310221ae5970a949bb2bb7da8819d519
|
7
|
+
data.tar.gz: 9606739e80de94d5bf619d30a8c57ed25d14fb821ec62c50a3c544eb91699fa8f908aee10ffc72ed451605f009336891b2e854365c265bbd1c10e84c3acac160
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Style/Encoding:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/MethodLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/PerceivedComplexity:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/AbcSize:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
AllCops:
|
23
|
+
TargetRubyVersion: 2.0
|
24
|
+
|
25
|
+
Documentation:
|
26
|
+
Enabled: false
|
data/README.md
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
![Image](extras/logo.png)
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/cesarferreira/dryrun.svg?branch=master)](https://travis-ci.org/cesarferreira/dryrun)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/dryrun.svg)](http://badge.fury.io/rb/dryrun)
|
5
|
+
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-dryrun-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2361)
|
6
|
+
[![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23200-blue.svg)](http://androidweekly.net/issues/issue-200)
|
4
7
|
|
5
8
|
|
6
|
-
|
7
|
-
[![Build Status](https://travis-ci.org/cesarferreira/dryrun.svg?branch=master)](https://travis-ci.org/cesarferreira/dryrun) [![Gem Version](https://badge.fury.io/rb/dryrun.svg)](http://badge.fury.io/rb/dryrun)
|
9
|
+
**Try** any **android library** hosted online **directly** from the **command line**
|
8
10
|
|
9
|
-
### Featured in
|
10
|
-
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-dryrun-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2361)
|
11
|
-
[![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23200-blue.svg)](http://androidweekly.net/issues/issue-200)
|
12
11
|
|
13
12
|
### Show some :heart:
|
14
|
-
[![GitHub stars](https://img.shields.io/github/stars/cesarferreira/dryrun.svg?style=social&label=Star)](https://github.com/cesarferreira/dryrun)
|
13
|
+
[![GitHub stars](https://img.shields.io/github/stars/cesarferreira/dryrun.svg?style=social&label=Star)](https://github.com/cesarferreira/dryrun)
|
14
|
+
[![GitHub forks](https://img.shields.io/github/forks/cesarferreira/dryrun.svg?style=social&label=Fork)](https://github.com/cesarferreira/dryrun/fork) [![GitHub watchers](https://img.shields.io/github/watchers/cesarferreira/dryrun.svg?style=social&label=Watch)](https://github.com/cesarferreira/dryrun) [![GitHub followers](https://img.shields.io/github/followers/cesarferreira.svg?style=social&label=Follow)](https://github.com/cesarferreira/dryrun)
|
15
15
|
[![Twitter Follow](https://img.shields.io/twitter/follow/cesarmcferreira.svg?style=social)](https://twitter.com/cesarmcferreira)
|
16
16
|
|
17
17
|
|
@@ -36,6 +36,8 @@ Options
|
|
36
36
|
-f, --flavour FLAVOUR Custom flavour (e.g. dev, qa, prod)
|
37
37
|
-p, --path PATH Custom path to android project
|
38
38
|
-t, --tag TAG Checkout tag/commit hash to clone (e.g. "v0.4.5", "6f7dd4b")
|
39
|
+
-c, --cleanup Clean the temporary folder before cloning the project
|
40
|
+
-w, --wipe Wipe the temporary dryrun folder
|
39
41
|
-h, --help Displays help
|
40
42
|
-v, --version Displays the version
|
41
43
|
```
|
data/Rakefile
CHANGED
data/bin/dryrun
CHANGED
data/dryrun.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
# coding: utf-8
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'dryrun/version'
|
5
5
|
|
6
|
-
#rake build # Build dryrun-0.0.1.gem into the pkg directory
|
7
|
-
#rake install # Build and install dryrun-0.0.1.gem into system gems
|
8
|
-
#rake release # Create tag v0.0.1 and build and push dryrun-0.0.1.gem t...
|
9
|
-
#rake spec # Run RSpec code examples
|
6
|
+
# rake build # Build dryrun-0.0.1.gem into the pkg directory
|
7
|
+
# rake install # Build and install dryrun-0.0.1.gem into system gems
|
8
|
+
# rake release # Create tag v0.0.1 and build and push dryrun-0.0.1.gem t...
|
9
|
+
# rake spec # Run RSpec code examples
|
10
10
|
|
11
11
|
Gem::Specification.new do |spec|
|
12
|
-
spec.name =
|
12
|
+
spec.name = 'dryrun'
|
13
13
|
spec.version = Dryrun::VERSION
|
14
|
-
spec.authors = [
|
15
|
-
spec.email = [
|
14
|
+
spec.authors = ['cesar ferreira']
|
15
|
+
spec.email = ['cesar.manuel.ferreira@gmail.com']
|
16
16
|
|
17
|
-
spec.summary =
|
18
|
-
spec.description =
|
19
|
-
spec.homepage =
|
17
|
+
spec.summary = 'Tool to try any android library hosted online directly from the command line'
|
18
|
+
spec.description = 'Tool to try any android library hosted online directly from the command line'
|
19
|
+
spec.homepage = 'https://github.com/cesarferreira/dryrun'
|
20
20
|
spec.license = 'MIT'
|
21
21
|
|
22
22
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
-
spec.bindir =
|
23
|
+
spec.bindir = 'bin'
|
24
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = [
|
25
|
+
spec.require_paths = ['lib']
|
26
26
|
|
27
27
|
spec.required_ruby_version = '>= 2.0.0'
|
28
28
|
|
@@ -31,10 +31,8 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'rspec'
|
32
32
|
|
33
33
|
spec.add_dependency 'bundler', '~> 1.7'
|
34
|
-
spec.add_dependency 'colorize',
|
35
|
-
spec.add_dependency 'oga',
|
34
|
+
spec.add_dependency 'colorize', '~> 0.7'
|
35
|
+
spec.add_dependency 'oga', '~> 1.3.1'
|
36
36
|
spec.add_dependency 'highline', '~> 1.7'
|
37
|
-
spec.add_dependency 'adb-sdklib', '~> 0.0.3'
|
38
37
|
spec.add_dependency 'rjb', '>= 1.5.4'
|
39
|
-
|
40
38
|
end
|
data/extras/logo.png
CHANGED
Binary file
|
data/lib/dryrun.rb
CHANGED
@@ -1,41 +1,40 @@
|
|
1
|
-
require '
|
2
|
-
require 'colorize'
|
1
|
+
require 'colorize'
|
3
2
|
require 'tmpdir'
|
4
3
|
require 'fileutils'
|
5
4
|
require 'dryrun/github'
|
6
5
|
require 'dryrun/version'
|
7
6
|
require 'dryrun/android_project'
|
8
|
-
require
|
7
|
+
require 'highline/import'
|
9
8
|
require 'openssl'
|
10
9
|
require 'open3'
|
11
10
|
require_relative 'dryrun/device'
|
11
|
+
require 'optparse'
|
12
12
|
|
13
13
|
module Dryrun
|
14
14
|
class MainApp
|
15
15
|
def initialize(arguments)
|
16
|
-
|
17
16
|
outdated_verification
|
18
17
|
|
19
|
-
@url =
|
18
|
+
@url = %w(-h --help -v --version -w --wipe).include?(arguments.first) ? nil : arguments.shift
|
20
19
|
|
21
20
|
# defaults
|
22
21
|
@app_path = nil
|
23
22
|
@custom_module = nil
|
24
23
|
@flavour = ''
|
25
24
|
@tag = nil
|
26
|
-
@branch =
|
27
|
-
@devices =
|
25
|
+
@branch = 'master'
|
26
|
+
@devices = []
|
27
|
+
@cleanup = false
|
28
28
|
|
29
29
|
# Parse Options
|
30
|
-
arguments.push "-h" unless @url
|
31
30
|
create_options_parser(arguments)
|
32
31
|
end
|
33
32
|
|
34
33
|
def create_options_parser(args)
|
35
34
|
args.options do |opts|
|
36
|
-
opts.banner =
|
35
|
+
opts.banner = 'Usage: dryrun GIT_URL [OPTIONS]'
|
37
36
|
opts.separator ''
|
38
|
-
opts.separator
|
37
|
+
opts.separator 'Options'
|
39
38
|
|
40
39
|
opts.on('-m MODULE_NAME', '--module MODULE_NAME', 'Custom module to run') do |custom_module|
|
41
40
|
@custom_module = custom_module
|
@@ -57,6 +56,14 @@ module Dryrun
|
|
57
56
|
@tag = tag
|
58
57
|
end
|
59
58
|
|
59
|
+
opts.on('-c', '--cleanup', 'Clean the temporary folder before cloning the project') do
|
60
|
+
@cleanup = true
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.on('-w', '--wipe', 'Wipe the temporary dryrun folder') do
|
64
|
+
wipe_temporary_folder
|
65
|
+
end
|
66
|
+
|
60
67
|
opts.on('-h', '--help', 'Displays help') do
|
61
68
|
puts opts.help
|
62
69
|
exit
|
@@ -68,133 +75,115 @@ module Dryrun
|
|
68
75
|
end
|
69
76
|
|
70
77
|
opts.parse!
|
71
|
-
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
75
81
|
def outdated_verification
|
76
|
-
|
77
|
-
|
78
|
-
if is_up_to_date
|
79
|
-
return
|
80
|
-
end
|
82
|
+
return if DryrunUtils.up_to_date
|
81
83
|
|
82
84
|
input = nil
|
83
85
|
|
84
86
|
begin
|
85
87
|
input = ask "\n#{'Your Dryrun version is outdated, want to update?'.yellow} #{'[Y/n]:'.white}"
|
86
|
-
end
|
87
|
-
|
88
|
-
if input.downcase.eql? 'y'
|
89
|
-
DryrunUtils.execute('gem update dryrun')
|
90
|
-
|
91
|
-
end
|
88
|
+
end until %w(y n s).include?(input.downcase)
|
92
89
|
|
90
|
+
DryrunUtils.execute('gem update dryrun') if input.casecmp 'y'
|
93
91
|
end
|
94
92
|
|
95
|
-
def pick_device
|
93
|
+
def pick_device
|
94
|
+
@device = nil
|
95
|
+
|
96
96
|
if !Gem.win_platform?
|
97
|
-
|
98
|
-
|
97
|
+
@sdk = `echo $ANDROID_HOME`.delete("\n")
|
98
|
+
@sdk += '/platform-tools/adb'
|
99
99
|
else
|
100
|
-
|
101
|
-
|
100
|
+
@sdk = `echo %ANDROID_HOME%`.delete("\n")
|
101
|
+
@sdk += '/platform-tools/adb.exe'
|
102
102
|
end
|
103
103
|
|
104
|
-
|
104
|
+
$sdk = @sdk
|
105
|
+
|
106
|
+
puts 'Searching for devices...'.yellow
|
105
107
|
|
106
|
-
run_adb(
|
108
|
+
@devices = DryrunUtils.run_adb('devices')
|
107
109
|
|
108
|
-
if @devices.empty?
|
109
|
-
puts
|
110
|
+
if @devices.nil? || @devices.empty?
|
111
|
+
puts 'Killing adb, there might be an issue with it...'
|
112
|
+
DryrunUtils.run_adb('kill-server')
|
113
|
+
@devices = DryrunUtils.run_adb('devices')
|
110
114
|
end
|
111
115
|
|
112
|
-
|
116
|
+
puts 'No devices attached, but I\'ll run anyway' if @devices.empty?
|
113
117
|
|
114
118
|
if @devices.size >= 2
|
115
|
-
puts
|
119
|
+
puts 'Pick your device (1,2,3...):'
|
116
120
|
|
117
|
-
@devices.each_with_index.map {|key, index| puts "#{index.to_s.green} - #{key.name} \n"}
|
121
|
+
@devices.each_with_index.map { |key, index| puts "#{index.to_s.green} - #{key.name} \n" }
|
118
122
|
|
119
|
-
|
123
|
+
input = gets.chomp
|
120
124
|
|
121
|
-
if
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
125
|
+
@device = if input.match(/^\d+$/) && input.to_i <= (@devices.length - 1) && input.to_i >= 0
|
126
|
+
@devices[input.to_i]
|
127
|
+
else
|
128
|
+
@devices.first
|
129
|
+
end
|
126
130
|
else
|
127
|
-
|
131
|
+
@device = @devices.first
|
128
132
|
end
|
129
133
|
|
130
|
-
|
134
|
+
$device = @device
|
135
|
+
puts "Picked #{@device.name.to_s.green}" unless @device.nil?
|
131
136
|
end
|
132
137
|
|
133
|
-
def
|
134
|
-
|
135
|
-
|
136
|
-
|
138
|
+
def android_home_is_defined
|
139
|
+
@sdk = if !Gem.win_platform?
|
140
|
+
`echo $ANDROID_HOME`.delete('\n')
|
141
|
+
else
|
142
|
+
`echo %ANDROID_HOME%`.delete('\n')
|
143
|
+
end
|
144
|
+
!@sdk.empty?
|
137
145
|
end
|
138
146
|
|
139
|
-
def
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.getSDK # :yields: stdout
|
154
|
-
@@sdk
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.getDevice # :yields: stdout
|
158
|
-
@@device
|
159
|
-
end
|
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
|
169
|
-
|
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"
|
147
|
+
def wipe_temporary_folder
|
148
|
+
tmpdir = Dir.tmpdir + '/dryrun/'
|
149
|
+
puts 'Wiping ' + tmpdir.red
|
150
|
+
FileUtils.rm_rf tmpdir
|
151
|
+
puts 'Folder totally removed!'.green
|
175
152
|
exit 1
|
176
153
|
end
|
177
154
|
|
178
|
-
|
179
|
-
|
155
|
+
def call
|
156
|
+
unless android_home_is_defined
|
157
|
+
puts "\nWARNING: your #{'$ANDROID_HOME'.yellow} is not defined\n"
|
158
|
+
puts "\nhint: in your #{'~/.bashrc'.yellow} or #{'~/.bash_profile'.yellow} add:\n #{"export ANDROID_HOME='/Users/cesarferreira/Library/Android/sdk/'".yellow}"
|
159
|
+
puts "\nNow type #{'source ~/.bashrc'.yellow}\n\n"
|
160
|
+
exit 1
|
161
|
+
end
|
180
162
|
|
163
|
+
if @url.nil?
|
164
|
+
puts 'You need to insert a valid GIT URL'
|
165
|
+
exit 1
|
166
|
+
end
|
181
167
|
|
182
|
-
|
168
|
+
@url = @url.split('?').first
|
169
|
+
@url.chop! if @url.end_with? '/'
|
183
170
|
|
184
|
-
|
171
|
+
pick_device
|
185
172
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
173
|
+
github = Github.new(@url)
|
174
|
+
|
175
|
+
unless github.valid?
|
176
|
+
puts "#{@url.red} is not a valid git @url"
|
177
|
+
exit 1
|
178
|
+
end
|
190
179
|
|
191
180
|
# clone the repository
|
192
|
-
repository_path = github.clone(@branch, @tag)
|
181
|
+
repository_path = github.clone(@branch, @tag, @cleanup)
|
193
182
|
|
194
|
-
android_project = AndroidProject.new(repository_path, @app_path, @custom_module, @flavour)
|
183
|
+
android_project = AndroidProject.new(repository_path, @app_path, @custom_module, @flavour, @device)
|
195
184
|
|
196
185
|
# is a valid android project?
|
197
|
-
unless android_project.
|
186
|
+
unless android_project.valid?
|
198
187
|
puts "#{@url.red} is not a valid android project"
|
199
188
|
exit 1
|
200
189
|
end
|
@@ -205,7 +194,7 @@ module Dryrun
|
|
205
194
|
# clean and install the apk
|
206
195
|
android_project.install
|
207
196
|
|
208
|
-
puts "\n> If you want to remove the app you just installed, execute:\n#{android_project.
|
197
|
+
puts "\n> If you want to remove the app you just installed, execute:\n#{android_project.uninstall_command.yellow}\n\n"
|
209
198
|
end
|
210
199
|
end
|
211
200
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'oga'
|
1
|
+
require 'oga'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'tempfile'
|
5
4
|
require 'find'
|
@@ -7,12 +6,12 @@ require_relative 'dryrun_utils'
|
|
7
6
|
|
8
7
|
module Dryrun
|
9
8
|
class AndroidProject
|
10
|
-
def initialize(path, custom_app_path, custom_module, flavour)
|
11
|
-
|
9
|
+
def initialize(path, custom_app_path, custom_module, flavour, device)
|
12
10
|
@custom_app_path = custom_app_path
|
13
11
|
@custom_module = custom_module
|
14
|
-
@base_path = @custom_app_path? File.join(path, @custom_app_path) : path
|
12
|
+
@base_path = @custom_app_path ? File.join(path, @custom_app_path) : path
|
15
13
|
@flavour = flavour
|
14
|
+
@device = device
|
16
15
|
|
17
16
|
@settings_gradle_path = settings_gradle_file
|
18
17
|
@main_gradle_file = main_gradle_file
|
@@ -28,7 +27,7 @@ module Dryrun
|
|
28
27
|
full_custom_path = @base_path
|
29
28
|
settings_path = settings_gradle_file(full_custom_path)
|
30
29
|
main_gradle_path = main_gradle_file(full_custom_path)
|
31
|
-
return unless
|
30
|
+
return unless valid?(main_gradle_path)
|
32
31
|
|
33
32
|
@settings_gradle_path = settings_path
|
34
33
|
@main_gradle_file = main_gradle_file
|
@@ -41,20 +40,19 @@ module Dryrun
|
|
41
40
|
file_name = 'local.properties'
|
42
41
|
|
43
42
|
File.delete(file_name) if File.exist?(file_name)
|
44
|
-
|
45
|
-
|
46
|
-
end
|
43
|
+
|
44
|
+
DryrunUtils.execute("touch #{file_name}") unless Gem.win_platform?
|
47
45
|
end
|
48
46
|
|
49
47
|
def remove_application_id
|
50
48
|
# Open temporary file
|
51
|
-
tmp = Tempfile.new(
|
49
|
+
tmp = Tempfile.new('extract')
|
52
50
|
|
53
51
|
file = "#{@path_to_sample}/build.gradle"
|
54
52
|
|
55
53
|
# Write good lines to temporary file
|
56
|
-
File.open(file, 'r') do |
|
57
|
-
|
54
|
+
File.open(file, 'r') do |f|
|
55
|
+
f.each do |l| tmp << l unless l.include? 'applicationId'
|
58
56
|
end
|
59
57
|
end
|
60
58
|
tmp.close
|
@@ -71,16 +69,17 @@ module Dryrun
|
|
71
69
|
File.join(path, 'build.gradle')
|
72
70
|
end
|
73
71
|
|
74
|
-
def
|
75
|
-
File.exist?(main_gradle_file)
|
72
|
+
def valid?(main_gradle_file = @main_gradle_file)
|
73
|
+
File.exist?(main_gradle_file) &&
|
74
|
+
File.exist?(@settings_gradle_path)
|
76
75
|
end
|
77
76
|
|
78
77
|
def find_modules
|
79
|
-
return [] unless
|
78
|
+
return [] unless valid?
|
80
79
|
|
81
|
-
content = File.open(@settings_gradle_path,
|
80
|
+
content = File.open(@settings_gradle_path, 'rb').read
|
82
81
|
modules = content.scan(/'([^']*)'/)
|
83
|
-
modules.each {|replacement| replacement.first.
|
82
|
+
modules.each { |replacement| replacement.first.tr!(':', '/') }
|
84
83
|
end
|
85
84
|
|
86
85
|
def install
|
@@ -88,24 +87,24 @@ module Dryrun
|
|
88
87
|
|
89
88
|
path, execute_line = sample_project
|
90
89
|
|
91
|
-
if path == false
|
90
|
+
if path == false && execute_line == false
|
92
91
|
puts "Couldn't open the sample project, sorry!".red
|
93
92
|
exit 1
|
94
93
|
end
|
95
94
|
|
96
|
-
builder =
|
95
|
+
builder = 'gradle'
|
97
96
|
|
98
97
|
if File.exist?('gradlew')
|
99
98
|
if !Gem.win_platform?
|
100
99
|
DryrunUtils.execute('chmod +x gradlew')
|
101
100
|
else
|
102
|
-
DryrunUtils.execute(
|
101
|
+
DryrunUtils.execute('icacls gradlew /T')
|
103
102
|
end
|
104
103
|
builder = './gradlew'
|
105
104
|
end
|
106
105
|
|
107
106
|
# Generate the gradle/ folder
|
108
|
-
DryrunUtils.execute('gradle wrap') if File.exist?('gradlew')
|
107
|
+
DryrunUtils.execute('gradle wrap') if File.exist?('gradlew') && !gradle_wrapped?
|
109
108
|
|
110
109
|
remove_application_id
|
111
110
|
remove_local_properties
|
@@ -115,22 +114,31 @@ module Dryrun
|
|
115
114
|
DryrunUtils.execute("#{builder} :#{@custom_module}:install#{@flavour}Debug")
|
116
115
|
else
|
117
116
|
DryrunUtils.execute("#{builder} clean")
|
118
|
-
puts "#{builder} install#{@flavour}Debug"
|
119
|
-
DryrunUtils.execute("#{builder} install#{@flavour}Debug")
|
120
|
-
end
|
121
117
|
|
122
|
-
|
118
|
+
if @device.nil?
|
119
|
+
puts 'No devices picked/available, proceeding with assemble instead'.green
|
120
|
+
puts "#{builder} assemble#{@flavour}Debug"
|
121
|
+
DryrunUtils.execute("#{builder} assemble#{@flavour}Debug")
|
122
|
+
else
|
123
|
+
puts "#{builder} install#{@flavour}Debug"
|
124
|
+
DryrunUtils.execute("#{builder} install#{@flavour}Debug")
|
125
|
+
end
|
126
|
+
end
|
123
127
|
|
124
|
-
|
125
|
-
|
128
|
+
unless @device.nil?
|
129
|
+
clear_app_data
|
130
|
+
puts "Installing #{@package.green}...\n"
|
131
|
+
puts "executing: #{execute_line.green}\n"
|
126
132
|
|
127
|
-
|
133
|
+
DryrunUtils.run_adb("shell #{execute_line}")
|
134
|
+
end
|
128
135
|
end
|
129
136
|
|
130
|
-
def
|
131
|
-
return false
|
137
|
+
def gradle_wrapped?
|
138
|
+
return false unless File.directory?('gradle/')
|
132
139
|
|
133
|
-
File.exist?('gradle/wrapper/gradle-wrapper.properties')
|
140
|
+
File.exist?('gradle/wrapper/gradle-wrapper.properties') &&
|
141
|
+
File.exist?('gradle/wrapper/gradle-wrapper.jar')
|
134
142
|
end
|
135
143
|
|
136
144
|
def sample_project
|
@@ -149,37 +157,33 @@ module Dryrun
|
|
149
157
|
[false, false]
|
150
158
|
end
|
151
159
|
|
152
|
-
def
|
153
|
-
|
160
|
+
def uninstall_command
|
161
|
+
"adb uninstall \"#{@package}\""
|
154
162
|
end
|
155
163
|
|
156
164
|
def clear_app_data
|
157
|
-
|
165
|
+
DryrunUtils.run_adb("shell pm clear #{@package}")
|
158
166
|
end
|
159
167
|
|
160
168
|
def uninstall_application
|
161
|
-
|
169
|
+
DryrunUtils.run_adb("shell pm uninstall #{@package}")
|
162
170
|
end
|
163
171
|
|
164
172
|
def get_execution_line_command(path_to_sample)
|
165
173
|
manifest_file = get_manifest(path_to_sample)
|
166
174
|
|
167
|
-
if manifest_file.nil?
|
168
|
-
return false
|
169
|
-
end
|
175
|
+
return false if manifest_file.nil?
|
170
176
|
|
171
177
|
doc = Oga.parse_xml(manifest_file)
|
172
178
|
|
173
179
|
@package = get_package(doc)
|
174
180
|
@launcher_activity = get_launcher_activity(doc)
|
175
181
|
|
176
|
-
|
177
|
-
return false
|
178
|
-
end
|
182
|
+
return false unless @launcher_activity
|
179
183
|
|
180
184
|
manifest_file.close
|
181
185
|
|
182
|
-
|
186
|
+
"am start -n \"#{launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
|
183
187
|
end
|
184
188
|
|
185
189
|
def get_manifest(path_to_sample)
|
@@ -193,25 +197,25 @@ module Dryrun
|
|
193
197
|
end
|
194
198
|
end
|
195
199
|
|
196
|
-
def
|
197
|
-
full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}"
|
200
|
+
def launchable_activity
|
201
|
+
full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package, '')}"
|
198
202
|
"#{@package}/#{full_path_to_launcher}"
|
199
203
|
end
|
200
204
|
|
201
205
|
def get_package(doc)
|
202
|
-
|
203
|
-
|
206
|
+
doc.xpath('//manifest').attr('package').first.value
|
207
|
+
end
|
204
208
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
+
def get_launcher_activity(doc)
|
210
|
+
activities = doc.css('activity')
|
211
|
+
activities.each do |child|
|
212
|
+
intent_filter = child.css('intent-filter')
|
209
213
|
|
210
|
-
|
211
|
-
|
214
|
+
if !intent_filter.nil? && !intent_filter.empty?
|
215
|
+
return child.attr('android:name').value
|
216
|
+
end
|
212
217
|
end
|
218
|
+
false
|
213
219
|
end
|
214
|
-
false
|
215
220
|
end
|
216
221
|
end
|
217
|
-
end
|
data/lib/dryrun/device.rb
CHANGED
data/lib/dryrun/dryrun_utils.rb
CHANGED
@@ -1,55 +1,63 @@
|
|
1
|
-
require 'open-uri'
|
1
|
+
require 'open-uri'
|
2
2
|
require 'dryrun/version'
|
3
3
|
require 'open3'
|
4
4
|
|
5
5
|
module Dryrun
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
6
|
+
class DryrunUtils
|
7
|
+
attr_accessor :sdk
|
8
|
+
attr_accessor :device
|
9
|
+
|
10
|
+
def self.execute(command)
|
11
|
+
is_success = system command
|
12
|
+
unless is_success
|
13
|
+
puts "\n\n======================================================\n\n"
|
14
|
+
puts ' Something went wrong while executing this:'.red
|
15
|
+
puts " $ #{command}\n".yellow
|
16
|
+
puts "======================================================\n\n"
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.latest_version
|
22
|
+
url = 'https://raw.githubusercontent.com/cesarferreira/dryrun/master/lib/dryrun/version.rb'
|
23
|
+
page_string = nil
|
24
|
+
|
25
|
+
if Gem.win_platform?
|
26
|
+
open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |f|
|
27
|
+
page_string = f.read
|
28
|
+
end
|
29
|
+
else
|
30
|
+
open(url) do |f|
|
31
|
+
page_string = f.read
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
page_string[/#{Regexp.escape('\'')}(.*?)#{Regexp.escape('\'')}/m, 1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.up_to_date
|
39
|
+
latest = latest_version
|
40
|
+
latest.to_s <= Dryrun::VERSION.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.run_adb(args) # :yields: stdout
|
44
|
+
adb_arg = " -s #{$device.name} " unless $device.nil?
|
45
|
+
path = "#{$sdk} #{adb_arg} #{args} "
|
46
|
+
run(path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.run(path)
|
50
|
+
Open3.popen3(path) do |_stdin, stdout, _stderr|
|
51
|
+
devices = []
|
52
|
+
stdout.each do |line|
|
53
|
+
line = line.strip
|
54
|
+
if !line.empty? && line !~ /^List of devices/ && !line.start_with?('adb') && !line.start_with?('*')
|
55
|
+
parts = line.split
|
56
|
+
devices << AdbDevice::Device.new(parts[0], parts[1])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
devices
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
data/lib/dryrun/github.rb
CHANGED
@@ -1,89 +1,87 @@
|
|
1
|
-
require 'tmpdir'
|
1
|
+
require 'tmpdir'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'uri'
|
4
|
-
require_relative 'dryrun_utils'
|
5
4
|
require 'digest'
|
5
|
+
require_relative 'dryrun_utils'
|
6
6
|
|
7
7
|
module Dryrun
|
8
|
-
|
9
8
|
class Github
|
10
9
|
def initialize(url)
|
11
|
-
url = url.split(
|
10
|
+
url = url.split('?').first
|
12
11
|
url.chop! if url.end_with? '/'
|
13
12
|
|
14
13
|
@base_url = url
|
15
|
-
@destination =
|
14
|
+
@destination = destination
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
17
|
+
def destination
|
19
18
|
Digest::SHA256.hexdigest @base_url
|
20
19
|
end
|
21
20
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def valid?
|
22
|
+
starts_with_git = @base_url.split(//).first(4).join.eql? 'git@'
|
23
|
+
starts_with_http = @base_url.split(//).first(7).join.eql? 'http://'
|
24
|
+
starts_with_https = @base_url.split(//).first(8).join.eql? 'https://'
|
26
25
|
|
27
|
-
|
26
|
+
(starts_with_git || starts_with_https || starts_with_http)
|
28
27
|
end
|
29
28
|
|
30
29
|
def clonable_url
|
31
|
-
starts_with_git = @base_url.split(//).first(4).join.eql?
|
32
|
-
ends_with_git = @base_url.split(//).last(4).join.eql?
|
30
|
+
starts_with_git = @base_url.split(//).first(4).join.eql? 'git@'
|
31
|
+
ends_with_git = @base_url.split(//).last(4).join.eql? '.git'
|
33
32
|
|
34
33
|
# ends with git but doesnt start with git
|
35
|
-
if ends_with_git
|
36
|
-
return @base_url
|
37
|
-
end
|
34
|
+
return @base_url if ends_with_git && !starts_with_git
|
38
35
|
|
39
36
|
# ends with git but doesnt start with git
|
40
|
-
if !ends_with_git
|
41
|
-
return "#{@base_url}.git"
|
42
|
-
end
|
37
|
+
return "#{@base_url}.git" if !ends_with_git && !starts_with_git
|
43
38
|
|
44
39
|
@base_url
|
45
|
-
|
46
|
-
# end
|
47
40
|
end
|
48
41
|
|
49
42
|
##
|
50
43
|
## CLONE THE REPOSITORY
|
51
44
|
##
|
52
|
-
def clone(branch, tag)
|
53
|
-
clonable =
|
45
|
+
def clone(branch, tag, cleanup)
|
46
|
+
clonable = clonable_url
|
47
|
+
|
48
|
+
tmpdir = Dir.tmpdir + "/dryrun/#{@destination}"
|
49
|
+
|
50
|
+
if cleanup
|
51
|
+
puts 'Wiping the folder: ' + tmpdir.green
|
52
|
+
FileUtils.rm_rf tmpdir
|
53
|
+
# FileUtils.mkdir_p tmpdir
|
54
|
+
end
|
54
55
|
|
55
|
-
tmpdir = Dir.tmpdir+"/dryrun/#{@destination}"
|
56
56
|
folder_exists = File.directory?(tmpdir)
|
57
|
-
|
57
|
+
|
58
58
|
if folder_exists
|
59
59
|
Dir.chdir tmpdir
|
60
|
-
|
61
|
-
|
60
|
+
|
61
|
+
is_git_repo = system('git rev-parse')
|
62
|
+
|
62
63
|
if !is_git_repo
|
63
|
-
FileUtils.rm_rf(tmpdir)
|
64
|
-
DryrunUtils.execute("git clone --depth 1 #{clonable} #{tmpdir}")
|
64
|
+
FileUtils.rm_rf(tmpdir)
|
65
|
+
DryrunUtils.execute("git clone --depth 1 #{clonable} #{tmpdir}")
|
65
66
|
DryrunUtils.execute("git checkout #{branch}")
|
66
67
|
else
|
67
68
|
puts "Found project in #{tmpdir.green}..."
|
68
|
-
DryrunUtils.execute(
|
69
|
-
DryrunUtils.execute(
|
69
|
+
DryrunUtils.execute('git reset --hard HEAD')
|
70
|
+
DryrunUtils.execute('git fetch --all')
|
70
71
|
DryrunUtils.execute("git checkout #{branch}")
|
71
72
|
DryrunUtils.execute("git pull origin #{branch}")
|
72
73
|
end
|
73
|
-
|
74
74
|
else
|
75
|
-
DryrunUtils.execute("git clone --depth 1 #{clonable} #{tmpdir}")
|
75
|
+
DryrunUtils.execute("git clone --depth 1 #{clonable} #{tmpdir}")
|
76
76
|
end
|
77
77
|
|
78
78
|
if tag
|
79
79
|
Dir.chdir tmpdir
|
80
|
-
DryrunUtils.execute(
|
80
|
+
DryrunUtils.execute('git fetch --depth=10000')
|
81
81
|
DryrunUtils.execute("git checkout #{tag}")
|
82
82
|
end
|
83
83
|
|
84
84
|
tmpdir
|
85
85
|
end
|
86
|
-
|
87
86
|
end
|
88
|
-
|
89
87
|
end
|
data/lib/dryrun/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Dryrun
|
2
|
-
VERSION = '0.
|
1
|
+
module Dryrun
|
2
|
+
VERSION = '0.8.0'.freeze
|
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.
|
4
|
+
version: 0.8.0
|
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-
|
11
|
+
date: 2016-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.7'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: adb-sdklib
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.0.3
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.0.3
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rjb
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +133,7 @@ extra_rdoc_files: []
|
|
147
133
|
files:
|
148
134
|
- ".gitignore"
|
149
135
|
- ".rspec"
|
136
|
+
- ".rubocop.yml"
|
150
137
|
- ".travis.yml"
|
151
138
|
- Gemfile
|
152
139
|
- LICENSE
|
@@ -186,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
173
|
version: '0'
|
187
174
|
requirements: []
|
188
175
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.6.6
|
190
177
|
signing_key:
|
191
178
|
specification_version: 4
|
192
179
|
summary: Tool to try any android library hosted online directly from the command line
|