ruboto 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +9 -9
- data/README.md +2 -0
- data/Rakefile +71 -7
- data/assets/Rakefile +2 -407
- data/assets/libs/dexmaker20120305.jar +0 -0
- data/assets/rakelib/ruboto.rake +428 -0
- data/assets/samples/sample_broadcast_receiver.rb +7 -3
- data/assets/samples/sample_broadcast_receiver_test.rb +47 -1
- data/assets/src/RubotoActivity.java +6 -2
- data/assets/src/org/ruboto/EntryPointActivity.java +2 -2
- data/assets/src/org/ruboto/Script.java +91 -24
- data/assets/src/org/ruboto/test/ActivityTest.java +27 -24
- data/assets/src/org/ruboto/test/InstrumentationTestRunner.java +42 -8
- data/assets/src/ruboto/activity.rb +1 -1
- data/assets/src/ruboto/base.rb +17 -6
- data/assets/src/ruboto/generate.rb +458 -0
- data/assets/src/ruboto/legacy.rb +9 -12
- data/assets/src/ruboto/widget.rb +9 -1
- data/lib/java_class_gen/android_api.xml +1 -1
- data/lib/ruboto.rb +1 -2
- data/lib/ruboto/commands/base.rb +19 -4
- data/lib/ruboto/sdk_versions.rb +12 -0
- data/lib/ruboto/util/build.rb +10 -11
- data/lib/ruboto/util/update.rb +150 -51
- data/lib/ruboto/util/verify.rb +6 -4
- data/lib/ruboto/util/xml_element.rb +2 -2
- data/lib/ruboto/version.rb +1 -1
- data/test/activity/option_menu_activity.rb +5 -1
- data/test/activity/psych_activity.rb +11 -6
- data/test/activity/stack_activity_test.rb +13 -5
- data/test/app_test_methods.rb +4 -3
- data/test/broadcast_receiver_test.rb +86 -0
- data/test/minimal_app_test.rb +27 -19
- data/test/rake_test.rb +13 -2
- data/test/ruboto_gen_test.rb +17 -3
- data/test/ruboto_update_test.rb +24 -2
- data/test/service_test.rb +1 -1
- data/test/test_helper.rb +134 -62
- data/test/update_test_methods.rb +40 -14
- data/test/updated_example_test_methods.rb +41 -0
- metadata +12 -6
data/Gemfile.lock
CHANGED
@@ -2,15 +2,15 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
arrayfields (4.7.4)
|
5
|
-
chronic (0.6.
|
6
|
-
fattr (2.2.
|
7
|
-
jruby-jars (1.6.
|
8
|
-
main (
|
9
|
-
arrayfields (
|
10
|
-
chronic (
|
11
|
-
fattr (
|
12
|
-
map (
|
13
|
-
map (5.
|
5
|
+
chronic (0.6.7)
|
6
|
+
fattr (2.2.1)
|
7
|
+
jruby-jars (1.6.7)
|
8
|
+
main (5.0.1)
|
9
|
+
arrayfields (>= 4.7.4)
|
10
|
+
chronic (>= 0.6.2)
|
11
|
+
fattr (>= 2.2.0)
|
12
|
+
map (>= 5.1.0)
|
13
|
+
map (5.5.0)
|
14
14
|
rake (0.9.2.2)
|
15
15
|
|
16
16
|
PLATFORMS
|
data/README.md
CHANGED
@@ -57,6 +57,8 @@ Ex:
|
|
57
57
|
|
58
58
|
Can subclass any part of the Android API to pass control over to a script when the specified methods are called. You can also create classes that implement a single Android interface to pass control over to ruboto.
|
59
59
|
|
60
|
+
_Note: While the command line calls below still work, there is an easier way to do this within your scripts. The new way of generating interfaces and subclasses is described in the wiki [Generating classes for callbacks](https://github.com/ruboto/ruboto/wiki/Generating-classes-for-callbacks)._
|
61
|
+
|
60
62
|
For classes that need subclassing (e.g., PhoneStateListener, SQLiteOpenHelper, View)
|
61
63
|
|
62
64
|
$ ruboto gen subclass AndroidPackageAndClassName --name YourClassName --method_base all-on-or-none --method_include methods --method_exclude methods
|
data/Rakefile
CHANGED
@@ -1,15 +1,21 @@
|
|
1
|
+
$:.unshift('lib') unless $:.include?('lib')
|
1
2
|
require 'rake/clean'
|
2
3
|
require 'rexml/document'
|
3
|
-
require '
|
4
|
+
require 'ruboto/version'
|
5
|
+
require 'ruboto/sdk_versions'
|
6
|
+
require 'uri'
|
7
|
+
require 'net/http'
|
4
8
|
|
5
9
|
PLATFORM_PROJECT = File.expand_path('tmp/RubotoCore', File.dirname(__FILE__))
|
6
10
|
PLATFORM_DEBUG_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-debug.apk"
|
7
11
|
PLATFORM_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk"
|
12
|
+
PLATFORM_CURRENT_RELEASE_APK = "#{PLATFORM_PROJECT}/bin/RubotoCore-release.apk.current"
|
8
13
|
MANIFEST_FILE = "AndroidManifest.xml"
|
9
14
|
GEM_FILE = "ruboto-#{Ruboto::VERSION}.gem"
|
10
15
|
GEM_FILE_OLD = "ruboto-core-#{Ruboto::VERSION}.gem"
|
11
16
|
GEM_SPEC_FILE = 'ruboto.gemspec'
|
12
17
|
GEM_SPEC_FILE_OLD = 'ruboto-core.gemspec'
|
18
|
+
EXAMPLE_FILE = File.expand_path("examples/RubotoTestApp_#{Ruboto::VERSION}_tools_r#{Ruboto::SdkVersions::ANDROID_TOOLS_REVISION}.tgz", File.dirname(__FILE__))
|
13
19
|
|
14
20
|
CLEAN.include('ruboto-*.gem', 'tmp')
|
15
21
|
|
@@ -28,15 +34,46 @@ file GEM_FILE_OLD => GEM_SPEC_FILE_OLD do
|
|
28
34
|
`gem build #{GEM_SPEC_FILE_OLD}`
|
29
35
|
end
|
30
36
|
|
37
|
+
task :install => :gem do
|
38
|
+
`gem query -i -n ^ruboto$ -v #{Ruboto::VERSION}`
|
39
|
+
if $? != 0
|
40
|
+
cmd = "gem install ruboto-#{Ruboto::VERSION}.gem"
|
41
|
+
output = `#{cmd}`
|
42
|
+
if $? == 0
|
43
|
+
puts output
|
44
|
+
else
|
45
|
+
sh "sudo #{cmd}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Generate an example app"
|
51
|
+
task :example => EXAMPLE_FILE
|
52
|
+
|
53
|
+
file EXAMPLE_FILE => :install do
|
54
|
+
puts "Creating example app #{EXAMPLE_FILE}"
|
55
|
+
app_name = 'RubotoTestApp'
|
56
|
+
Dir.chdir File.dirname(EXAMPLE_FILE) do
|
57
|
+
FileUtils.rm_rf app_name
|
58
|
+
sh "ruboto gen app --package org.ruboto.test_app --name #{app_name} --path #{app_name}"
|
59
|
+
sh "tar czf #{EXAMPLE_FILE} #{app_name}"
|
60
|
+
FileUtils.rm_rf app_name
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
31
64
|
desc "Push the gem to RubyGems"
|
32
|
-
task :release => :gem do
|
65
|
+
task :release => [:clean, :gem] do
|
33
66
|
output = `git status --porcelain`
|
34
67
|
raise "Workspace not clean!\n#{output}" unless output.empty?
|
35
68
|
sh "git tag #{Ruboto::VERSION}"
|
36
69
|
sh "git push --tags"
|
37
70
|
sh "gem push #{GEM_FILE}"
|
38
71
|
sh "gem push #{GEM_FILE_OLD}"
|
39
|
-
|
72
|
+
|
73
|
+
Rake::Task[:example].invoke
|
74
|
+
sh "git add #{EXAMPLE_FILE}"
|
75
|
+
sh "git commit -m '* Added example app for Ruboto #{Ruboto::VERSION} tools r#{Ruboto::SdkVersions::ANDROID_TOOLS_REVISION}' #{EXAMPLE_FILE}"
|
76
|
+
sh "git push"
|
40
77
|
end
|
41
78
|
|
42
79
|
desc "Run the tests"
|
@@ -57,22 +94,33 @@ namespace :platform do
|
|
57
94
|
task :project => PLATFORM_PROJECT
|
58
95
|
|
59
96
|
file PLATFORM_PROJECT do
|
60
|
-
sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} bin/ruboto gen app --package org.ruboto.core --name RubotoCore --with-jruby --path #{PLATFORM_PROJECT}"
|
97
|
+
sh "ruby -rubygems -I#{File.expand_path('lib', File.dirname(__FILE__))} bin/ruboto gen app --package org.ruboto.core --name RubotoCore --with-jruby --path #{PLATFORM_PROJECT} --min-sdk #{Ruboto::SdkVersions::MINIMUM_SUPPORTED_SDK} --target #{Ruboto::SdkVersions::DEFAULT_TARGET_SDK}"
|
61
98
|
Dir.chdir(PLATFORM_PROJECT) do
|
62
99
|
manifest = REXML::Document.new(File.read(MANIFEST_FILE))
|
63
100
|
manifest.root.attributes['android:versionCode'] = '408'
|
64
|
-
manifest.root.attributes['android:versionName'] = '0.4.8'
|
101
|
+
manifest.root.attributes['android:versionName'] = '0.4.8.dev'
|
65
102
|
manifest.root.attributes['android:installLocation'] = 'auto' # or 'preferExternal' ?
|
66
|
-
manifest.root.elements['uses-sdk'].attributes['android:targetSdkVersion'] = '8'
|
67
103
|
File.open(MANIFEST_FILE, 'w') { |f| manifest.document.write(f, 4) }
|
68
|
-
File.open('project.properties', 'w'){|f| f << "target=android-8\n"}
|
69
104
|
File.open('Gemfile.apk', 'w'){|f| f << "source :rubygems\n\ngem 'activerecord-jdbc-adapter'\n"}
|
105
|
+
|
106
|
+
# FIXME(uwe): Add this when either jruby-openssl is simplified or most devices are Android 4
|
107
|
+
# FIXME(uwe): Reeference: #154 and http://code.google.com/p/android/issues/detail?id=22586
|
108
|
+
# File.open('Gemfile.apk', 'w'){|f| f << "gem 'jruby-openssl'\n"}
|
109
|
+
# FIXME end
|
110
|
+
|
70
111
|
File.open('ant.properties', 'a'){|f| f << "key.store=${user.home}/ruboto_core.keystore\nkey.alias=Ruboto\n"}
|
71
112
|
end
|
72
113
|
end
|
73
114
|
|
115
|
+
desc 'Generate a Ruboto Core platform debug apk'
|
116
|
+
task :debug => PLATFORM_DEBUG_APK
|
117
|
+
|
74
118
|
file PLATFORM_DEBUG_APK => PLATFORM_PROJECT do
|
75
119
|
Dir.chdir(PLATFORM_PROJECT) do
|
120
|
+
if File.exists?(PLATFORM_CURRENT_RELEASE_APK) && File.exists?(PLATFORM_DEBUG_APK) &&
|
121
|
+
File.size(PLATFORM_CURRENT_RELEASE_APK) == File.size(PLATFORM_DEBUG_APK)
|
122
|
+
sh 'rake uninstall'
|
123
|
+
end
|
76
124
|
sh 'rake debug'
|
77
125
|
end
|
78
126
|
end
|
@@ -86,6 +134,22 @@ namespace :platform do
|
|
86
134
|
end
|
87
135
|
end
|
88
136
|
|
137
|
+
desc 'Download the current RubotoCore platform release apk'
|
138
|
+
task :current => :debug do
|
139
|
+
Dir.chdir PLATFORM_PROJECT do
|
140
|
+
if !File.exists?(PLATFORM_CURRENT_RELEASE_APK)
|
141
|
+
puts 'Downloading the current RubotoCore platform release apk'
|
142
|
+
url = 'http://cloud.github.com/downloads/ruboto/ruboto/RubotoCore-release.apk'
|
143
|
+
File.open(PLATFORM_CURRENT_RELEASE_APK, 'w') { |f| f << Net::HTTP.get(URI.parse url) }
|
144
|
+
end
|
145
|
+
|
146
|
+
if File.size(PLATFORM_CURRENT_RELEASE_APK) != File.size(PLATFORM_DEBUG_APK)
|
147
|
+
FileUtils.cp PLATFORM_CURRENT_RELEASE_APK, PLATFORM_DEBUG_APK
|
148
|
+
sh 'rake uninstall'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
89
153
|
desc 'Install the Ruboto Core platform debug apk'
|
90
154
|
task :install => PLATFORM_DEBUG_APK do
|
91
155
|
Dir.chdir(PLATFORM_PROJECT) do
|
data/assets/Rakefile
CHANGED
@@ -1,407 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exit 1
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'time'
|
7
|
-
|
8
|
-
def manifest() @manifest ||= REXML::Document.new(File.read(MANIFEST_FILE)) end
|
9
|
-
def package() manifest.root.attribute('package') end
|
10
|
-
def build_project_name() @build_project_name ||= REXML::Document.new(File.read('build.xml')).elements['project'].attribute(:name).value end
|
11
|
-
def scripts_path() @sdcard_path ||= "/mnt/sdcard/Android/data/#{package}/files/scripts" end
|
12
|
-
def app_files_path() @app_files_path ||= "/data/data/#{package}/files" end
|
13
|
-
|
14
|
-
require 'rake/clean'
|
15
|
-
require 'rexml/document'
|
16
|
-
|
17
|
-
PROJECT_DIR = Dir.getwd
|
18
|
-
UPDATE_MARKER_FILE = File.expand_path(File.join('bin', 'LAST_UPDATE'), File.dirname(__FILE__))
|
19
|
-
BUNDLE_JAR = File.expand_path 'libs/bundle.jar'
|
20
|
-
BUNDLE_PATH = File.expand_path 'bin/bundle'
|
21
|
-
MANIFEST_FILE = File.expand_path 'AndroidManifest.xml'
|
22
|
-
RUBOTO_CONFIG_FILE = File.expand_path 'ruboto.yml'
|
23
|
-
GEM_FILE = File.expand_path('Gemfile.apk')
|
24
|
-
GEM_LOCK_FILE = File.expand_path('Gemfile.apk.lock')
|
25
|
-
RELEASE_APK_FILE = File.expand_path "bin/#{build_project_name}-release.apk"
|
26
|
-
APK_FILE = File.expand_path "bin/#{build_project_name}-debug.apk"
|
27
|
-
TEST_APK_FILE = File.expand_path "test/bin/#{build_project_name}Test-debug.apk"
|
28
|
-
JRUBY_JARS = Dir[File.expand_path 'libs/jruby-*.jar']
|
29
|
-
RESOURCE_FILES = Dir[File.expand_path 'res/**/*']
|
30
|
-
JAVA_SOURCE_FILES = Dir[File.expand_path 'src/**/*.java']
|
31
|
-
RUBY_SOURCE_FILES = Dir[File.expand_path 'src/**/*.rb']
|
32
|
-
APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES
|
33
|
-
KEYSTORE_FILE = (key_store = File.readlines('ant.properties').grep(/^key.store=/).first) ? key_store.chomp.sub(/^key.store=/, '') : "#{build_project_name}.keystore"
|
34
|
-
KEYSTORE_ALIAS = (key_alias = File.readlines('ant.properties').grep(/^key.alias=/).first) ? key_alias.chomp.sub(/^key.alias=/, '') : build_project_name
|
35
|
-
|
36
|
-
CLEAN.include('bin')
|
37
|
-
|
38
|
-
task :default => :debug
|
39
|
-
|
40
|
-
file JRUBY_JARS => RUBOTO_CONFIG_FILE do
|
41
|
-
next unless File.exists? RUBOTO_CONFIG_FILE
|
42
|
-
jruby_jars_mtime = JRUBY_JARS.map { |f| File.mtime(f) }.min
|
43
|
-
ruboto_yml_mtime = File.mtime(RUBOTO_CONFIG_FILE)
|
44
|
-
next if jruby_jars_mtime > ruboto_yml_mtime
|
45
|
-
puts '*' * 80
|
46
|
-
if JRUBY_JARS.empty?
|
47
|
-
puts ' The JRuby jars are missing.'
|
48
|
-
else
|
49
|
-
puts " The JRuby jars need reconfiguring after changes to #{RUBOTO_CONFIG_FILE}"
|
50
|
-
puts " #{RUBOTO_CONFIG_FILE}: #{ruboto_yml_mtime}"
|
51
|
-
puts " #{JRUBY_JARS.join(', ')}: #{jruby_jars_mtime}"
|
52
|
-
end
|
53
|
-
puts ' Run "ruboto update jruby" to regenerate the JRuby jars'
|
54
|
-
puts '*' * 80
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'build debug package'
|
58
|
-
task :debug => APK_FILE
|
59
|
-
|
60
|
-
namespace :debug do
|
61
|
-
desc 'build debug package if compiled files have changed'
|
62
|
-
task :quick => [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES do |t|
|
63
|
-
build_apk(t, false)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
desc "build package and install it on the emulator or device"
|
68
|
-
task :install => APK_FILE do
|
69
|
-
install_apk
|
70
|
-
end
|
71
|
-
|
72
|
-
namespace :install do
|
73
|
-
desc 'uninstall, build, and install the application'
|
74
|
-
task :clean => [:uninstall, APK_FILE, :install]
|
75
|
-
|
76
|
-
desc 'Install the application, but only if compiled files are changed.'
|
77
|
-
task :quick => 'debug:quick' do
|
78
|
-
install_apk
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
desc 'Build APK for release'
|
83
|
-
task :release => RELEASE_APK_FILE
|
84
|
-
|
85
|
-
file RELEASE_APK_FILE => [KEYSTORE_FILE] + APK_DEPENDENCIES do |t|
|
86
|
-
build_apk(t, true)
|
87
|
-
end
|
88
|
-
|
89
|
-
desc 'Create a keystore for signing the release APK'
|
90
|
-
file KEYSTORE_FILE do
|
91
|
-
unless File.read('ant.properties') =~ /^key.store=/
|
92
|
-
File.open('ant.properties', 'a'){|f| f << "\nkey.store=#{KEYSTORE_FILE}\n"}
|
93
|
-
end
|
94
|
-
unless File.read('ant.properties') =~ /^key.alias=/
|
95
|
-
File.open('ant.properties', 'a'){|f| f << "\nkey.alias=#{KEYSTORE_ALIAS}\n"}
|
96
|
-
end
|
97
|
-
sh "keytool -genkey -v -keystore #{KEYSTORE_FILE} -alias #{KEYSTORE_ALIAS} -keyalg RSA -keysize 2048 -validity 10000"
|
98
|
-
end
|
99
|
-
|
100
|
-
desc 'Tag this working copy with the current version'
|
101
|
-
task :tag => :release do
|
102
|
-
unless `git branch` =~ /^\* master$/
|
103
|
-
puts "You must be on the master branch to release!"
|
104
|
-
exit!
|
105
|
-
end
|
106
|
-
# sh "git commit --allow-empty -a -m 'Release #{version}'"
|
107
|
-
output = `git status --porcelain`
|
108
|
-
raise "Workspace not clean!\n#{output}" unless output.empty?
|
109
|
-
sh "git tag #{version}"
|
110
|
-
sh "git push origin master --tags"
|
111
|
-
end
|
112
|
-
|
113
|
-
task :sign => :release do
|
114
|
-
sh "jarsigner -keystore #{ENV['RUBOTO_KEYSTORE']} -signedjar bin/#{build_project_name}.apk bin/#{build_project_name}-unsigned.apk #{ENV['RUBOTO_KEY_ALIAS']}"
|
115
|
-
end
|
116
|
-
|
117
|
-
task :align => :sign do
|
118
|
-
sh "zipalign 4 bin/#{build_project_name}.apk #{build_project_name}.apk"
|
119
|
-
end
|
120
|
-
|
121
|
-
task :publish => :align do
|
122
|
-
puts "#{build_project_name}.apk is ready for the market!"
|
123
|
-
end
|
124
|
-
|
125
|
-
desc 'Start the emulator with larger disk'
|
126
|
-
task :emulator do
|
127
|
-
sh 'emulator -partition-size 1024 -avd Android_3.0'
|
128
|
-
end
|
129
|
-
|
130
|
-
task :start do
|
131
|
-
start_app
|
132
|
-
end
|
133
|
-
|
134
|
-
task :stop do
|
135
|
-
raise "Unable to stop app. Only available on emulator." unless stop_app
|
136
|
-
end
|
137
|
-
|
138
|
-
desc 'Restart the application'
|
139
|
-
task :restart => [:stop, :start]
|
140
|
-
|
141
|
-
task :uninstall do
|
142
|
-
uninstall_apk
|
143
|
-
end
|
144
|
-
|
145
|
-
file MANIFEST_FILE
|
146
|
-
file RUBOTO_CONFIG_FILE
|
147
|
-
|
148
|
-
file APK_FILE => APK_DEPENDENCIES do |t|
|
149
|
-
build_apk(t, false)
|
150
|
-
end
|
151
|
-
|
152
|
-
desc 'Copy scripts to emulator or device'
|
153
|
-
task :update_scripts => ['install:quick'] do
|
154
|
-
update_scripts
|
155
|
-
end
|
156
|
-
|
157
|
-
namespace :update_scripts do
|
158
|
-
desc 'Copy scripts to emulator and restart the app'
|
159
|
-
task :restart => APK_DEPENDENCIES do |t|
|
160
|
-
if build_apk(t, false) || !stop_app
|
161
|
-
install_apk
|
162
|
-
else
|
163
|
-
update_scripts
|
164
|
-
end
|
165
|
-
start_app
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
task :test => :uninstall do
|
170
|
-
Dir.chdir('test') do
|
171
|
-
puts 'Running tests'
|
172
|
-
sh "adb uninstall #{package}.tests"
|
173
|
-
sh "ant instrument install test"
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
namespace :test do
|
178
|
-
task :quick => :update_scripts do
|
179
|
-
Dir.chdir('test') do
|
180
|
-
puts 'Running quick tests'
|
181
|
-
sh 'ant instrument'
|
182
|
-
sh 'ant installi'
|
183
|
-
sh "ant run-tests-quick"
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
file GEM_FILE
|
189
|
-
file GEM_LOCK_FILE
|
190
|
-
|
191
|
-
desc 'Generate bundle jar from Gemfile'
|
192
|
-
task :bundle => BUNDLE_JAR
|
193
|
-
|
194
|
-
file BUNDLE_JAR => [GEM_FILE, GEM_LOCK_FILE] do
|
195
|
-
next unless File.exists? GEM_FILE
|
196
|
-
puts "Generating #{BUNDLE_JAR}"
|
197
|
-
|
198
|
-
FileUtils.mkdir_p BUNDLE_PATH
|
199
|
-
sh "bundle install --gemfile #{GEM_FILE} --path=#{BUNDLE_PATH}"
|
200
|
-
gem_path = Dir["#{BUNDLE_PATH}/*ruby/1.8/gems"][0]
|
201
|
-
|
202
|
-
if package != 'org.ruboto.core' && JRUBY_JARS.none? { |f| File.exists? f }
|
203
|
-
Dir.chdir gem_path do
|
204
|
-
Dir['activerecord-jdbc-adapter-*'].each do |g|
|
205
|
-
puts "Removing #{g} gem since it is included in the RubotoCore platform apk."
|
206
|
-
FileUtils.rm_rf g
|
207
|
-
end
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# Remove duplicate files
|
212
|
-
Dir.chdir gem_path do
|
213
|
-
scanned_files = []
|
214
|
-
source_files = RUBY_SOURCE_FILES.map { |f| f.gsub("#{PROJECT_DIR}/src/", '') }
|
215
|
-
Dir["*/lib/**/*"].each do |f|
|
216
|
-
next if File.directory? f
|
217
|
-
raise "Malformed file name" unless f =~ %r{^(.*?)/lib/(.*)$}
|
218
|
-
gem_name, lib_file = $1, $2
|
219
|
-
if existing_file = scanned_files.find { |sf| sf =~ %r{(.*?)/lib/#{lib_file}} }
|
220
|
-
puts "Overwriting duplicate file #{lib_file} in gem #{$1} with file in #{gem_name}"
|
221
|
-
FileUtils.rm existing_file
|
222
|
-
scanned_files.delete existing_file
|
223
|
-
elsif source_files.include? lib_file
|
224
|
-
puts "Removing duplicate file #{lib_file} in gem #{gem_name}"
|
225
|
-
puts "Already present in project source src/#{lib_file}"
|
226
|
-
FileUtils.rm f
|
227
|
-
next
|
228
|
-
end
|
229
|
-
scanned_files << f
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
# Expand JARs
|
234
|
-
Dir.chdir gem_path do
|
235
|
-
Dir['*'].each do |gem_lib|
|
236
|
-
Dir.chdir "#{gem_lib}/lib" do
|
237
|
-
Dir['**/*.jar'].each do |jar|
|
238
|
-
unless jar =~ /sqlite-jdbc/
|
239
|
-
puts "Expanding #{gem_lib} #{jar} into #{BUNDLE_JAR}"
|
240
|
-
`jar xf #{jar}`
|
241
|
-
end
|
242
|
-
if jar == 'arjdbc/jdbc/adapter_java.jar'
|
243
|
-
jar_load_code = <<-END_CODE
|
244
|
-
require 'jruby'
|
245
|
-
Java::arjdbc.jdbc.AdapterJavaService.new.basicLoad(JRuby.runtime)
|
246
|
-
END_CODE
|
247
|
-
else
|
248
|
-
jar_load_code = ''
|
249
|
-
end
|
250
|
-
puts "Writing dummy JAR file #{jar + '.rb'}"
|
251
|
-
File.open(jar + '.rb', 'w') { |f| f << jar_load_code }
|
252
|
-
if jar.end_with?('.jar')
|
253
|
-
puts "Writing dummy JAR file #{jar.sub(/.jar$/, '.rb')}"
|
254
|
-
File.open(jar.sub(/.jar$/, '.rb'), 'w') { |f| f << jar_load_code }
|
255
|
-
end
|
256
|
-
FileUtils.rm_f(jar)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
|
263
|
-
FileUtils.rm_f BUNDLE_JAR
|
264
|
-
Dir["#{gem_path}/*"].each_with_index do |gem_dir, i|
|
265
|
-
`jar #{i == 0 ? 'c' : 'u'}f #{BUNDLE_JAR} -C #{gem_dir}/lib .`
|
266
|
-
end
|
267
|
-
FileUtils.rm_rf BUNDLE_PATH
|
268
|
-
end
|
269
|
-
|
270
|
-
# Methods
|
271
|
-
|
272
|
-
def mark_update(time = Time.now)
|
273
|
-
FileUtils.mkdir_p File.dirname(UPDATE_MARKER_FILE)
|
274
|
-
File.open(UPDATE_MARKER_FILE, 'w') { |f| f << time.iso8601 }
|
275
|
-
end
|
276
|
-
|
277
|
-
def clear_update
|
278
|
-
mark_update File.ctime APK_FILE
|
279
|
-
if device_path_exists?(scripts_path)
|
280
|
-
sh "adb shell rm -r #{scripts_path}"
|
281
|
-
puts "Deleted scripts directory #{scripts_path}"
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def strings(name)
|
286
|
-
@strings ||= REXML::Document.new(File.read('res/values/strings.xml'))
|
287
|
-
value = @strings.elements["//string[@name='#{name.to_s}']"] or raise "string '#{name}' not found in strings.xml"
|
288
|
-
value.text
|
289
|
-
end
|
290
|
-
|
291
|
-
def version()
|
292
|
-
strings :version_name
|
293
|
-
end
|
294
|
-
|
295
|
-
def app_name()
|
296
|
-
strings :app_name
|
297
|
-
end
|
298
|
-
|
299
|
-
def main_activity()
|
300
|
-
manifest.root.elements['application'].elements["activity[@android:label='@string/app_name']"].attribute('android:name')
|
301
|
-
end
|
302
|
-
|
303
|
-
def device_path_exists?(path)
|
304
|
-
path_output =`adb shell ls #{path}`
|
305
|
-
result = path_output.chomp !~ /No such file or directory|opendir failed, Permission denied/
|
306
|
-
result
|
307
|
-
end
|
308
|
-
|
309
|
-
def package_installed? test = false
|
310
|
-
package_name = "#{package}#{'.tests' if test}"
|
311
|
-
['', '-0', '-1', '-2'].each do |i|
|
312
|
-
p = "/data/app/#{package_name}#{i}.apk"
|
313
|
-
o = `adb shell ls -l #{p}`.chomp
|
314
|
-
if o =~ /^-rw-r--r-- system\s+system\s+(\d+) \d{4}-\d{2}-\d{2} \d{2}:\d{2} #{File.basename(p)}$/
|
315
|
-
apk_file = test ? TEST_APK_FILE : APK_FILE
|
316
|
-
if !File.exists?(apk_file) || $1.to_i == File.size(apk_file)
|
317
|
-
return true
|
318
|
-
else
|
319
|
-
return false
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
return nil
|
324
|
-
end
|
325
|
-
|
326
|
-
private
|
327
|
-
|
328
|
-
def replace_faulty_code(faulty_file, faulty_code)
|
329
|
-
explicit_requires = Dir["#{faulty_file.chomp('.rb')}/*.rb"].sort.map { |f| File.basename(f) }.map do |filename|
|
330
|
-
"require 'active_model/validations/#{filename}'"
|
331
|
-
end.join("\n")
|
332
|
-
|
333
|
-
old_code = File.read(faulty_file)
|
334
|
-
new_code = old_code.gsub faulty_code, explicit_requires
|
335
|
-
if new_code != old_code
|
336
|
-
puts "Replaced directory listing code in file #{faulty_file} with explicit requires."
|
337
|
-
File.open(faulty_file, 'w') { |f| f << new_code }
|
338
|
-
else
|
339
|
-
puts "Could not find expected faulty code\n\n#{faulty_code}\n\nin file #{faulty_file}\n\n#{old_code}\n\n"
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
def build_apk(t, release)
|
344
|
-
apk_file = release ? RELEASE_APK_FILE : APK_FILE
|
345
|
-
if File.exist?(apk_file)
|
346
|
-
changed_prereqs = t.prerequisites.select do |p|
|
347
|
-
File.file?(p) && !Dir[p].empty? && Dir[p].map { |f| File.mtime(f) }.max > File.mtime(APK_FILE)
|
348
|
-
end
|
349
|
-
return false if changed_prereqs.empty?
|
350
|
-
changed_prereqs.each { |f| puts "#{f} changed." }
|
351
|
-
puts "Forcing rebuild of #{apk_file}."
|
352
|
-
end
|
353
|
-
if release
|
354
|
-
sh 'ant release'
|
355
|
-
else
|
356
|
-
sh 'ant debug'
|
357
|
-
end
|
358
|
-
return true
|
359
|
-
end
|
360
|
-
|
361
|
-
def install_apk
|
362
|
-
case package_installed?
|
363
|
-
when true
|
364
|
-
puts "Package already installed."
|
365
|
-
return
|
366
|
-
when false
|
367
|
-
puts "Package installed, but of wrong size."
|
368
|
-
end
|
369
|
-
sh 'ant installd'
|
370
|
-
clear_update
|
371
|
-
end
|
372
|
-
|
373
|
-
def uninstall_apk
|
374
|
-
return if package_installed?.nil?
|
375
|
-
puts "Uninstalling package #{package}"
|
376
|
-
system "adb uninstall #{package}"
|
377
|
-
if $? != 0 && package_installed?
|
378
|
-
puts "Uninstall failed exit code #{$?}"
|
379
|
-
exit $?
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
def update_scripts
|
384
|
-
`adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path)
|
385
|
-
puts "Pushing files to apk public file area."
|
386
|
-
last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00')
|
387
|
-
# TODO(uwe): Use `adb sync src` instead?
|
388
|
-
Dir.chdir('src') do
|
389
|
-
Dir["**/*.rb"].each do |script_file|
|
390
|
-
next if File.directory? script_file
|
391
|
-
next if File.mtime(script_file) < last_update
|
392
|
-
next if script_file =~ /~$/
|
393
|
-
print "#{script_file}: "; $stdout.flush
|
394
|
-
`adb push #{script_file} #{scripts_path}/#{script_file}`
|
395
|
-
end
|
396
|
-
end
|
397
|
-
mark_update
|
398
|
-
end
|
399
|
-
|
400
|
-
def start_app
|
401
|
-
`adb shell am start -a android.intent.action.MAIN -n #{package}/.#{main_activity}`
|
402
|
-
end
|
403
|
-
|
404
|
-
def stop_app
|
405
|
-
output = `adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
|
406
|
-
return output !~ /Operation not permitted/
|
407
|
-
end
|
1
|
+
# Write your own rake tasks here.
|
2
|
+
# You can find the Ruboto rake tasks in rakelib/ruboto.rake
|