danger-apkstats 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc1a0db0fe161e8b61abb00fd8a12a7040af81ef0b525d3c5a2a06267e2e0d9f
4
- data.tar.gz: 36c1d0ab4947c4fae224f5f35d8449415c73de6981f01a1f49602597acae8724
3
+ metadata.gz: 06da284025d85c4baf756df842fef7ed035bbc6a4b51e3869b03df48f851b480
4
+ data.tar.gz: ed4436f89c1b65211bd338aa4e48095df59c7f518c69a185836cdde7655d2149
5
5
  SHA512:
6
- metadata.gz: 965a9ddd9979aef4ad646489d10402695686d8260d3a86fb4c666370f491d1b5cc76ece977db67d6216408ba87ccaf15e1ab29322ddab9ac85e6273a99b23531
7
- data.tar.gz: 71130099a63a8f8d347c647e4ecff86cc8964600118e9bdd30ed771e5441372de7f1acd270b53247d54d29558b1422676d879eb8a303893681b21daa72c328c7
6
+ metadata.gz: d67745379004649774230e918514f09ac792050190540f23efab90c29308b9b3fe098884288c975f2c74a37e1aab2d9434881224a4e9682a0be1bf58859a17a4
7
+ data.tar.gz: 869be5736265bffec15b3468846b346a6a45c3b4796e7a80b4cf1448845009f22d9c6e5fb12bebc4c4d7a6e363bffa62a386cd4be18b39eeeeb9c31de139cd8c
@@ -3,7 +3,16 @@
3
3
  # If you don't like these settings, just delete this file :)
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.0
6
+ Exclude:
7
+ - 'vendor/**/*'
8
+ - 'spec/fixtures/**/*'
9
+ - 'tmp/**/*'
10
+ TargetRubyVersion: 2.3.7
11
+
12
+ Metrics/ModuleLength:
13
+ Exclude:
14
+ - 'spec/**/*'
15
+ Enabled: true
7
16
 
8
17
  Style/StringLiterals:
9
18
  EnforcedStyle: double_quotes
@@ -150,3 +159,12 @@ PercentLiteralDelimiters:
150
159
 
151
160
  Security/YAMLLoad:
152
161
  Enabled: false
162
+
163
+ Style/TrailingCommaInArguments:
164
+ Enabled: true
165
+
166
+ Style/TrailingCommaInArrayLiteral:
167
+ Enabled: false
168
+
169
+ Style/TrailingCommaInHashLiteral:
170
+ Enabled: false
@@ -1,12 +1,25 @@
1
1
  language: ruby
2
2
  cache:
3
3
  directories:
4
- - bundle
4
+ - vendor/bundle
5
+ - sdk
5
6
 
6
7
  rvm:
7
- - 2.0
8
- - 2.1.3
9
- - 2.3.1
8
+ - 2.3.7
9
+ - 2.4.4
10
+ - 2.5.1
10
11
 
11
12
  script:
12
- - bundle exec rake spec
13
+ - |
14
+ version='4333796'
15
+
16
+ if [ "$(cat sdk/.sdk_tools_version || echo)" != "$version" ]; then
17
+ rm -fr sdk || :
18
+ mkdir -p sdk/licenses
19
+ curl -o sdk-tools-linux.zip "https://dl.google.com/android/repository/sdk-tools-linux-$version.zip"
20
+ unzip "sdk-tools-linux.zip" -d sdk
21
+ fi
22
+
23
+ echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > sdk/licenses/android-sdk-license
24
+ sdk/tools/bin/sdkmanager "build-tools;27.0.3"
25
+ - ANDROID_HOME="$PWD/sdk" bundle exec rake spec
@@ -0,0 +1,15 @@
1
+ apkstats.command_type=:apk_analyzer
2
+ apkstats.apk_filepath='./spec/fixture/app-base.apk'
3
+
4
+ # custom command path
5
+ # apkstats.command_path='/path/to/analysis_command'
6
+
7
+ message(apkstats.file_size)
8
+ message(apkstats.download_size)
9
+ message(apkstats.required_features)
10
+ message(apkstats.non_required_features)
11
+ message(apkstats.permissions)
12
+ message(apkstats.min_sdk)
13
+ message(apkstats.target_sdk)
14
+
15
+ apkstats.compare_with('/spec/fixture/app-other5.apk', do_report: true)
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in danger-apkstats.gemspec
4
6
  gemspec
