danger-apkstats 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: 206a4a16c43f2e18507ab485cce2947c1e932fbee471db57e4f43b20b9e4aa02
4
- data.tar.gz: f38876905c1095c7da969bbb6d6e43ea5a09ab0cce2941544263137c2ffa3a1e
3
+ metadata.gz: 7e3766086cf1f908f3a553259ce56b77077cb25af31cb6f1d2c36c565d4fc62a
4
+ data.tar.gz: a8592f39aa1288898076e59e0586c3ac941a92294d65123eaad05236e9d78588
5
5
  SHA512:
6
- metadata.gz: a9490b757975f4ed708ce6e2df907cea5594cd1fdd8bd338cd6eff111f8d75148c41ad442c1756af7aca9f78992d908fb76905bbcd7cddb0fb3f4ea4e6ab4d04
7
- data.tar.gz: 73c01476155e698d19655affd292bbdebfffad6e4615bb96257280a57deced379b7a4fedc3bcd43d049460a8d0f2da6925d9fae7e08c048e4fd0b7eb6e3fbbd8
6
+ metadata.gz: 0a93c60400f8692df2701b939cd840d740990da627c530e015ef4012f652de3770d10fb339fe1db7795fb313cbfdd2854c2ac7b5e0580b69add6995e1d1ac980
7
+ data.tar.gz: b77a1fa1c2c6cff74fdeeba07b6e4d41db76cda9b691f2d702dfdd69138d15a75fcb7897cbe4a8371de9e55ed984b8ea41389efe32fbb83c10498c247f661090
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-apkstats (0.3.0)
4
+ danger-apkstats (0.3.1)
5
5
  danger-plugin-api (~> 1.0)
6
6
 
7
7
  GEM
@@ -57,7 +57,7 @@ GEM
57
57
  guard (~> 2.1)
58
58
  guard-compat (~> 1.1)
59
59
  rspec (>= 2.99.0, < 4.0)
60
- kramdown (2.2.1)
60
+ kramdown (2.3.0)
61
61
  rexml
62
62
  kramdown-parser-gfm (1.1.0)
63
63
  kramdown (~> 2.0)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apkstats
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -109,91 +109,93 @@ module Danger
109
109
  def compare_with(other_apk_filepath, do_report: true)
110
110
  raise "apk filepaths must be specified" if apk_filepath.nil? || apk_filepath.empty?
111
111
 
112
- base_apk = Apkstats::Entity::ApkInfo.new(command, apk_filepath)
113
- other_apk = Apkstats::Entity::ApkInfo.new(command, other_apk_filepath)
112
+ base_apk = Apkstats::Entity::ApkInfo.new(apkanalyzer_command, apk_filepath)
113
+ other_apk = Apkstats::Entity::ApkInfo.new(apkanalyzer_command, other_apk_filepath)
114
114
 
115
- return {
115
+ result = {
116
116
  base: base_apk.to_h,
117
117
  other: base_apk.to_h,
118
118
  diff: Apkstats::Entity::ApkInfoDiff.new(base_apk, other_apk).to_h,
119
- }.tap do |result|
120
- break unless do_report
119
+ }
121
120
 
122
- diff = result[:diff]
121
+ return result unless do_report
123
122
 
124
- md = +"### Apk comparison results" << "\n\n"
125
- md << "Property | Summary" << "\n"
126
- md << ":--- | :---" << "\n"
123
+ diff = result[:diff]
127
124
 
128
- diff[:min_sdk].tap do |min_sdk|
129
- break if min_sdk.size == 1
125
+ md = +"### Apk comparison results" << "\n\n"
126
+ md << "Property | Summary" << "\n"
127
+ md << ":--- | :---" << "\n"
130
128
 
131
- md << "Min SDK Change | Before #{min_sdk[1]} / After #{min_sdk[0]}" << "\n"
132
- end
129
+ diff[:min_sdk].tap do |min_sdk|
130
+ break if min_sdk.size == 1
133
131
 
134
- diff[:target_sdk].tap do |target_sdk|
135
- break if target_sdk.size == 1
132
+ md << "Min SDK Change | Before #{min_sdk[1]} / After #{min_sdk[0]}" << "\n"
133
+ end
136
134
 
137
- md << "Target SDK Change | Before #{target_sdk[1]} / After #{target_sdk[0]}" << "\n"
138
- end
135
+ diff[:target_sdk].tap do |target_sdk|
136
+ break if target_sdk.size == 1
139
137
 
140
- result[:base][:file_size].tap do |file_size|
141
- size = Apkstats::Helper::Bytes.from_b(file_size)
138
+ md << "Target SDK Change | Before #{target_sdk[1]} / After #{target_sdk[0]}" << "\n"
139
+ end
142
140
 
