dryrun 1.0.0 → 1.1.0

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: 4a8b8b33d462e6e7dc193f307ea700166bcc90c0
4
- data.tar.gz: ef5926a7a47f020ebeb7753de7483f1e6c3ad676
3
+ metadata.gz: 12d9fa58a5064dd85da72920ac21be5fcaa0906c
4
+ data.tar.gz: cc3f02008e17b792b1e637bf16377e47d4da7e22
5
5
  SHA512:
6
- metadata.gz: 42886f6dae79ad2810173c8bb1407a3f19b1918fab1b74a45ae12a79e9b88bf6d8039cba9d639346bd67c2c9aea7b190d2b061bde875c14767f21c222053a47f
7
- data.tar.gz: 7e443523c64f26248d19236038813510ad6c8af0b9cdddfa0028f4e9136ad200d6f9f2dab47ba1cc01bbc579c569953cd21c9b90a0741714ec56f867651bd2da
6
+ metadata.gz: 889183fa40425402bed0665325d5abc4aa7ee8c3741864c87e4c46637a82d5881f90c7868874fe5b0727b3f47c6860f35bd696518658e12d98f33026901fd397
7
+ data.tar.gz: 18739688e6362dc37467995c029eee686d7e43632f885526d24227d7663ec4e4c14d49924e48aba1a0f894ada9a4408b54ccc45f84bcc72441881936fe018b6a
data/README.md CHANGED
@@ -49,6 +49,7 @@ Options
49
49
  -w, --wipe Wipe the temporary dryrun folder
50
50
  -h, --help Displays help
51
51
  -v, --version Displays the version
