Skip to content

Commit

Permalink
* Make 'rake update_scripts:restart' revert to installing the applica…
Browse files Browse the repository at this point in the history
…tion when on non-rooted device

* Bumped RubotoCore version to 0.4.3
  • Loading branch information
donv committed Oct 5, 2011
1 parent b513a5c commit 5fcc786
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -60,7 +60,7 @@ namespace :platform do
Dir.chdir(PLATFORM_PROJECT) do
manifest = REXML::Document.new(File.read(MANIFEST_FILE))
manifest.root.attributes['android:versionCode'] = '3'
manifest.root.attributes['android:versionName'] = '0.4.2'
manifest.root.attributes['android:versionName'] = '0.4.3'
manifest.root.attributes['android:installLocation'] = 'auto' # or 'preferExternal' ?
manifest.root.elements['uses-sdk'].attributes['android:targetSdkVersion'] = '8'
File.open(MANIFEST_FILE, 'w') { |f| manifest.document.write(f, 4) }
Expand Down
58 changes: 40 additions & 18 deletions assets/Rakefile
Expand Up @@ -22,6 +22,7 @@ JRUBY_JARS = Dir[File.expand_path 'libs/jruby-*.jar']
RESOURCE_FILES = Dir[File.expand_path 'res/**/*']
JAVA_SOURCE_FILES = Dir[File.expand_path 'src/**/*.java']
RUBY_SOURCE_FILES = Dir[File.expand_path 'src/**/*.rb']
APK_DEPENDENCIES = [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES

CLEAN.include('tmp', 'bin')

Expand Down Expand Up @@ -102,11 +103,11 @@ task :emulator do
end

task :start do
`adb shell am start -a android.intent.action.MAIN -n #{package}/.#{main_activity}`
start_app
end

task :stop do
`adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
raise "Unable to stop app. Only available on emulator." unless stop_app
end

desc 'Restart the application'
Expand All @@ -119,31 +120,26 @@ end
file MANIFEST_FILE
file RUBOTO_CONFIG_FILE

file APK_FILE => [MANIFEST_FILE, RUBOTO_CONFIG_FILE, BUNDLE_JAR] + JRUBY_JARS + JAVA_SOURCE_FILES + RESOURCE_FILES + RUBY_SOURCE_FILES do |t|
file APK_FILE => APK_DEPENDENCIES do |t|
build_apk(t)
end

desc 'Copy scripts to emulator or device'
task :update_scripts => ['install:quick'] do
`adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path)
puts "Pushing files to apk public file area."
last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00')
# TODO(uwe): Use `adb sync src` instead?
Dir.chdir('src') do
Dir["**/*.rb"].each do |script_file|
next if File.directory? script_file
next if File.mtime(script_file) < last_update
next if script_file =~ /~$/
print "#{script_file}: "; $stdout.flush
`adb push #{script_file} #{scripts_path}/#{script_file}`
end
end
mark_update
update_scripts
end

namespace :update_scripts do
desc 'Copy scripts to emulator and restart the app'
task :restart => [:stop, :update_scripts, :start]
task :restart => APK_DEPENDENCIES do |t|
if stop_app
update_scripts
else
build_apk(t)
install_apk
end
start_app
end
end

task :test => :uninstall do
Expand Down Expand Up @@ -347,3 +343,29 @@ def uninstall_apk
exit $?
end
end

def update_scripts
`adb shell mkdir -p #{scripts_path}` if !device_path_exists?(scripts_path)
puts "Pushing files to apk public file area."
last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00')
# TODO(uwe): Use `adb sync src` instead?
Dir.chdir('src') do
Dir["**/*.rb"].each do |script_file|
next if File.directory? script_file
next if File.mtime(script_file) < last_update
next if script_file =~ /~$/
print "#{script_file}: "; $stdout.flush
`adb push #{script_file} #{scripts_path}/#{script_file}`
end
end
mark_update
end

def start_app
`adb shell am start -a android.intent.action.MAIN -n #{package}/.#{main_activity}`
end

def stop_app
output = `adb shell ps | grep #{package} | awk '{print $2}' | xargs adb shell kill`
return output !~ /Operation not permitted/
end
1 change: 1 addition & 0 deletions test/app_test_methods.rb
Expand Up @@ -11,6 +11,7 @@ def test_activity_tests
end

assert_code 'ReadSourceFile', "File.read(__FILE__)"
assert_code 'DirListsFilesInApk', 'Dir["#{File.dirname(__FILE__)}/*"].each{|f| raise "File #{f.inspect} not found" unless File.exists?(f)}'

Dir[File.expand_path('activity/*_test.rb', File.dirname(__FILE__))].each do |test_src|
snake_name = test_src.chomp('_test.rb')
Expand Down

0 comments on commit 5fcc786

Please sign in to comment.