rubotium 0.0.4 → 0.0.7
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 +4 -4
- data/.gitignore +4 -0
- data/bin/rubotium +4 -2
- data/lib/rubotium/adb/commands/command.rb +55 -0
- data/lib/rubotium/adb/commands/install_command.rb +19 -0
- data/lib/rubotium/adb/commands/instrument_command.rb +27 -0
- data/lib/rubotium/adb/commands/memory_command.rb +19 -0
- data/lib/rubotium/adb/commands/pull_command.rb +19 -0
- data/lib/rubotium/adb/commands/shell_command.rb +21 -0
- data/lib/rubotium/adb/commands/uninstall_command.rb +19 -0
- data/lib/rubotium/adb/commands.rb +7 -0
- data/lib/rubotium/adb/devices.rb +15 -6
- data/lib/rubotium/adb/parsers/procrank.rb +51 -0
- data/lib/rubotium/adb/parsers/single_test_result_parser.rb +61 -0
- data/lib/rubotium/adb/parsers/test_results_parser.rb +69 -0
- data/lib/rubotium/adb/parsers.rb +3 -0
- data/lib/rubotium/adb/test_result_parser.rb +5 -4
- data/lib/rubotium/adb.rb +3 -5
- data/lib/rubotium/apk/android_apk.rb +102 -0
- data/lib/rubotium/apk.rb +2 -2
- data/lib/rubotium/cmd.rb +1 -1
- data/lib/rubotium/device.rb +19 -33
- data/lib/rubotium/devices.rb +27 -14
- data/lib/rubotium/formatters/junit_formatter.rb +10 -11
- data/lib/rubotium/memory/data_point.rb +63 -0
- data/lib/rubotium/memory/monitor.rb +65 -0
- data/lib/rubotium/memory.rb +8 -0
- data/lib/rubotium/package.rb +7 -4
- data/lib/rubotium/runnable_test.rb +13 -0
- data/lib/rubotium/test_cases_reader.rb +32 -0
- data/lib/rubotium/test_result.rb +52 -0
- data/lib/rubotium/test_results.rb +18 -0
- data/lib/rubotium/test_runners/instrumentation_test_runner.rb +24 -0
- data/lib/rubotium/tests_runner.rb +80 -0
- data/lib/rubotium/version.rb +1 -1
- data/lib/rubotium.rb +54 -41
- data/rubotium.gemspec +0 -1
- data/spec/fixtures/adb_raw_result.rb +138 -0
- data/spec/fixtures/adb_raw_results.rb +153 -0
- data/spec/fixtures/adb_results.rb +4 -0
- data/spec/lib/rubotium/adb/adb_devices_spec.rb +43 -12
- data/spec/lib/rubotium/adb/adb_result_parser_spec.rb +22 -7
- data/spec/lib/rubotium/adb/adb_shell_spec.rb +11 -6
- data/spec/lib/rubotium/adb/parsers/procrank_spec.rb +61 -0
- data/spec/lib/rubotium/adb/parsers/single_test_result_parser_spec.rb +116 -0
- data/spec/lib/rubotium/adb/parsers/test_results_parser_spec.rb +108 -0
- data/spec/lib/rubotium/apk/android_apk_spec.rb +37 -0
- data/spec/lib/rubotium/apk/mock/BarcodeScanner4.2.apk +0 -0
- data/spec/lib/rubotium/apk/mock/UECExpress.apk +0 -0
- data/spec/lib/rubotium/apk/mock/dummy.apk +1 -0
- data/spec/lib/rubotium/apk/mock/sample.apk +0 -0
- data/spec/lib/rubotium/device_spec.rb +38 -0
- data/spec/lib/rubotium/devices_spec.rb +41 -24
- data/spec/lib/rubotium/memory/data_point_spec.rb +42 -0
- data/spec/lib/rubotium/memory/monitor_spec.rb +6 -0
- data/spec/lib/rubotium/tests_runner_spec.rb +47 -0
- data/spec/spec_helper.rb +2 -0
- data/test.rb +11 -0
- metadata +62 -41
- data/lib/rubotium/adb/command.rb +0 -21
- data/lib/rubotium/adb/install_command.rb +0 -17
- data/lib/rubotium/adb/instrumentation.rb +0 -36
- data/lib/rubotium/adb/uninstall_command.rb +0 -17
- data/lib/rubotium/apk/converter.rb +0 -22
- data/lib/rubotium/grouper.rb +0 -40
- data/lib/rubotium/jar_reader.rb +0 -70
- data/lib/rubotium/runable_test.rb +0 -11
- data/lib/rubotium/test_case.rb +0 -6
- data/lib/rubotium/test_suite.rb +0 -12
- data/spec/lib/rubotium/adb/adb_instrumentation_spec.rb +0 -32
- data/spec/lib/rubotium/grouper_spec.rb +0 -56
- data/spec/lib/rubotium/jar_reader_spec.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72623c02c54541abecf0431da8b66994b1404a95
|
4
|
+
data.tar.gz: 25d93c5df3c122e59a6fe66f9d848c5be3744556
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42c5267c1aba6a11a8d6e2b5b7d8c813a1690e3479544294847b4c91474e30ae65ec8407685e7bd0fa7c679c146d6cedb5787d5bbc28fefb71b28f2b5341926
|
7
|
+
data.tar.gz: edd630a22f94aa3004f3287b031a40bf3ada2de15e5db653c488016941d868cc44dd9f0e983eba2b5e1a8db96da9b1e8a512dd6e59c84c5e0c7e5d8d91bc3060
|
data/.gitignore
CHANGED
data/bin/rubotium
CHANGED
@@ -10,7 +10,8 @@ opts = Trollop::options do
|
|
10
10
|
opt :rerun, 'Retries count', :default => 0, :short => '-R'
|
11
11
|
opt :out, 'Report file', :default => 'report.xml', :short => '-o'
|
12
12
|
opt :device, 'Match devices', :type => :string, :short => '-d'
|
13
|
-
opt :runner, 'Test runner', :type => :string, :short => 'r'
|
13
|
+
opt :runner, 'Test runner', :type => :string, :short => '-r'
|
14
|
+
opt :annotation, 'Run annotated tests', :type => :string, :short => '-n'
|
14
15
|
end
|
15
16
|
|
16
17
|
params = {
|
@@ -20,7 +21,8 @@ params = {
|
|
20
21
|
:rerun_count => opts[:rerun],
|
21
22
|
:report => opts[:out],
|
22
23
|
:device_matcher => opts[:device],
|
23
|
-
:runner => opts[:runner]
|
24
|
+
:runner => opts[:runner],
|
25
|
+
:annotation => opts[:annotation]
|
24
26
|
}
|
25
27
|
|
26
28
|
Rubotium.new(params)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class Command
|
5
|
+
def initialize(device_serial)
|
6
|
+
@device_serial = device_serial
|
7
|
+
end
|
8
|
+
|
9
|
+
def install(apk_path)
|
10
|
+
execute(install_command(apk_path))
|
11
|
+
end
|
12
|
+
|
13
|
+
def uninstall(package_name)
|
14
|
+
execute(uninstall_command(package_name))
|
15
|
+
end
|
16
|
+
|
17
|
+
def pull(files_glob)
|
18
|
+
execute(pull_command(files_glob))
|
19
|
+
end
|
20
|
+
|
21
|
+
def shell(command)
|
22
|
+
execute(shell_command(command))
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(command_to_run)
|
26
|
+
puts "EXECUTING_COMMAND: #{adb_command} #{command_to_run.executable_command}"
|
27
|
+
CMD.run_command(adb_command + " " + command_to_run.executable_command)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
attr_reader :device_serial
|
32
|
+
|
33
|
+
def adb_command
|
34
|
+
"adb -s #{device_serial} "
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_command(apk_path)
|
38
|
+
Rubotium::Adb::Commands::InstallCommand.new(apk_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def uninstall_command(package_name)
|
42
|
+
Rubotium::Adb::Commands::UninstallCommand.new(package_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def pull_command(files_glob)
|
46
|
+
Rubotium::Adb::Commands::PullCommand.new(files_glob)
|
47
|
+
end
|
48
|
+
|
49
|
+
def shell_command(command)
|
50
|
+
Rubotium::Adb::Commands::ShellCommand.new(command)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class InstallCommand
|
5
|
+
COMMAND = 'install'
|
6
|
+
def initialize(apk_path)
|
7
|
+
@apk_path = apk_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def executable_command
|
11
|
+
"#{COMMAND} #{apk_path}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
attr_reader :apk_path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class InstrumentCommand
|
5
|
+
COMMAND = 'am instrument -w -e class'
|
6
|
+
def initialize(package_name, test_name, test_package_name, test_runner)
|
7
|
+
@package_name = package_name
|
8
|
+
@test_name = test_name
|
9
|
+
@test_package_name = test_package_name
|
10
|
+
@test_runner = test_runner
|
11
|
+
end
|
12
|
+
|
13
|
+
def executable_command
|
14
|
+
[COMMAND, ].join(' ')
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :package_name
|
20
|
+
|
21
|
+
def test_case
|
22
|
+
[package_name, test_name].join('#')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class MemoryCommand
|
5
|
+
COMMAND = 'procrank'
|
6
|
+
def initialize(application_package_name)
|
7
|
+
@application_package_name = application_package_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def executable_command
|
11
|
+
"#{COMMAND} | grep #{application_package_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
attr_reader :application_package_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class PullCommand
|
5
|
+
COMMAND = 'pull'
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def executable_command
|
11
|
+
"#{COMMAND} #{path}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
attr_reader :path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class ShellCommand
|
5
|
+
COMMAND = 'shell'
|
6
|
+
|
7
|
+
def initialize(command)
|
8
|
+
@command = command
|
9
|
+
end
|
10
|
+
|
11
|
+
def executable_command
|
12
|
+
"#{COMMAND} #{command}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :command
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Commands
|
4
|
+
class UninstallCommand
|
5
|
+
COMMAND = 'uninstall'
|
6
|
+
def initialize(package_name)
|
7
|
+
@package_name = package_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def executable_command
|
11
|
+
"#{COMMAND} #{package_name}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
attr_reader :package_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require_relative 'commands/command'
|
2
|
+
require_relative 'commands/install_command'
|
3
|
+
require_relative 'commands/instrument_command'
|
4
|
+
require_relative 'commands/memory_command'
|
5
|
+
require_relative 'commands/pull_command'
|
6
|
+
require_relative 'commands/shell_command'
|
7
|
+
require_relative 'commands/uninstall_command'
|
data/lib/rubotium/adb/devices.rb
CHANGED
@@ -1,15 +1,24 @@
|
|
1
1
|
module Rubotium
|
2
2
|
module Adb
|
3
3
|
class Devices
|
4
|
-
attr_reader :list
|
5
4
|
|
6
|
-
def
|
7
|
-
|
5
|
+
def attached
|
6
|
+
parse.map{|device_serial|
|
7
|
+
create_device(device_serial)
|
8
|
+
}
|
8
9
|
end
|
9
10
|
|
10
11
|
private
|
11
|
-
def
|
12
|
-
|
12
|
+
def create_device(device_serial)
|
13
|
+
Device.new(device_serial)
|
14
|
+
end
|
15
|
+
|
16
|
+
def adb_devices_command
|
17
|
+
CMD.run_command('adb devices', { :timeout => 5 } )
|
18
|
+
end
|
19
|
+
|
20
|
+
def parse
|
21
|
+
list = adb_devices_command.split("\n")
|
13
22
|
list.shift
|
14
23
|
attached_devices list
|
15
24
|
end
|
@@ -22,4 +31,4 @@ module Rubotium
|
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
25
|
-
end
|
34
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
module Rubotium
|
3
|
+
module Adb
|
4
|
+
module Parsers
|
5
|
+
class Procrank
|
6
|
+
|
7
|
+
DEFAULT_RESULT = [0, 0, 0, 0, 0, '']
|
8
|
+
|
9
|
+
def initialize(result)
|
10
|
+
@result = result
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
OpenStruct.new(:pid => pid, :vss => vss, :rss => rss, :pss => pss, :uss => uss, :cmdline => cmdline)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :result
|
20
|
+
def pid
|
21
|
+
split.first.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def vss
|
25
|
+
split[1].to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def rss
|
29
|
+
split[2].to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def pss
|
33
|
+
split[3].to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def uss
|
37
|
+
split[4].to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def cmdline
|
41
|
+
split[-1]
|
42
|
+
end
|
43
|
+
|
44
|
+
def split
|
45
|
+
@split ||= result.empty? ? DEFAULT_RESULT : result.split
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Parsers
|
4
|
+
class SingleTestResultParser
|
5
|
+
STATUS_CODE_PATTERN = Regexp.new('.*INSTRUMENTATION_STATUS_CODE: (-?\d)$', Regexp::MULTILINE)
|
6
|
+
STACK_TRACE__PATTERN = Regexp.new('INSTRUMENTATION_STATUS: stack=(.*)INSTRUMENTATION_STATUS:', Regexp::MULTILINE)
|
7
|
+
TEST_NAME_PATTERN = Regexp.new('INSTRUMENTATION_STATUS: test=(.*)$')
|
8
|
+
CLASS_NAME_PATTERN = Regexp.new('INSTRUMENTATION_STATUS: class=(.*)$')
|
9
|
+
ERROR_STATUS = 'ERROR'
|
10
|
+
FAIL_STATUS = 'FAIL'
|
11
|
+
OK_STATUS = 'OK'
|
12
|
+
|
13
|
+
attr_reader :result, :stack_trace, :time, :error_message, :status, :package_name
|
14
|
+
|
15
|
+
def initialize(test_result)
|
16
|
+
@result = test_result
|
17
|
+
end
|
18
|
+
|
19
|
+
def class_name
|
20
|
+
match_class_name.strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_name
|
24
|
+
match_test_name.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
def failed?
|
28
|
+
result[STATUS_CODE_PATTERN, 1] == '-2'
|
29
|
+
end
|
30
|
+
|
31
|
+
def passed?
|
32
|
+
result[STATUS_CODE_PATTERN, 1] == '0'
|
33
|
+
end
|
34
|
+
|
35
|
+
def errored?
|
36
|
+
result[STATUS_CODE_PATTERN, 1] == '-1'
|
37
|
+
end
|
38
|
+
|
39
|
+
def stack_trace
|
40
|
+
match_stack_trace.strip
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
attr_reader :result
|
46
|
+
|
47
|
+
def match_class_name
|
48
|
+
result[CLASS_NAME_PATTERN, 1]
|
49
|
+
end
|
50
|
+
|
51
|
+
def match_test_name
|
52
|
+
result[TEST_NAME_PATTERN, 1]
|
53
|
+
end
|
54
|
+
|
55
|
+
def match_stack_trace
|
56
|
+
result[STACK_TRACE__PATTERN, 1] || ''
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Rubotium
|
2
|
+
module Adb
|
3
|
+
module Parsers
|
4
|
+
class TestResultsParser
|
5
|
+
PATTERN = Regexp.new('(INSTRUMENTATION_STATUS_CODE: 1.*?INSTRUMENTATION_STATUS_CODE: -?\d)', Regexp::MULTILINE)
|
6
|
+
TIME_PATTERN = Regexp.new('Time: (.*)')
|
7
|
+
SHORT_MESSAGE_PATTERN = Regexp.new('INSTRUMENTATION_RESULT: shortMsg=(.*)')
|
8
|
+
LONG_MESSAGE_PATTERN = Regexp.new('INSTRUMENTATION_RESULT: longMsg=(.*)')
|
9
|
+
ERROR_MESSAGE_PATTERN = Regexp.new('INSTRUMENTATION_STATUS: Error=(.*)')
|
10
|
+
|
11
|
+
def initialize(results)
|
12
|
+
@results = results
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_results
|
16
|
+
tests.map{|result|
|
17
|
+
create_single_test_result_parser(result)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def count
|
22
|
+
tests.count
|
23
|
+
end
|
24
|
+
|
25
|
+
def failed?
|
26
|
+
count == 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def successful?
|
30
|
+
count > 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def time
|
34
|
+
match_time.strip
|
35
|
+
end
|
36
|
+
|
37
|
+
def message
|
38
|
+
[error_message, short_message, long_message].compact.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
attr_reader :results
|
43
|
+
def tests
|
44
|
+
@tests ||= results.scan(PATTERN).flatten
|
45
|
+
end
|
46
|
+
|
47
|
+
def match_time
|
48
|
+
results[TIME_PATTERN, 1] || '0'
|
49
|
+
end
|
50
|
+
|
51
|
+
def error_message
|
52
|
+
results[ERROR_MESSAGE_PATTERN, 1]
|
53
|
+
end
|
54
|
+
|
55
|
+
def short_message
|
56
|
+
results[SHORT_MESSAGE_PATTERN, 1]
|
57
|
+
end
|
58
|
+
|
59
|
+
def long_message
|
60
|
+
results[LONG_MESSAGE_PATTERN, 1]
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_single_test_result_parser(result)
|
64
|
+
Rubotium::Adb::Parsers::SingleTestResultParser.new(result)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -7,10 +7,11 @@ module Rubotium
|
|
7
7
|
|
8
8
|
attr_reader :result, :stack_trace, :time, :error_message, :status, :package_name, :test_name
|
9
9
|
|
10
|
-
def initialize(result,
|
10
|
+
def initialize(result, runnable, device_name)
|
11
|
+
@device = device_name
|
11
12
|
@result = result
|
12
|
-
@package_name = package_name
|
13
|
-
@test_name = test_name
|
13
|
+
@package_name = runnable.package_name
|
14
|
+
@test_name = runnable.test_name
|
14
15
|
parse
|
15
16
|
end
|
16
17
|
|
@@ -84,4 +85,4 @@ module Rubotium
|
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
87
|
-
end
|
88
|
+
end
|
data/lib/rubotium/adb.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require_relative 'adb/
|
2
|
-
require_relative 'adb/install_command'
|
3
|
-
require_relative 'adb/uninstall_command'
|
1
|
+
require_relative 'adb/commands'
|
4
2
|
require_relative 'adb/devices'
|
5
3
|
require_relative 'adb/test_result_parser'
|
6
4
|
require_relative 'adb/shell'
|
7
|
-
require_relative 'adb/
|
5
|
+
require_relative 'adb/parsers'
|
8
6
|
|
9
7
|
module Rubotium
|
10
8
|
module Adb
|
11
9
|
|
12
10
|
end
|
13
|
-
end
|
11
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "tmpdir"
|
2
|
+
require "pp"
|
3
|
+
module Rubotium
|
4
|
+
module Apk
|
5
|
+
require "tmpdir"
|
6
|
+
require "pp"
|
7
|
+
class AndroidApk
|
8
|
+
attr_accessor :results,:label,:labels,:icon,:icons,:package_name,:version_code,:version_name,:sdk_version,:target_sdk_version,:filepath
|
9
|
+
def initialize(path_to_apk)
|
10
|
+
@path = path_to_apk
|
11
|
+
raise(Errno::ENOENT, "File does not exist") unless File.exist?(@path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def package_name
|
15
|
+
parsed_aapt['package']['name']
|
16
|
+
end
|
17
|
+
|
18
|
+
def icon
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def results
|
23
|
+
command = "aapt dump badging \"" + @path + "\" 2>&1"
|
24
|
+
results = `#{command}`
|
25
|
+
if $?.exitstatus != 0 or results.index("ERROR: dump failed")
|
26
|
+
raise(RuntimeError, results)
|
27
|
+
end
|
28
|
+
@results ||= results
|
29
|
+
end
|
30
|
+
|
31
|
+
def parsed_aapt
|
32
|
+
vars = Hash.new
|
33
|
+
results.split("\n").each do |line|
|
34
|
+
key, value = _parse_line(line)
|
35
|
+
next if key.nil?
|
36
|
+
if vars.key?(key)
|
37
|
+
if (vars[key].is_a?(Hash) and value.is_a?(Hash))
|
38
|
+
vars[key].merge(value)
|
39
|
+
else
|
40
|
+
vars[key] = [vars[key]] unless (vars[key].is_a?(Array))
|
41
|
+
if (value.is_a?(Array))
|
42
|
+
vars[key].concat(value)
|
43
|
+
else
|
44
|
+
vars[key].push(value)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
vars[key] = value.nil? ? nil :
|
49
|
+
(value.is_a?(Hash) ? value :
|
50
|
+
(value.length > 1 ? value : value[0]))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
return vars
|
54
|
+
end
|
55
|
+
|
56
|
+
def _parse_values(str)
|
57
|
+
return nil if str.nil?
|
58
|
+
if str.index("='")
|
59
|
+
# key-value hash
|
60
|
+
vars = Hash[str.scan(/(\S+)='((?:\\'|[^'])*)'/)]
|
61
|
+
vars.each_value {|v| v.gsub(/\\'/, "'")}
|
62
|
+
else
|
63
|
+
# values array
|
64
|
+
vars = str.scan(/'((?:\\'|[^'])*)'/).map{|v| v[0].gsub(/\\'/, "'")}
|
65
|
+
end
|
66
|
+
return vars
|
67
|
+
end
|
68
|
+
|
69
|
+
def _parse_line(line)
|
70
|
+
return nil if line.nil?
|
71
|
+
info = line.split(":", 2)
|
72
|
+
return info[0], _parse_values( info[1] )
|
73
|
+
end
|
74
|
+
|
75
|
+
def self._parse_aapt(results)
|
76
|
+
vars = Hash.new
|
77
|
+
results.split("\n").each do |line|
|
78
|
+
key, value = _parse_line(line)
|
79
|
+
next if key.nil?
|
80
|
+
if vars.key?(key)
|
81
|
+
if (vars[key].is_a?(Hash) and value.is_a?(Hash))
|
82
|
+
vars[key].merge(value)
|
83
|
+
else
|
84
|
+
vars[key] = [vars[key]] unless (vars[key].is_a?(Array))
|
85
|
+
if (value.is_a?(Array))
|
86
|
+
vars[key].concat(value)
|
87
|
+
else
|
88
|
+
vars[key].push(value)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
else
|
92
|
+
vars[key] = value.nil? ? nil :
|
93
|
+
(value.is_a?(Hash) ? value :
|
94
|
+
(value.length > 1 ? value : value[0]))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return vars
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
data/lib/rubotium/apk.rb
CHANGED
data/lib/rubotium/cmd.rb
CHANGED
@@ -5,7 +5,7 @@ module Rubotium
|
|
5
5
|
def run_command(command_to_run, opts = {})
|
6
6
|
begin
|
7
7
|
Timeout::timeout(opts[:timeout] || 10 * 60) {
|
8
|
-
|
8
|
+
Rubotium.logger.debug "[EXECUTING]: #{command_to_run}"
|
9
9
|
`#{command_to_run}`
|
10
10
|
}
|
11
11
|
rescue Timeout::Error
|