143
- md << "New File Size | #{size.to_b} Bytes. (#{size.to_mb} MB) " << "\n"
144
- end
141
+ result[:base][:file_size].tap do |file_size|
142
+ size = Apkstats::Helper::Bytes.from_b(file_size)
145
143
 
146
- diff[:file_size].tap do |file_size|
147
- size = Apkstats::Helper::Bytes.from_b(file_size)
144
+ md << "New File Size | #{size.to_b} Bytes. (#{size.to_mb} MB) " << "\n"
145
+ end
148
146
 
149
- md << "File Size Change | #{size.to_s_b} Bytes. (#{size.to_s_kb} KB) " << "\n"
150
- end
147
+ diff[:file_size].tap do |file_size|
148
+ size = Apkstats::Helper::Bytes.from_b(file_size)
151
149
 
152
- diff[:download_size].tap do |download_size|
153
- size = Apkstats::Helper::Bytes.from_b(download_size)
150
+ md << "File Size Change | #{size.to_s_b} Bytes. (#{size.to_s_kb} KB) " << "\n"
151
+ end
154
152
 
155
- md << "Download Size Change | #{size.to_s_b} Bytes. (#{size.to_s_kb} KB) " << "\n"
156
- end
153
+ diff[:download_size].tap do |download_size|
154
+ size = Apkstats::Helper::Bytes.from_b(download_size)
157
155
 
158
- result[:base][:method_reference_count].tap do |method_reference_count|
159
- md << "New Method Reference Count | #{method_reference_count}" << "\n"
160
- end
156
+ md << "Download Size Change | #{size.to_s_b} Bytes. (#{size.to_s_kb} KB) " << "\n"
157
+ end
161
158
 
162
- diff[:method_reference_count].tap do |method_reference_count|
163
- md << "Method Reference Count Change | #{method_reference_count}" << "\n"
164
- end
159
+ result[:base][:method_reference_count].tap do |method_reference_count|
160
+ md << "New Method Reference Count | #{method_reference_count}" << "\n"
161
+ end
165
162
 
166
- result[:base][:dex_count].tap do |dex_count|
167
- md << "New Number of dex file(s) | #{dex_count}" << "\n"
168
- end
163
+ diff[:method_reference_count].tap do |method_reference_count|
164
+ md << "Method Reference Count Change | #{method_reference_count}" << "\n"
165
+ end
169
166
 
170
- diff[:dex_count].tap do |dex_count|
171
- md << "Number of dex file(s) Change | #{dex_count}" << "\n"
172
- end
167
+ result[:base][:dex_count].tap do |dex_count|
168
+ md << "New Number of dex file(s) | #{dex_count}" << "\n"
169
+ end
173
170
 
