ruboto-core 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- metadata +16 -88
- data/COPYING +0 -19
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -21
- data/README.md +0 -293
- data/Rakefile +0 -104
- data/assets/Rakefile +0 -386
- data/assets/res/drawable-hdpi/icon.png +0 -0
- data/assets/res/drawable-ldpi/icon.png +0 -0
- data/assets/res/drawable-mdpi/icon.png +0 -0
- data/assets/res/layout/get_ruboto_core.xml +0 -25
- data/assets/samples/sample_activity.rb +0 -21
- data/assets/samples/sample_activity_test.rb +0 -21
- data/assets/samples/sample_broadcast_receiver.rb +0 -6
- data/assets/samples/sample_broadcast_receiver_test.rb +0 -1
- data/assets/samples/sample_service.rb +0 -14
- data/assets/samples/sample_service_test.rb +0 -1
- data/assets/src/InheritingActivity.java +0 -195
- data/assets/src/InheritingBroadcastReceiver.java +0 -27
- data/assets/src/InheritingClass.java +0 -19
- data/assets/src/InheritingService.java +0 -9
- data/assets/src/RubotoActivity.java +0 -111
- data/assets/src/RubotoBroadcastReceiver.java +0 -51
- data/assets/src/RubotoService.java +0 -61
- data/assets/src/org/ruboto/RubotoDialog.java +0 -11
- data/assets/src/org/ruboto/Script.java +0 -509
- data/assets/src/org/ruboto/test/ActivityTest.java +0 -63
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +0 -117
- data/assets/src/ruboto.rb +0 -621
- data/assets/test/assets/scripts/test_helper.rb +0 -13
- data/bin/ruboto +0 -5
- data/lib/java_class_gen/InheritingClass.java.erb +0 -10
- data/lib/java_class_gen/android_api.xml +0 -1
- data/lib/ruboto.rb +0 -16
- data/lib/ruboto/api.rb +0 -21
- data/lib/ruboto/commands/base.rb +0 -392
- data/lib/ruboto/core_ext/array.rb +0 -6
- data/lib/ruboto/core_ext/object.rb +0 -10
- data/lib/ruboto/util/asset_copier.rb +0 -27
- data/lib/ruboto/util/build.rb +0 -201
- data/lib/ruboto/util/code_formatting.rb +0 -22
- data/lib/ruboto/util/log_action.rb +0 -20
- data/lib/ruboto/util/main_fix.rb +0 -13
- data/lib/ruboto/util/objectspace.rb +0 -8
- data/lib/ruboto/util/scan_in_api.rb +0 -40
- data/lib/ruboto/util/update.rb +0 -405
- data/lib/ruboto/util/verify.rb +0 -87
- data/lib/ruboto/util/xml_element.rb +0 -200
- data/lib/ruboto/version.rb +0 -3
- data/test/activity/image_button_activity.rb +0 -21
- data/test/activity/image_button_activity_test.rb +0 -21
- data/test/activity/image_button_and_button_activity.rb +0 -24
- data/test/activity/image_button_and_button_activity_test.rb +0 -27
- data/test/activity/option_menu_activity.rb +0 -21
- data/test/activity/option_menu_activity_test.rb +0 -20
- data/test/activity/stack_activity.rb +0 -21
- data/test/activity/stack_activity_test.rb +0 -23
- data/test/app_test_methods.rb +0 -41
- data/test/minimal_app_test.rb +0 -22
- data/test/rake_test.rb +0 -40
- data/test/ruboto_gen_test.rb +0 -32
- data/test/ruboto_gen_with_psych_test.rb +0 -16
- data/test/ruboto_update_test.rb +0 -5
- data/test/ruboto_update_with_psych_test.rb +0 -18
- data/test/service_test.rb +0 -49
- data/test/test_helper.rb +0 -176
- data/test/update_test_methods.rb +0 -33
data/Rakefile
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
require 'lib/ruboto/version'
|
3
|
-
|
4
|
-
PLATFORM_PROJECT = File.expand_path('tmp/RubotoCore', File.dirname(__FILE__))
|
5
|
-
PLATFORM_DEBUG_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk"
|
6
|
-
PLATFORM_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk"
|
7
|
-
MANIFEST_FILE = "AndroidManifest.xml"
|
8
|
-
GEM_FILE = "ruboto-core-#{Ruboto::VERSION}.gem"
|
9
|
-
GEM_SPEC_FILE = 'ruboto-core.gemspec'
|
10
|
-
|
11
|
-
# FIXME(uwe): Remove when we stop supporting JRuby 1.5.6
|
12
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
|
13
|
-
gem_spec = Gem::Specification.find_by_path 'jruby-jars'
|
14
|
-
else
|
15
|
-
gem_spec = Gem.searcher.find('jruby-jars')
|
16
|
-
end
|
17
|
-
raise StandardError.new("Can't find Gem specification jruby-jars.") unless gem_spec
|
18
|
-
JRUBY_JARS_VERSION = gem_spec.version
|
19
|
-
ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
|
20
|
-
# FIXME end
|
21
|
-
|
22
|
-
|
23
|
-
task :default => :gem
|
24
|
-
|
25
|
-
desc "Generate a gem"
|
26
|
-
task :gem => GEM_FILE
|
27
|
-
|
28
|
-
file GEM_FILE => GEM_SPEC_FILE do
|
29
|
-
puts "Generating #{GEM_FILE}"
|
30
|
-
`gem build #{GEM_SPEC_FILE}`
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Push the gem to RubyGems"
|
34
|
-
task :release => :gem do
|
35
|
-
output = `git status --porcelain`
|
36
|
-
raise "Workspace not clean!\n#{output}" unless output.empty?
|
37
|
-
sh "git tag #{Ruboto::VERSION}"
|
38
|
-
sh "gem push #{Dir['ruboto-core-*.gem'][-1]}"
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "Run the tests"
|
42
|
-
task :test do
|
43
|
-
FileUtils.rm_rf Dir['tmp/RubotoTestApp_template*']
|
44
|
-
Dir['test/*_test.rb'].each do |f|
|
45
|
-
require f.chomp('.rb')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
namespace :platform do
|
50
|
-
desc 'Remove Ruboto Core platform project'
|
51
|
-
task :clean do
|
52
|
-
FileUtils.rm_rf PLATFORM_PROJECT
|
53
|
-
end
|
54
|
-
|
55
|
-
desc 'Generate the Ruboto Core platform project'
|
56
|
-
task :project => PLATFORM_PROJECT
|
57
|
-
|
58
|
-
file PLATFORM_PROJECT do
|
59
|
-
sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} bin/ruboto gen app --package org.ruboto.core --name RubotoCore --with-jruby #{'--with-psych' unless ON_JRUBY_JARS_1_5_6} --path #{PLATFORM_PROJECT}"
|
60
|
-
Dir.chdir(PLATFORM_PROJECT) do
|
61
|
-
manifest = REXML::Document.new(File.read(MANIFEST_FILE))
|
62
|
-
manifest.root.attributes['android:versionCode'] = '407'
|
63
|
-
manifest.root.attributes['android:versionName'] = '0.4.7'
|
64
|
-
manifest.root.attributes['android:installLocation'] = 'auto' # or 'preferExternal' ?
|
65
|
-
manifest.root.elements['uses-sdk'].attributes['android:targetSdkVersion'] = '8'
|
66
|
-
File.open(MANIFEST_FILE, 'w') { |f| manifest.document.write(f, 4) }
|
67
|
-
File.open('project.properties', 'w'){|f| f << "target=android-8\n"}
|
68
|
-
File.open('Gemfile.apk', 'w'){|f| f << "source :rubygems\n\ngem 'activerecord-jdbc-adapter'\n"}
|
69
|
-
keystore_file = File.expand_path('~/android_market.keystore')
|
70
|
-
if File.exists?(keystore_file)
|
71
|
-
File.open('local.properties', 'a'){|f| f << "key.store=#{keystore_file}\nkey.alias=android_market\n"}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
file PLATFORM_DEBUG_APK => PLATFORM_PROJECT do
|
77
|
-
Dir.chdir(PLATFORM_PROJECT) do
|
78
|
-
sh 'rake debug'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
desc 'Generate a Ruboto Core platform release apk'
|
83
|
-
task :release => PLATFORM_RELEASE_APK
|
84
|
-
|
85
|
-
file PLATFORM_RELEASE_APK => PLATFORM_PROJECT do
|
86
|
-
Dir.chdir(PLATFORM_PROJECT) do
|
87
|
-
sh 'rake release'
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
desc 'Install the Ruboto Core platform debug apk'
|
92
|
-
task :install => PLATFORM_DEBUG_APK do
|
93
|
-
Dir.chdir(PLATFORM_PROJECT) do
|
94
|
-
sh 'rake install'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
desc 'Uninstall the Ruboto Core platform debug apk'
|
99
|
-
task :uninstall => PLATFORM_PROJECT do
|
100
|
-
Dir.chdir(PLATFORM_PROJECT) do
|
101
|
-
sh 'rake uninstall'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
data/assets/Rakefile
DELETED
@@ -1,386 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
|
3
|
-
def manifest() @manifest ||= REXML::Document.new(File.read(MANIFEST_FILE)) end
|
4
|
-
def package() manifest.root.attribute('package') end
|
5
|
-
def build_project_name() @build_project_name ||= REXML::Document.new(File.read('build.xml')).elements['project'].attribute(:name).value end
|
6
|
-
def scripts_path() @sdcard_path ||= "/mnt/sdcard/Android/data/#{package}/files/scripts" end
|
7
|
-
def app_files_path() @app_files_path ||= "/data/data/#{package}/files" end
|
8
|
-
|
9
|
-
require 'rake/clean'
|
10
|
-
require 'rexml/document'
|
11
|
-
|
12
|
-
PROJECT_DIR = Dir.getwd
|
13
|
-
UPDATE_MARKER_FILE = File.expand_path(File.join('tmp', 'LAST_UPDATE'), File.dirname(__FILE__))
|
14
|
-
BUNDLE_JAR = File.expand_path 'libs/bundle.jar'
|
15
|
-
BUNDLE_PATH = File.expand_path 'tmp/bundle'
|
16
|
-
MANIFEST_FILE = File.expand_path 'AndroidManifest.xml'
|
17
|
-
RUBOTO_CONFIG_FILE = File.expand_path 'ruboto.yml'
|
18
|
-
GEM_FILE = File.expand_path('Gemfile.apk')
|
19
|
-
GEM_LOCK_FILE = File.expand_path('Gemfile.apk.lock')
|
20
|
-
RELEASE_APK_FILE = File.expand_path "bin/#{build_project_name}-release.apk"
|
21
|
-
APK_FILE = File.expand_path "bin/#{build_project_name}-debug.apk"
|
22
|
-
TEST_APK_FILE = File.expand_path "test/bin/#{build_project_name}Test-debug.apk"
|
23
|
-
JRUBY_JARS = Dir[File.expand_path 'libs/jruby-*.jar']
|
24
|
-
RESOURCE_FILES = Dir[File.expand_path 'res/**/*']
|
25
|
-
JAVA_SOURCE_FILES = Dir[File.expand_path 'src/**/*.java']
|
26
|
-
RUBY_SOURCE_FILES = Dir[File.expand_path 'src/**/*.rb']
|
27
|
-
APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES
|
28
|
-
|
29
|
-
CLEAN.include('tmp', 'bin')
|
30
|
-
|
31
|
-
task :default => :debug
|
32
|
-
|
33
|
-
file JRUBY_JARS => RUBOTO_CONFIG_FILE do
|
34
|
-
next unless File.exists? RUBOTO_CONFIG_FILE
|
35
|
-
jruby_jars_mtime = JRUBY_JARS.map { |f| File.mtime(f) }.min
|
36
|
-
ruboto_yml_mtime = File.mtime(RUBOTO_CONFIG_FILE)
|
37
|
-
next if jruby_jars_mtime > ruboto_yml_mtime
|
38
|
-
puts '*' * 80
|
39
|
-
if JRUBY_JARS.empty?
|
40
|
-
puts ' The JRuby jars are missing.'
|
41
|
-
else
|
42
|
-
puts " The JRuby jars need reconfiguring after changes to #{RUBOTO_CONFIG_FILE}"
|
43
|
-
puts " #{RUBOTO_CONFIG_FILE}: #{ruboto_yml_mtime}"
|
44
|
-
puts " #{JRUBY_JARS.join(', ')}: #{jruby_jars_mtime}"
|
45
|
-
end
|
46
|
-
puts ' Run "ruboto update jruby" to regenerate the JRuby jars'
|
47
|
-
puts '*' * 80
|
48
|
-
end
|
49
|
-
|
50
|
-
desc 'build debug package'
|
51
|
-
task :debug => APK_FILE
|
52
|
-
|
53
|
-
namespace :debug do
|
54
|
-
desc 'build debug package if compiled files have changed'
|
55
|
-
task :quick => [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES do |t|
|
56
|
-
build_apk(t, false)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
desc "build package and install it on the emulator or device"
|
61
|
-
task :install => APK_FILE do
|
62
|
-
install_apk
|
63
|
-
end
|
64
|
-
|
65
|
-
namespace :install do
|
66
|
-
desc 'uninstall, build, and install the application'
|
67
|
-
task :clean => [:uninstall, APK_FILE, :install]
|
68
|
-
|
69
|
-
desc 'Install the application, but only if compiled files are changed.'
|
70
|
-
task :quick => 'debug:quick' do
|
71
|
-
install_apk
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
task :release => RELEASE_APK_FILE
|
76
|
-
|
77
|
-
file RELEASE_APK_FILE => APK_DEPENDENCIES do |t|
|
78
|
-
build_apk(t, true)
|
79
|
-
end
|
80
|
-
|
81
|
-
task :tag => :release do
|
82
|
-
unless `git branch` =~ /^\* master$/
|
83
|
-
puts "You must be on the master branch to release!"
|
84
|
-
exit!
|
85
|
-
end
|
86
|
-
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
87
|
-
sh "git tag #{version}"
|
88
|
-
sh "git push origin master --tags"
|
89
|
-
#sh "gem push pkg/#{name}-#{version}.gem"
|
90
|
-
end
|
91
|
-
|
92
|
-
task :sign => :release do
|
93
|
-
sh "jarsigner -keystore #{ENV['RUBOTO_KEYSTORE']} -signedjar bin/#{build_project_name}.apk bin/#{build_project_name}-unsigned.apk #{ENV['RUBOTO_KEY_ALIAS']}"
|
94
|
-
end
|
95
|
-
|
96
|
-
task :align => :sign do
|
97
|
-
sh "zipalign 4 bin/#{build_project_name}.apk #{build_project_name}.apk"
|
98
|
-
end
|
99
|
-
|
100
|
-
task :publish => :align do
|
101
|
-
puts "#{build_project_name}.apk is ready for the market!"
|
102
|
-
end
|
103
|
-
|
104
|
-
desc 'Start the emulator with larger disk'
|
105
|
-
task :emulator do
|
106
|
-
sh 'emulator -partition-size 1024 -avd Android_3.0'
|
107
|
-
end
|
108
|
-
|
109
|
-
task :start do
|
110
|
-
start_app
|
111
|
-
end
|
112
|
-
|
113
|
-
task :stop do
|
114
|
-
raise "Unable to stop app. Only available on emulator." unless stop_app
|
115
|
-
end
|
116
|
-
|
117
|
-
desc 'Restart the application'
|
118
|
-
task :restart => [:stop, :start]
|
119
|
-
|
120
|
-
task :uninstall do
|
121
|
-
uninstall_apk
|
122
|
-
end
|
123
|
-
|
124
|
-
file MANIFEST_FILE
|
125
|
-
file RUBOTO_CONFIG_FILE
|
126
|
-
|
127
|
-
file APK_FILE => APK_DEPENDENCIES do |t|
|
128
|
-
build_apk(t, false)
|
129
|
-
end
|
130
|
-
|
131
|
-
desc 'Copy scripts to emulator or device'
|
132
|
-
task :update_scripts => ['install:quick'] do
|
133
|
-
update_scripts
|
134
|
-
end
|
135
|
-
|
136
|
-
namespace :update_scripts do
|
137
|
-
desc 'Copy scripts to emulator and restart the app'
|
138
|
-
task :restart => APK_DEPENDENCIES do |t|
|
139
|
-
if stop_app
|
140
|
-
update_scripts
|
141
|
-
else
|
142
|
-
build_apk(t, false)
|
143
|
-
install_apk
|
144
|
-
end
|
145
|
-
start_app
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
task :test => :uninstall do
|
150
|
-
Dir.chdir('test') do
|
151
|
-
puts 'Running tests'
|
152
|
-
sh "adb uninstall #{package}.tests"
|
153
|
-
sh "ant instrument install test"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
namespace :test do
|
158
|
-
task :quick => :update_scripts do
|
159
|
-
Dir.chdir('test') do
|
160
|
-
puts 'Running quick tests'
|
161
|
-
sh 'ant instrument'
|
162
|
-
sh 'ant installi'
|
163
|
-
sh "ant run-tests-quick"
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
file GEM_FILE
|
169
|
-
file GEM_LOCK_FILE
|
170
|
-
|
171
|
-
desc 'Generate bundle jar from Gemfile'
|
172
|
-
task :bundle => BUNDLE_JAR
|
173
|
-
|
174
|
-
file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do
|
175
|
-
next unless File.exists? GEM_FILE
|
176
|
-
puts "Generating #{BUNDLE_JAR}"
|
177
|
-
|
178
|
-
FileUtils.mkdir_p BUNDLE_PATH
|
179
|
-
sh "bundle install --gemfile #{GEM_FILE} --path=#{BUNDLE_PATH}"
|
180
|
-
gem_path = Dir["#{BUNDLE_PATH}/*ruby/1.8/gems"][0]
|
181
|
-
|
182
|
-
if package != 'org.ruboto.core' && JRUBY_JARS.none? { |f| File.exists? f }
|
183
|
-
Dir.chdir gem_path do
|
184
|
-
Dir['activerecord-jdbc-adapter-*'].each do |g|
|
185
|
-
puts "Removing #{g} gem since it is included in the RubotoCore platform apk."
|
186
|
-
FileUtils.rm_rf g
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
# Remove duplicate files
|
192
|
-
Dir.chdir gem_path do
|
193
|
-
scanned_files = []
|
194
|
-
source_files = RUBY_SOURCE_FILES.map { |f| f.gsub("#{PROJECT_DIR}/src/", '') }
|
195
|
-
Dir["*/lib/**/*"].each do |f|
|
196
|
-
next if File.directory? f
|
197
|
-
raise "Malformed file name" unless f =~ %r{^(.*?)/lib/(.*)$}
|
198
|
-
gem_name, lib_file = $1, $2
|
199
|
-
if existing_file = scanned_files.find { |sf| sf =~ %r{(.*?)/lib/#{lib_file}} }
|
200
|
-
puts "Overwriting duplicate file #{lib_file} in gem #{$1} with file in #{gem_name}"
|
201
|
-
FileUtils.rm existing_file
|
202
|
-
scanned_files.delete existing_file
|
203
|
-
elsif source_files.include? lib_file
|
204
|
-
puts "Removing duplicate file #{lib_file} in gem #{gem_name}"
|
205
|
-
puts "Already present in project source src/#{lib_file}"
|
206
|
-
FileUtils.rm f
|
207
|
-
next
|
208
|
-
end
|
209
|
-
scanned_files << f
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
# Expand JARs
|
214
|
-
Dir.chdir gem_path do
|
215
|
-
Dir['*'].each do |gem_lib|
|
216
|
-
Dir.chdir "#{gem_lib}/lib" do
|
217
|
-
Dir['**/*.jar'].each do |jar|
|
218
|
-
unless jar =~ /sqlite-jdbc/
|
219
|
-
puts "Expanding #{gem_lib} #{jar} into #{BUNDLE_JAR}"
|
220
|
-
`jar xf #{jar}`
|
221
|
-
end
|
222
|
-
if jar == 'arjdbc/jdbc/adapter_java.jar'
|
223
|
-
jar_load_code = <<-END_CODE
|
224
|
-
require 'jruby'
|
225
|
-
Java::arjdbc.jdbc.AdapterJavaService.new.basicLoad(JRuby.runtime)
|
226
|
-
END_CODE
|
227
|
-
else
|
228
|
-
jar_load_code = ''
|
229
|
-
end
|
230
|
-
puts "Writing dummy JAR file #{jar + '.rb'}"
|
231
|
-
File.open(jar + '.rb', 'w') { |f| f << jar_load_code }
|
232
|
-
if jar.end_with?('.jar')
|
233
|
-
puts "Writing dummy JAR file #{jar.sub(/.jar$/, '.rb')}"
|
234
|
-
File.open(jar.sub(/.jar$/, '.rb'), 'w') { |f| f << jar_load_code }
|
235
|
-
end
|
236
|
-
FileUtils.rm_f(jar)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
|
243
|
-
FileUtils.rm_f BUNDLE_JAR
|
244
|
-
Dir["#{gem_path}/*"].each_with_index do |gem_dir, i|
|
245
|
-
`jar #{i == 0 ? 'c' : 'u'}f #{BUNDLE_JAR} -C #{gem_dir}/lib .`
|
246
|
-
end
|
247
|
-
FileUtils.rm_rf BUNDLE_PATH
|
248
|
-
end
|
249
|
-
|
250
|
-
# Methods
|
251
|
-
|
252
|
-
def mark_update(time = Time.now)
|
253
|
-
FileUtils.mkdir_p File.dirname(UPDATE_MARKER_FILE)
|
254
|
-
File.open(UPDATE_MARKER_FILE, 'w') { |f| f << time.iso8601 }
|
255
|
-
end
|
256
|
-
|
257
|
-
def clear_update
|
258
|
-
mark_update File.ctime APK_FILE
|
259
|
-
if device_path_exists?(scripts_path)
|
260
|
-
sh "adb shell rm -r #{scripts_path}"
|
261
|
-
puts "Deleted scripts directory #{scripts_path}"
|
262
|
-
end
|
263
|
-
end
|
264
|
-
|
265
|
-
def strings(name)
|
266
|
-
@strings ||= REXML::Document.new(File.read('res/values/strings.xml'))
|
267
|
-
value = @strings.elements["//string[@name='#{name.to_s}']"] or raise "string '#{name}' not found in strings.xml"
|
268
|
-
value.text
|
269
|
-
end
|
270
|
-
|
271
|
-
def version()
|
272
|
-
strings :version_name
|
273
|
-
end
|
274
|
-
|
275
|
-
def app_name()
|
276
|
-
strings :app_name
|
277
|
-
end
|
278
|
-
|
279
|
-
def main_activity()
|
280
|
-
manifest.root.elements['application'].elements["activity[@android:label='@string/app_name']"].attribute('android:name')
|
281
|
-
end
|
282
|
-
|
283
|
-
def device_path_exists?(path)
|
284
|
-
path_output =`adb shell ls #{path}`
|
285
|
-
result = path_output.chomp !~ /No such file or directory|opendir failed, Permission denied/
|
286
|
-
result
|
287
|
-
end
|
288
|
-
|
289
|
-
def package_installed? test = false
|
290
|
-
package_name = "#{package}#{'.tests' if test}"
|
291
|
-
['', '-0', '-1', '-2'].each do |i|
|
292
|
-
p = "/data/app/#{package_name}#{i}.apk"
|
293
|
-
o = `adb shell ls -l #{p}`.chomp
|
294
|
-
if o =~ /^-rw-r--r-- system\s+system\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(p)}$/
|
295
|
-
apk_file = test ? TEST_APK_FILE : APK_FILE
|
296
|
-
if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
|
297
|
-
return true
|
298
|
-
else
|
299
|
-
return false
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
return nil
|
304
|
-
end
|
305
|
-
|
306
|
-
private
|
307
|
-
|
308
|
-
def replace_faulty_code(faulty_file, faulty_code)
|
309
|
-
explicit_requires = Dir["#{faulty_file.chomp('.rb')}/*.rb"].sort.map { |f| File.basename(f) }.map do |filename|
|
310
|
-
"require 'active_model/validations/#{filename}'"
|
311
|
-
end.join("\n")
|
312
|
-
|
313
|
-
old_code = File.read(faulty_file)
|
314
|
-
new_code = old_code.gsub faulty_code, explicit_requires
|
315
|
-
if new_code != old_code
|
316
|
-
puts "Replaced directory listing code in file #{faulty_file} with explicit requires."
|
317
|
-
File.open(faulty_file, 'w') { |f| f << new_code }
|
318
|
-
else
|
319
|
-
puts "Could not find expected faulty code\n\n#{faulty_code}\n\nin file #{faulty_file}\n\n#{old_code}\n\n"
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
def build_apk(t, release)
|
324
|
-
apk_file = release ? RELEASE_APK_FILE : APK_FILE
|
325
|
-
if File.exist?(apk_file)
|
326
|
-
changed_prereqs = t.prerequisites.select do |p|
|
327
|
-
File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(APK_FILE)
|
328
|
-
end
|
329
|
-
return if changed_prereqs.empty?
|
330
|
-
changed_prereqs.each { |f| puts "#{f} changed." }
|
331
|
-
puts "Forcing rebuild of #{apk_file}."
|
332
|
-
end
|
333
|
-
if release
|
334
|
-
sh 'ant release'
|
335
|
-
else
|
336
|
-
sh 'ant debug'
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def install_apk
|
341
|
-
case package_installed?
|
342
|
-
when true
|
343
|
-
puts "Package already installed."
|
344
|
-
return
|
345
|
-
when false
|
346
|
-
puts "Package installed, but of wrong size."
|
347
|
-
end
|
348
|
-
sh 'ant installd'
|
349
|
-
clear_update
|
350
|
-
end
|
351
|
-
|
352
|
-
def uninstall_apk
|
353
|
-
return if package_installed?.nil?
|
354
|
-
puts "Uninstalling package #{package}"
|
355
|
-
system "adb uninstall #{package}"
|
356
|
-
if $? != 0 && package_installed?
|
357
|
-
puts "Uninstall failed exit code #{$?}"
|
358
|
-
exit $?
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def update_scripts
|
363
|
-
`adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path)
|
364
|
-
puts "Pushing files to apk public file area."
|
365
|
-
last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00')
|
366
|
-
# TODO(uwe): Use `adb sync src` instead?
|
367
|
-
Dir.chdir('src') do
|
368
|
-
Dir["**/*.rb"].each do |script_file|
|
369
|
-
next if File.directory? script_file
|
370
|
-
next if File.mtime(script_file) < last_update
|
371
|
-
next if script_file =~ /~$/
|
372
|
-
print "#{script_file}: "; $stdout.flush
|
373
|
-
`adb push #{script_file} #{scripts_path}/#{script_file}`
|
374
|
-
end
|
375
|
-
end
|
376
|
-
mark_update
|
377
|
-
end
|
378
|
-
|
379
|
-
def start_app
|
380
|
-
`adb shell am start -a android.intent.action.MAIN -n #{package}/.#{main_activity}`
|
381
|
-
end
|
382
|
-
|
383
|
-
def stop_app
|
384
|
-
output = `adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
|
385
|
-
return output !~ /Operation not permitted/
|
386
|
-
end
|