apu 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: f79a90e0ddf23a429f6e765d6e6b18e0fd1f68b0
4
- data.tar.gz: f01e40f3220de39a18c0ae1345d7436405e85f67
3
+ metadata.gz: c653f1497cad70c640aee94f45d578d6d34f4e43
4
+ data.tar.gz: c4996f4179474b8b9f6ce176fc363bae223ed663
5
5
  SHA512:
6
- metadata.gz: 1331aea84f604d1f4482a27165b3292557bbf1a459140c7d595ac4a3ae4d1db8755441438f10d061eaeb57631f5b2a8d043d9da3acf762598e3bb8b192f0c31c
7
- data.tar.gz: 924df7fb51761272d74219c149453cbe048ed28f13d960ea77bed83fbf6893c527a0ef1c32b27ec4795878aaf8d16de0ebd308228bf54e0fd155db9781a8177b
6
+ metadata.gz: 2a3b6422b9a9ef788b6a7ac9ef2cefb15d3ca94fb618d14717e0ed9f3bd0b193f060afbb6bdae626a5b829946107726ec547c06a378c202cf498440d5fc8d342
7
+ data.tar.gz: b5959750564111ad9a991d81088d27f9b06313ca26fa793d15354f28cef3e512206c2e2f2f99b8bb6e91c3cf7f8eefb1414dcd0f76ac5ba1e71c13840bcc657e
@@ -1,7 +1,6 @@
1
1
  require 'nokogiri'
2
2
  require 'fileutils'
3
3
  require 'tempfile'
4
- require 'pry'
5
4
 
6
5
  module Apu
7
6
  class AndroidProject
data/lib/apu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Apu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cesar ferreira
@@ -116,7 +116,6 @@ files:
116
116
  - extras/apu.gif
117
117
  - extras/apu2.gif
118
118
  - extras/apu3.gif
119
- - lib/apk-utils/android_project.rb
120
119
  - lib/apu.rb
121
120
  - lib/apu/android_project.rb
122
121
  - lib/apu/version.rb
@@ -1,176 +0,0 @@
1
- require 'nokogiri'
2
- require 'fileutils'
3
- require 'tempfile'
4
- require 'pry'
5
-
6
- module Apu
7
- class AndroidProject
8
- def initialize(path)
9
- @base_path = "#{path}/"
10
- @settings_gradle_path = settings_gradle_file
11
- @modules = find_modules
12
- path, @execute_command = sample_project #supa hack
13
- end
14
-
15
- def execution_line
16
- @execute_command
17
- end
18
-
19
- def remove_local_properties
20
- Dir.chdir @base_path
21
- file_name = 'local.properties'
22
-
23
- File.delete(file_name) if File.exist?(file_name)
24
-
25
- system("touch #{file_name}")
26
- end
27
-
28
- def remove_application_id
29
- # Open temporary file
30
- tmp = Tempfile.new("extract")
31
-
32
- file = "#{@path_to_sample}/build.gradle"
33
-
34
- # Write good lines to temporary file
35
- open(file, 'r').each { |l| tmp << l unless l.include? 'applicationId' }
36
- tmp.close
37
-
38
- # Move temp file to origin
39
- FileUtils.mv(tmp.path, file)
40
- end
41
-
42
- def settings_gradle_file(path = @base_path)
43
- File.join(path, 'settings.gradle')
44
- end
45
-
46
- def is_valid(settings_path = @settings_gradle_path)
47
- File.exist?(settings_path)
48
- end
49
-
50
- def find_modules
51
- return [] unless is_valid
52
-
53
- content = File.open(@settings_gradle_path, "rb").read
54
- modules = content.scan(/'([^']*)'/)
55
- modules.each {|replacement| replacement.first.gsub!(':', '/')}
56
- end
57
-
58
- def install
59
- Dir.chdir @base_path
60
-
61
- path, execute_line = sample_project
62
-
63
- if path == false and execute_line == false
64
- puts "Couldn't open the sample project, sorry!".red
65
- exit 1
66
- end
67
-
68
- builder = "gradle"
69
-
70
- if File.exist?('gradlew')
71
- system('chmod +x gradlew')
72
-
73
- builder = 'sh gradlew'
74
- end
75
-
76
- # Generate the gradle/ folder
77
- system('gradle wrap') if File.exist?('gradlew') and !is_gradle_wrapped
78
-
79
- remove_application_id
80
- remove_local_properties
81
-
82
- system("#{builder} clean installDebug")
83
-
84
- clear_app_data
85
-
86
- puts "Installing #{@package.green}...\n"
87
-
88
- @execute_line = execute_line
89
- end
90
-
91
- def get_execute_line
92
- @execute_line
93
- end
94
-
95
- def is_gradle_wrapped
96
- return false if !File.directory?('gradle/')
97
-
98
- File.exist?('gradle/wrapper/gradle-wrapper.properties') and File.exist?('gradle/wrapper/gradle-wrapper.jar')
99
- end
100
-
101
- def sample_project
102
-
103
- @modules.each do |child|
104
- full_path = File.join(@base_path, child.first)
105
- @path_to_sample = full_path
106
-
107
- execution_line_command = get_execution_line_command(full_path)
108
- return full_path, execution_line_command if execution_line_command
109
-
110
- end
111
- [false, false]
112
- end
113
-
114
- def get_clear_app_command
115
- "adb shell pm clear #{@package}"
116
- end
117
-
118
- def get_uninstall_command
119
- "adb uninstall #{@package}"
120
- end
121
-
122
- def get_package_name
123
- @package
124
- end
125
-
126
- def clear_app_data
127
- system(get_clear_app_command)
128
- end
129
-
130
- def uninstall_application
131
- system(get_uninstall_command) # > /dev/null 2>&1")
132
- end
133
-
134
- def get_execution_line_command(path_to_sample)
135
- path_to_manifest = File.join(path_to_sample, 'src/main/AndroidManifest.xml')
136
-
137
- if !File.exist?(path_to_manifest)
138
- return false
139
- end
140
-
141
- f = File.open(path_to_manifest)
142
- doc = Nokogiri::XML(f)
143
-
144
- @package = get_package(doc)
145
- @launcher_activity = get_launcher_activity(doc)
146
-
147
- if !@launcher_activity
148
- return false
149
- end
150
-
151
- f.close
152
-
153
- "adb shell am start -n \"#{get_launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER"
154
- end
155
-
156
- def get_launchable_activity
157
- full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}"
158
- "#{@package}/#{full_path_to_launcher}"
159
- end
160
-
161
- def get_package(doc)
162
- doc.xpath("//manifest").attr('package').value
163
- end
164
-
165
- def get_launcher_activity(doc)
166
- activities = doc.css('activity')
167
- activities.each do |child|
168
- intent_filter = child.css('intent-filter')
169
- if intent_filter != nil and intent_filter.length != 0
170
- return child.attr('android:name')
171
- end
172
- end
173
- false
174
- end
175
- end
176
- end