52
+ -a, --android-test Execute android tests
52
53
  ```
53
54
 
54
55
  ## Alternative scenario (if you don't use `dryrun`)
@@ -80,7 +81,7 @@ Be aware that ANDROID_HOME needs to be set with the adb path:
80
81
  - MAC -> ```ANDROID_HOME=/usr/local/opt/android-sdk```
81
82
  - Linux -> ```ANDROID_HOME=/usr/local/opt/android-sdk```
82
83
  - Windows -> ```ANDROID_HOME="...sdk"```
83
- In windows this ANDROID_HOME is not automatically created, see more in [here](https://facebook.github.io/react-native/releases/0.21/docs/android-setup.html#define-the-android-home-environment-variable)
84
+ In windows this ANDROID_HOME is not automatically created, see more in [here](https://github.com/facebook/react-native/blob/0.24-stable/docs/DevelopmentSetupAndroid.md#define-the-android_home-environment-variable)
84
85
 
85
86
  Additionally, on windows in order to use git commands, the following path should be on the environment variable
86
87
  - ```...\Git\cmd ```
data/lib/dryrun.rb CHANGED
@@ -4,6 +4,8 @@ require 'fileutils'
4
4
  require 'dryrun/github'
5
5
  require 'dryrun/version'
6
6
  require 'dryrun/android_project'
7
+ require 'dryrun/install_application_command'
8
+ require 'dryrun/test_application_command'
7
9
  require 'dryrun/device'
8
10
  require 'highline/import'
9
11
  require 'openssl'
@@ -25,6 +27,7 @@ module Dryrun
25
27
  @branch = 'master'
26
28
  @devices = []
27
29
  @cleanup = false
30
+ @command = InstallApplicationCommand.new
28
31
 
29
32
  # Parse Options
30
33
  create_options_parser(arguments)
@@ -74,6 +77,10 @@ module Dryrun
74
77
  exit
75
78
  end
76
79
 
80
+ opts.on('-a', '--android-test', 'Execute android tests') do
81
+ @command = TestApplicationCommand.new
82
+ end
83
+
77
84
  opts.parse!
78
85
  end
79
86
  end
@@ -118,7 +125,7 @@ module Dryrun
118
125
  if @devices.size >= 2
119
126
  puts 'Pick your device (1,2,3...):'
120
127
 
121
- @devices.each_with_index.map { |key, index| puts "#{index.to_s.green} - #{key.name} \n" }
128
+ @devices.each_with_index.map {|key, index| puts "#{index.to_s.green} - #{key.name} \n"}
122
129
 
123
130
  input = gets.chomp
124
131
 
@@ -198,7 +205,7 @@ module Dryrun
198
205
  puts "Using custom module: #{@custom_module.green}" if @custom_module
199
206
 
200
207
  # clean and install the apk
201
- android_project.install
208
+ android_project.execute_command(@command)
202
209
 
203
210
  puts "\n> If you want to remove the app you just installed, execute:\n#{android_project.uninstall_command.yellow}\n\n"
204
211
  end
@@ -3,6 +3,8 @@ require 'fileutils'
3
3
  require 'tempfile'
4
4
  require 'find'
5
5
  require_relative 'dryrun_utils'
6
+ require_relative 'manifest_parser'
7
+ require_relative 'gradle_adapter'
6
8
 
7
9
  module Dryrun
8
10
  class AndroidProject
@@ -52,7 +54,8 @@ module Dryrun
52
54
 
53
55
  # Write good lines to temporary file
54
56
  File.open(file, 'r') do |f|
55
- f.each do |l| tmp << l unless l.include? 'applicationId'
57
+ f.each do |l|
58
+ tmp << l unless l.include? 'applicationId'
56
59
  end
57
60
  end
58
61
  tmp.close
@@ -71,7 +74,7 @@ module Dryrun
71
74
 
72
75
  def valid?(main_gradle_file = @main_gradle_file)
73
76
  File.exist?(main_gradle_file) &&
74
- File.exist?(@settings_gradle_path)
77
+ File.exist?(@settings_gradle_path)
75
78
  end
76
79
 
77
80
  def find_modules
@@ -79,111 +82,69 @@ module Dryrun
79
82
 
80
83
  content = File.open(@settings_gradle_path, 'rb').read
81
84
  modules = content.scan(/'([^']*)'/)
82
- modules.each { |replacement| replacement.first.tr!(':', '/') }
85
+ modules.each {|replacement| replacement.first.tr!(':', '/')}
83
86
  end
84
87
 
85
- def install
88
+ def execute_command(command)
86
89
  Dir.chdir @base_path
87
90
 
88
- path, execute_line = sample_project
91
+ path = sample_project
92
+ manifest_parsed = parse_manifest(path)
89
93
 
90
- if path == false && execute_line == false
94
+ if path == false && manifest_parsed == false
91
95
  puts "Couldn't open the sample project, sorry!".red
92
96
  exit 1
93
97
  end
94
98
 
95
- builder = 'gradle'
96
-
97
- if File.exist?('gradlew')
98
- if !Gem.win_platform?
99
- DryrunUtils.execute('chmod +x gradlew')
100
- else
101
- DryrunUtils.execute('icacls gradlew /T')
102
- end
103
- builder = './gradlew'
104
- end
105
-
106
- # Generate the gradle/ folder
107
- DryrunUtils.execute('gradle wrap') if File.exist?('gradlew') && !gradle_wrapped?
99
+ builder = create_builder
108
100
 
109
101
  remove_application_id
110
102
  remove_local_properties
111
103
 
112
- if @custom_module
113
- DryrunUtils.execute("#{builder} clean")
114
- DryrunUtils.execute("#{builder} :#{@custom_module}:install#{@flavour}Debug")
115
- else
116
- DryrunUtils.execute("#{builder} clean")
117
-
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
127
-
128
- unless @device.nil?
129
- clear_app_data
130
- puts "Installing #{@package.green}...\n"
131
- puts "executing: #{execute_line.green}\n"
132
-
133
- DryrunUtils.run_adb("shell #{execute_line}")
134
- end
104
+ command.run(builder, @package, @launcher_activity, @custom_module, @flavour, @device)
135
105
  end
136
106
 
137
107
  def gradle_wrapped?
138
108
  return false unless File.directory?('gradle/')
139
109
 
140
110
  File.exist?('gradle/wrapper/gradle-wrapper.properties') &&
141
- File.exist?('gradle/wrapper/gradle-wrapper.jar')
111
+ File.exist?('gradle/wrapper/gradle-wrapper.jar')
142
112
  end
143
113
 
144
114
  def sample_project
145
- if @custom_module && @modules.any? { |m| m.first == "/#{@custom_module}" }
115
+ if @custom_module && @modules.any? {|m| m.first == "/#{@custom_module}"}
146
116
  @path_to_sample = File.join(@base_path, "/#{@custom_module}")
147
- return @path_to_sample, get_execution_line_command(@path_to_sample)
117
+ return @path_to_sample
148
118
  else
149
119
  @modules.each do |child|
150
120
  full_path = File.join(@base_path, child.first)
151
121
  @path_to_sample = full_path
152
-
153
- execution_line_command = get_execution_line_command(full_path)
154
- return full_path, execution_line_command if execution_line_command
122
+ return full_path
155
123
  end
156
124
  end
157
- [false, false]
125
+ false
158
126
  end
159
127
 
160
128
  def uninstall_command
161
129
  "adb uninstall \"#{@package}\""
162
130
  end
163
131
 
164
- def clear_app_data
165
- DryrunUtils.run_adb("shell pm clear #{@package}")
166
- end
167
-
168
132
  def uninstall_application
169
133
  DryrunUtils.run_adb("shell pm uninstall #{@package}")
170
134
  end
171
135
 
172
- def get_execution_line_command(path_to_sample)
136
+ def parse_manifest(path_to_sample)
173
137
  manifest_file = get_manifest(path_to_sample)
174
138
 
175
139
  return false if manifest_file.nil?
176
140
 
177
- doc = Oga.parse_xml(manifest_file)
178
-
179
- @package = get_package(doc)
180
- @launcher_activity = get_launcher_activity(doc)
141
+ manifest_parser = ManifestParser.new(manifest_file)
142
+ @package = manifest_parser.package
143
+ @launcher_activity = manifest_parser.launcher_activity
181
144
 
182
145
  return false unless @launcher_activity
183
146
 
184
147
  manifest_file.close
185
-
186
- "am start -n \"#{launcheable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
187
148
  end
188
149
 
189
150
  def get_manifest(path_to_sample)
@@ -199,25 +160,21 @@ module Dryrun
199
160
  end
200
161
  end
201
162
 
202
- def launcheable_activity
203
- full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package, '')}"
204
- "#{@package}/#{full_path_to_launcher}"
205
- end
206
-
207
- def get_package(doc)
208
- doc.xpath('//manifest').attr('package').first.value
209
- end
210
-
211
- def get_launcher_activity(doc)
212
- activities = doc.css('activity')
213
- activities.each do |child|
214
- intent_filter = child.css('intent-filter')
163
+ def create_builder
164
+ builder = 'gradle'
215
165
 
216
- if !intent_filter.nil? && !intent_filter.empty?
217
- return child.attr('android:name').value
166
+ if File.exist?('gradlew')
167
+ if !Gem.win_platform?
168
+ DryrunUtils.execute('chmod +x gradlew')
169
+ else
170
+ DryrunUtils.execute('icacls gradlew /T')
218
171
  end
172
+ builder = './gradlew'
219
173
  end
220
- false
174
+
175
+ # Generate the gradle/ folder
176
+ DryrunUtils.execute('gradle wrap') if File.exist?('gradlew') && !gradle_wrapped?
177
+ GradleAdapter.new(builder)
221
178
  end
222
179
  end
223
180
  end
@@ -0,0 +1,17 @@
1
+ require_relative 'dryrun_utils'
2
+
3
+ module Dryrun
4
+ class AndroidUtils
5
+
6
+ def self.pretty_run(execute_line, package)
7
+ puts "Installing #{package.green}...\n"
8
+ puts "executing: #{execute_line.green}\n"
9
+
10
+ DryrunUtils.run_adb("shell #{execute_line}")
11
+ end
12
+
13
+ def self.clear_app_data(package)
14
+ DryrunUtils.run_adb("shell pm clear #{package}")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ require_relative 'dryrun_utils'
2
+
3
+ module Dryrun
4
+ class GradleAdapter
5
+
6
+ def initialize(builder)
7
+ @builder = builder
8
+ end
9
+
10
+ def clean
11
+ DryrunUtils.execute("#{@builder} clean")
12
+ end
13
+
14
+ def run_android_tests(custom_module, flavour)
15
+ if custom_module
16
+ puts "#{@builder} :#{custom_module}:connected#{flavour}DebugAndroidTest"
17
+ DryrunUtils.execute("#{@builder} :#{custom_module}:connected#{flavour}DebugAndroidTest")
18
+ else
19
+ puts "#{@builder} connected#{flavour}DebugAndroidTest"
20
+ DryrunUtils.execute("#{@builder} connected#{flavour}DebugAndroidTest")
21
+ end
22
+ end
23
+
24
+ def run_unit_tests(custom_module, flavour)
25
+ if custom_module
26
+ puts "#{@builder} :#{custom_module}:test#{flavour}DebugUnitTest"
27
+ DryrunUtils.execute("#{@builder} :#{custom_module}:test#{flavour}DebugUnitTest")
28
+ else
29
+ puts "#{@builder} test#{flavour}DebugUnitTest"
30
+ DryrunUtils.execute("#{@builder} test#{flavour}DebugUnitTest")
31
+ end
32
+ end
33
+
34
+ def install(custom_module, flavour)
35
+ if custom_module
36
+ puts "#{@builder} :#{custom_module}:install#{flavour}Debug"
37
+ DryrunUtils.execute("#{@builder} :#{custom_module}:install#{flavour}Debug")
38
+ else
39
+ puts "#{@builder} install#{flavour}Debug"
40
+ DryrunUtils.execute("#{@builder} install#{flavour}Debug")
41
+ end
42
+ end
43
+
44
+
45
+ def assemble(custom_module, flavour)
46
+ if custom_module
47
+ puts "#{@builder} :#{custom_module}:assemble#{flavour}Debug"
48
+ DryrunUtils.execute("#{@builder} :#{custom_module}:assemble#{flavour}Debug")
49
+ else
50
+ puts "#{@builder} assemble#{flavour}Debug"
51
+ DryrunUtils.execute("#{@builder} assemble#{flavour}Debug")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'dryrun_utils'
2
+ require_relative 'android_utils'
3
+
4
+ module Dryrun
5
+ class InstallApplicationCommand
6
+
7
+ def run(builder, package, launcher_activity, custom_module, flavour, device)
8
+ execute_line = get_execution_command_line(package, launcher_activity)
9
+ builder.clean
10
+
11
+ if device.nil?
12
+ puts 'No devices picked/available, proceeding with assemble instead'.green
13
+ builder.assemble(custom_module, flavour)
14
+ else
15
+ builder.install(custom_module, flavour)
16
+ end
17
+
18
+ unless device.nil?
19
+ AndroidUtils.clear_app_data(package)
20
+ AndroidUtils.pretty_run(execute_line, package)
21
+ end
22
+ end
23
+
24
+ def get_execution_command_line(package, launcher_activity)
25
+ "am start -n \"#{launcheable_activity(package, launcher_activity)}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
26
+ end
27
+
28
+ def launcheable_activity(package, launcher_activity)
29
+ full_path_to_launcher = "#{package}#{launcher_activity.gsub(package, '')}"
30
+ "#{package}/#{full_path_to_launcher}"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'oga'
2
+
3
+ module Dryrun
4
+
5
+ class ManifestParser
6
+
7
+ attr_accessor :package, :launcher_activity
8
+
9
+ def initialize(manifest_file)
10
+ doc = Oga.parse_xml(manifest_file)
11
+
12
+ @package = get_package(doc)
13
+ @launcher_activity = get_launcher_activity(doc)
14
+ end
15
+
16
+ def get_package(doc)
17
+ doc.xpath('//manifest').attr('package').first.value
18
+ end
19
+
20
+ def get_launcher_activity(doc)
21
+ activities = doc.css('activity')
22
+ activities.each do |child|
23
+ intent_filter = child.css('intent-filter')
24
+
25
+ if !intent_filter.nil? && !intent_filter.empty?
26
+ return child.attr('android:name').value
27
+ end
28
+ end
29
+ false
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'dryrun_utils'
2
+ require_relative 'android_utils'
3
+
4
+ module Dryrun
5
+ class TestApplicationCommand
6
+
7
+ def run(builder, package, launcher_activity, custom_module, flavour, device)
8
+ execute_line = get_execution_command_line(package)
9
+ builder.clean
10
+
11
+ if device.nil?
12
+ puts 'No devices picked/available, proceeding with unit tests instead'.green
13
+ builder.run_unit_tests(custom_module, flavour)
14
+ else
15
+ builder.run_android_tests(custom_module, flavour)
16
+ end
17
+
18
+ unless device.nil?
19
+ AndroidUtils.clear_app_data(package)
20
+ AndroidUtils.pretty_run(execute_line, package)
21
+ end
22
+ end
23
+
24
+ def get_execution_command_line(package)
25
+ "adb shell am instrument -w #{package}"
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Dryrun
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.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: 1.0.0
4
+ version: 1.1.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: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -149,9 +149,14 @@ files:
149
149
  - extras/usage_v4.gif
150
150
  - lib/dryrun.rb
151
151
  - lib/dryrun/android_project.rb
152
+ - lib/dryrun/android_utils.rb
152
153
  - lib/dryrun/device.rb
153
154
  - lib/dryrun/dryrun_utils.rb
154
155
  - lib/dryrun/github.rb
156
+ - lib/dryrun/gradle_adapter.rb
157
+ - lib/dryrun/install_application_command.rb
158
+ - lib/dryrun/manifest_parser.rb
159
+ - lib/dryrun/test_application_command.rb
155
160
  - lib/dryrun/version.rb
156
161
  - spec/dryrun_spec.rb
157
162
  - spec/github_spec.rb
@@ -177,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
182
  version: '0'
178
183
  requirements: []
179
184
  rubyforge_project:
180
- rubygems_version: 2.6.11
185
+ rubygems_version: 2.6.14
181
186
  signing_key:
182
187
  specification_version: 4
183
188
  summary: Tool to try any android library hosted online directly from the command line