@@ -0,0 +1,136 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-apkstats (0.1.0)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ ast (2.4.0)
13
+ claide (1.0.2)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.2)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (5.6.4)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (~> 0.9)
28
+ faraday-http-cache (~> 1.0)
29
+ git (~> 1)
30
+ kramdown (~> 1.5)
31
+ no_proxy_fix
32
+ octokit (~> 4.7)
33
+ terminal-table (~> 1)
34
+ danger-plugin-api (1.0.0)
35
+ danger (> 2.0)
36
+ diff-lcs (1.3)
37
+ faraday (0.15.2)
38
+ multipart-post (>= 1.2, < 3)
39
+ faraday-http-cache (1.3.1)
40
+ faraday (~> 0.8)
41
+ ffi (1.9.25)
42
+ formatador (0.2.5)
43
+ git (1.4.0)
44
+ guard (2.14.2)
45
+ formatador (>= 0.2.4)
46
+ listen (>= 2.7, < 4.0)
47
+ lumberjack (>= 1.0.12, < 2.0)
48
+ nenv (~> 0.1)
49
+ notiffany (~> 0.0)
50
+ pry (>= 0.9.12)
51
+ shellany (~> 0.0)
52
+ thor (>= 0.18.1)
53
+ guard-compat (1.2.1)
54
+ guard-rspec (4.7.3)
55
+ guard (~> 2.1)
56
+ guard-compat (~> 1.1)
57
+ rspec (>= 2.99.0, < 4.0)
58
+ jaro_winkler (1.5.1)
59
+ kramdown (1.17.0)
60
+ listen (3.0.7)
61
+ rb-fsevent (>= 0.9.3)
62
+ rb-inotify (>= 0.9.7)
63
+ lumberjack (1.0.13)
64
+ method_source (0.9.0)
65
+ multipart-post (2.0.0)
66
+ nap (1.1.0)
67
+ nenv (0.3.0)
68
+ no_proxy_fix (0.1.2)
69
+ notiffany (0.1.1)
70
+ nenv (~> 0.1)
71
+ shellany (~> 0.0)
72
+ octokit (4.9.0)
73
+ sawyer (~> 0.8.0, >= 0.5.3)
74
+ open4 (1.3.4)
75
+ parallel (1.12.1)
76
+ parser (2.5.1.2)
77
+ ast (~> 2.4.0)
78
+ powerpack (0.1.2)
79
+ pry (0.11.3)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.9.0)
82
+ public_suffix (3.0.2)
83
+ rainbow (3.0.0)
84
+ rake (10.5.0)
85
+ rb-fsevent (0.10.3)
86
+ rb-inotify (0.9.10)
87
+ ffi (>= 0.5.0, < 2)
88
+ rspec (3.7.0)
89
+ rspec-core (~> 3.7.0)
90
+ rspec-expectations (~> 3.7.0)
91
+ rspec-mocks (~> 3.7.0)
92
+ rspec-core (3.7.1)
93
+ rspec-support (~> 3.7.0)
94
+ rspec-expectations (3.7.0)
95
+ diff-lcs (>= 1.2.0, < 2.0)
96
+ rspec-support (~> 3.7.0)
97
+ rspec-mocks (3.7.0)
98
+ diff-lcs (>= 1.2.0, < 2.0)
99
+ rspec-support (~> 3.7.0)
100
+ rspec-support (3.7.1)
101
+ rubocop (0.58.2)
102
+ jaro_winkler (~> 1.5.1)
103
+ parallel (~> 1.10)
104
+ parser (>= 2.5, != 2.5.1.1)
105
+ powerpack (~> 0.1)
106
+ rainbow (>= 2.2.2, < 4.0)
107
+ ruby-progressbar (~> 1.7)
108
+ unicode-display_width (~> 1.0, >= 1.0.1)
109
+ ruby-progressbar (1.9.0)
110
+ sawyer (0.8.1)
111
+ addressable (>= 2.3.5, < 2.6)
112
+ faraday (~> 0.8, < 1.0)
113
+ shellany (0.0.1)
114
+ terminal-table (1.8.0)
115
+ unicode-display_width (~> 1.1, >= 1.1.1)
116
+ thor (0.20.0)
117
+ unicode-display_width (1.4.0)
118
+ yard (0.9.15)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ bundler (~> 1.3)
125
+ danger-apkstats!
126
+ guard (~> 2.14)
127
+ guard-rspec (~> 4.7)
128
+ listen (= 3.0.7)
129
+ pry
130
+ rake (~> 10.0)
131
+ rspec (~> 3.4)
132
+ rubocop
133
+ yard
134
+
135
+ BUNDLED WITH
136
+ 1.16.1
data/Guardfile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A guardfile for making Danger Plugins
2
4
  # For more info see https://github.com/guard/guard#readme