174
- report_hash_and_arrays = lambda { |key, name|
175
- list_up_entities = lambda { |type_key, label|
176
- diff[key][type_key].tap do |features|
177
- break if features.empty?
171
+ diff[:dex_count].tap do |dex_count|
172
+ md << "Number of dex file(s) Change | #{dex_count}" << "\n"
173
+ end
178
174
 
179
- md << "#{label} | " << features.map { |f| "- #{f}" }.join("<br>").to_s << "\n"
180
- end
181
- }
175
+ report_hash_and_arrays = lambda { |key, name|
176
+ list_up_entities = lambda { |type_key, label|
177
+ diff[key][type_key].tap do |features|
178
+ break if features.empty?
182
179
 
183
- list_up_entities.call(:new, "New #{name}")
184
- list_up_entities.call(:removed, "Removed #{name}")
180
+ md << "#{label} | " << features.map { |f| "- #{f}" }.join("<br>").to_s << "\n"
181
+ end
185
182
  }
186
183
 
187
- report_hash_and_arrays.call(:required_features, "Required Features")
188
- report_hash_and_arrays.call(:non_required_features, "Non-required Features")
189
- report_hash_and_arrays.call(:permissions, "Permissions")
184
+ list_up_entities.call(:new, "New #{name}")
185
+ list_up_entities.call(:removed, "Removed #{name}")
186
+ }
190
187
 
191
- markdown(md)
192
- end
188
+ report_hash_and_arrays.call(:required_features, "Required Features")
189
+ report_hash_and_arrays.call(:non_required_features, "Non-required Features")
190
+ report_hash_and_arrays.call(:permissions, "Permissions")
191
+
192
+ markdown(md)
193
+ true
193
194
  rescue StandardError => e
194
195
  warn("apkstats failed to execute the command due to #{e.message}")
195
196
 
196
197
  on_error(e)
198
+ false
197
199
  end
198
200
 
199
201
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -287,17 +289,25 @@ module Danger
287
289
  def apkanalyzer_command
288
290
  return @apkanalyzer_command if defined?(@apkanalyzer_command)
289
291
 
290
- command_path = apkanalyzer_path || begin
291
- android_home = ENV["ANDROID_HOME"]
292
+ command_path = apkanalyzer_path || `which apkanalyzer`.chomp
293
+
294
+ if command_path.empty?
295
+ sdk_path = ENV["ANDROID_HOME"] || ENV["ANDROID_SDK_ROOT"]
296
+
297
+ if sdk_path
298
+ tmp_path = File.join(sdk_path, "cmdline-tools/tools/bin/apkanalyzer")
299
+ tmp_path = File.join(sdk_path, "tools/bin/apkanalyzer") unless File.executable?(tmp_path)
300
+
301
+ command_path = tmp_path if File.executable?(tmp_path)
302
+ else
303
+ warn("apkstats will not infer the apkanalyzer path in further versions so please include apkanalyer in your PATH or specify it explicitly.")
304
+ end
305
+ end
292
306
 
293
- if android_home
294
- warn("apkstats will not use ANDROID_HOME in further versions because ANDROID_HOME has been officially deprecated.")
295
- else
296
- raise Error, "Please specify apkanalyzer_path to execute apkstats"
297
- end
307
+ command_path = command_path.chomp
298
308
 
299
- "#{android_home}/tools/bin/apkanalyzer"
300
- end
309
+ raise Error, "Please include apkanalyer in your PATH or specify it explicitly." if command_path.empty?
310
+ raise Error, "#{command_path} is not executable." unless File.executable?(command_path)
301
311
 
302
312
  @apkanalyzer_command = Apkstats::Command::ApkAnalyzer.new(command_path: command_path)
303
313
  end
@@ -4,11 +4,6 @@ require File.expand_path("spec_helper", __dir__)
4
4
 
5
5
  module Danger
6
6
  describe Danger::DangerApkstats do
7
- before do
8
- ENV.delete("ANDROID_HOME")
9
- ENV.delete("ANDROID_SDK_ROOT")
10
- end
11
-
12
7
  it "should be a plugin" do
13
8
  expect(Danger::DangerApkstats.new(nil)).to be_a Danger::Plugin
14
9
  end
@@ -22,48 +17,24 @@ module Danger
22
17
  allow(apkstats.github).to receive(:pr_json).and_return(json)
23
18
  end
24
19
 
25
- # compatibility
26
- describe "#command_path=" do
27
- context "unless command_path is given" do
28
- it { expect { apkstats.send(:apkanalyzer_command) }.to raise_error(Danger::DangerApkstats::Error) }
20
+ describe "#compare_with" do
21
+ let(:apk_base) { fixture_path + "app-base.apk" }
22
+ let(:apk_other1) { fixture_path + "app-other1.apk" }
29
23
 
30
- context "with ANDROID_HOME" do
31
- before do
32
- ENV["ANDROID_HOME"] = "dummy"
33
- end
34
-
35
- it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
36
- end
24
+ before do
25
+ apkstats.apkanalyzer_path = `which apkanalyzer`.chomp
37
26
  end
38
27
 
39
- context "if command_path is given" do
40
- before do
41
- apkstats.command_path = "dummy"
42
- end
43
-
44
- it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
45
- end
46
- end
47
-
48
- describe "#apkanalyzer_path=" do
49
- context "unless analyzer_path is given" do
50
- it { expect { apkstats.send(:apkanalyzer_command) }.to raise_error(Danger::DangerApkstats::Error) }
51
-
52
- context "with ANDROID_HOME" do
53
- before do
54
- ENV["ANDROID_HOME"] = "dummy"
55
- end
56
-
57
- it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
58
- end
28
+ context "unless apk_filepath is specified" do
29
+ it { expect(apkstats.compare_with(apk_other1, do_report: true)).to be_falsey }
59
30
  end
60
31
 
61
- context "if analyzer_path is given" do
32
+ context "otherwise" do
62
33
  before do
63
- apkstats.apkanalyzer_path = "dummy"
34
+ apkstats.apk_filepath = apk_base
64
35
  end
65
36
 
66
- it { expect(apkstats.send(:apkanalyzer_command)).to be_kind_of(Apkstats::Command::ApkAnalyzer) }
37
+ it { expect(apkstats.compare_with(apk_other1, do_report: true)).to be_truthy }
67
38
  end
68
39
  end
69
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-apkstats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jumpei Matsuda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-21 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -194,7 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.1.2
197
+ rubyforge_project:
198
+ rubygems_version: 2.7.6.2
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: This is a danger plugin to inspect android application file.