3
5
 
4
6
  # To run, use `bundle exec guard`.
5
7
 
6
- guard :rspec, cmd: 'bundle exec rspec' do
7
- require 'guard/rspec/dsl'
8
+ guard :rspec, cmd: "bundle exec rspec" do
9
+ require "guard/rspec/dsl"
8
10
  dsl = Guard::RSpec::Dsl.new(self)
9
11
 
10
12
  # RSpec files
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.com/jmatsu/danger-apkstats.svg?branch=master)](https://travis-ci.com/jmatsu/danger-apkstats) [![Gem Version](https://badge.fury.io/rb/danger-apkstats.svg)](https://badge.fury.io/rb/danger-apkstats)
2
+
1
3
  # danger-apkstats
2
4
 
3
5
  A description of danger-apkstats.
@@ -14,13 +16,32 @@ A description of danger-apkstats.
14
16
  # Sample
15
17
 
16
18
  ```
17
- apkstats.command_type=:apk_analyzer # required
18
- apkstats.apk_filepath='app-debug.apk' # required
19
+ apkstats.apk_filepath='app-debug.apk' # required.
19
20
  apkstats.compare_with('app-other.apk', do_report: true)
20
- apkstats.filesize
21
- apkstats.downloadsize
21
+ apkstats.file_size #=> Fixnum
22
+ apkstats.download_size #=> Fixnum
23
+ apkstats.required_features #=> Array<String> | Nil
24
+ apkstats.non_required_features #=> Array<String> | Nil
25
+ apkstats.permissions #=> Array<String> | Nil
26
+ apkstats.min_sdk #=> String | Nil
27
+ apkstats.target_sdk #=> String | Nils
22
28
  ```
23
29
 
30
+ ## Compare apk files
31
+
32
+ The report will be like below.
33
+
34
+ ### Apk comparision results
35
+
36
+ Property | Summary
37
+ :--- | :---
38
+ New File Size | 1621248 Bytes. (1.55 MB
39
+ File Size Change | -13352 Bytes. (-13.04 KB)
40
+ Download Size Change | +41141 Bytes. (+40.18 KB)
41
+ Removed Required Features | - android.hardware.camera
42
+ Removed Non-required Features | - android.hardware.camera.front (not-required)
43
+ Removed Permissions | - android.permission.INTERNET<br>- android.permission.CAMERA
44
+
24
45
  ## Development
25
46
 
26
47
  1. Clone this repo
data/Rakefile CHANGED
@@ -1,23 +1,25 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rubocop/rake_task'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
4
6
 
5
7
  RSpec::Core::RakeTask.new(:specs)
6
8
 
7
9
  task default: :specs
8
10
 
9
11
  task :spec do
10
- Rake::Task['specs'].invoke
11
- Rake::Task['rubocop'].invoke
12
- Rake::Task['spec_docs'].invoke
12
+ Rake::Task["specs"].invoke
13
+ Rake::Task["rubocop"].invoke
14
+ Rake::Task["spec_docs"].invoke
13
15
  end
14
16
 
15
- desc 'Run RuboCop on the lib/specs directory'
17
+ desc "Run RuboCop on the lib/specs directory"
16
18
  RuboCop::RakeTask.new(:rubocop) do |task|
17
- task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
19
+ task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
18
20
  end
19
21
 
20
- desc 'Ensure that the plugin passes `danger plugins lint`'
22
+ desc "Ensure that the plugin passes `danger plugins lint`"
21
23
  task :spec_docs do
22
- sh 'bundle exec danger plugins lint'
24
+ sh "bundle exec danger plugins lint"
23
25
  end
@@ -1,42 +1,43 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'apkstats/gem_version.rb'
5
+ require "apkstats/gem_version.rb"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = 'danger-apkstats'
8
+ spec.name = "danger-apkstats"
8
9
  spec.version = Apkstats::VERSION
9
- spec.authors = ['Jumpei Matsuda']
10
- spec.email = ['jmatsu.drm@gmail.com']
11
- spec.description = %q{To inpsect android application file with danger.}
12
- spec.summary = %q{This is a danger plugin to inspect android application file.}
13
- spec.homepage = 'https://github.com/jmatsu/danger-apkstats'
14
- spec.license = 'MIT'
10
+ spec.authors = ["Jumpei Matsuda"]
11
+ spec.email = ["jmatsu.drm@gmail.com"]
12
+ spec.description = "To inpsect android application file with danger."
13
+ spec.summary = "This is a danger plugin to inspect android application file."
14
+ spec.homepage = "https://github.com/jmatsu/danger-apkstats"
15
+ spec.license = "MIT"
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ['lib']
20
+ spec.require_paths = ["lib"]
20
21
 
21
- spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+ spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
22
23
 
23
24
  # General ruby development
24
- spec.add_development_dependency 'bundler', '~> 1.3'
25
- spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake", "~> 10.0"
26
27
 
27
28
  # Testing support
28
- spec.add_development_dependency 'rspec', '~> 3.4'
29
+ spec.add_development_dependency "rspec", "~> 3.4"
29
30
 
30
31
  # Linting code and docs
31
32
  spec.add_development_dependency "rubocop"
32
33
  spec.add_development_dependency "yard"
33
34
 
34
35
  # Makes testing easy via `bundle exec guard`
35
- spec.add_development_dependency 'guard', '~> 2.14'
36
- spec.add_development_dependency 'guard-rspec', '~> 4.7'
36
+ spec.add_development_dependency "guard", "~> 2.14"
37
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
37
38
 
38
39
  # If you want to work on older builds of ruby
39
- spec.add_development_dependency 'listen', '3.0.7'
40
+ spec.add_development_dependency "listen", "3.0.7"
40
41
 
41
42
  # This gives you the chance to run a REPL inside your tests
42
43
  # via:
@@ -45,5 +46,5 @@ Gem::Specification.new do |spec|
45
46
  # binding.pry
46
47
  #
47
48
  # This will stop test execution and let you inspect the results
48
- spec.add_development_dependency 'pry'
49
+ spec.add_development_dependency "pry"
49
50
  end
@@ -1,35 +1,70 @@
1
- module Danger::Apkstats
1
+ # frozen_string_literal: true
2
+
3
+ module Apkstats::Command
2
4
  class ApkAnalyzer
3
- include Danger::Apkstats::ExecutableCommand
5
+ include Apkstats::Command::Executable
4
6
 
5
- def compare_with(apk_filepath, other_apk_filepath)
6
- out, err = run_command('apk', 'compare', '--different-only', apk_filepath, other_apk_filepath)
7
+ def initialize(opts)
8
+ @command_path = opts[:command_path] || "#{ENV.fetch('ANDROID_HOME')}/tools/bin/apkanalyzer"
9
+ end
7
10
 
8
- if out
9
- return out.partition("\n").first.strip, nil
10
- else
11
- return nil, err
12
- end
11
+ def file_size(apk_filepath)
12
+ run_command("apk", "file-size", apk_filepath)
13
13
  end
14
14
 
15
- def filesize(apk_filepath)
16
- run_command('apk', 'file-size', apk_filepath)
15
+ def download_size(apk_filepath)
16
+ run_command("apk", "download-size", apk_filepath)
17
17
  end
18
18
 
19
- def downloadsize(apk_filepath)
20
- run_command('apk', 'download-size', apk_filepath)
19
+ def required_features(apk_filepath)
20
+ ::Apkstats::Entity::Features.new(ApkAnalyzer.parse_features(run_command("apk", "features", apk_filepath)))
21
21
  end
22
22
 
23
- private
23
+ def non_required_features(apk_filepath)
24
+ all_features = ApkAnalyzer.parse_features(run_command("apk", "features", "--not-required", apk_filepath))
25
+ Apkstats::Entity::Features.new(all_features.select(&:not_required?))
26
+ end
24
27
 
25
- def run_command(*args)
26
- out, err, status = Open3.capture3("#{command} #{args.join(' ')}")
27
- return out, nil if status == 0
28
- return nil, (err || 'failed due while executing a command')
28
+ def permissions(apk_filepath)
29
+ ::Apkstats::Entity::Permissions.new(ApkAnalyzer.parse_permissions(run_command("manifest", "permissions", apk_filepath)))
30
+ end
31
+
32
+ def min_sdk(apk_filepath)
33
+ run_command("manifest", "min-sdk", apk_filepath)
34
+ end
35
+
36
+ def target_sdk(apk_filepath)
37
+ run_command("manifest", "target-sdk", apk_filepath)
38
+ end
39
+
40
+ def self.parse_permissions(command_output)
41
+ command_output.split(/\r?\n/).map { |s| to_permission(s) }
29
42
  end
30
43
 
31
- def command
32
- @command ||= "#{ENV.fetch('ANDROID_HOME')}/tools/bin/apkanalyzer"
44
+ def self.to_permission(str)
45
+ # If maxSdkVersion is specified, the output is like `android.permission.INTERNET' maxSdkVersion='23`
46
+ name_seed, max_sdk_seed = str.strip.split(/\s/)
47
+ ::Apkstats::Entity::Permission.new(name_seed.gsub(/'$/, ""), max_sdk: max_sdk_seed && max_sdk_seed[/[0-9]+/])
48
+ end
49
+
50
+ def self.parse_features(command_output)
51
+ command_output.split(/\r?\n/).map { |s| to_feature(s) }
52
+ end
53
+
54
+ def self.to_feature(str)
55
+ # format / name implied: xxxx
56
+ # not-required and implied cannot co-exist so it's okay to parse them like this
57
+ name, kind, tail = str.strip.split(/\s/, 3)
58
+
59
+ ::Apkstats::Entity::Feature.new(name, not_required: kind == "not-required", implied_reason: kind == "implied:" && tail)
60
+ end
61
+
62
+ private
63
+
64
+ def run_command(*args)
65
+ out, err, status = Open3.capture3("#{command_path} #{args.join(' ')}")
66
+ raise err unless status.success?
67
+ out.rstrip
33
68
  end
34
69
  end
35
- end
70
+ end