lib/ruboto/util/update.rb in ruboto-1.0.3 vs lib/ruboto/util/update.rb in ruboto-1.1.0
- old
+ new
@@ -8,47 +8,61 @@
module Update
include Build
include Ruboto::SdkVersions
include Ruboto::SdkLocations
+ TARGET_VERSION_REGEXP = /^(target=android-)(\d+)$/
+
###########################################################################
#
# Updating components
#
- def update_android
+
+ def update_android(target_level = nil)
root = Dir.getwd
build_xml_file = "#{root}/build.xml"
if File.exists? build_xml_file
- name = REXML::Document.new(File.read(build_xml_file)).root.attributes['name']
+ ant_script = File.read(build_xml_file)
+ name = REXML::Document.new(ant_script).root.attributes['name']
else
name = File.basename(root)
end
+ update_project_properties_target_level("#{root}/project.properties", target_level)
+ system "android update project -p #{root} -n #{name} --subprojects"
+ raise "android update project failed with return code #{$?}" unless $? == 0
+ end
- prop_file = "#{root}/project.properties"
- version_regexp = /^(target=android-)(\d+)$/
- if (project_property_file = File.read(prop_file)) =~ version_regexp
- if $2.to_i < MINIMUM_SUPPORTED_SDK_LEVEL
- puts "Upgrading project to target #{MINIMUM_SUPPORTED_SDK}"
- File.open(prop_file, 'w') { |f| f << project_property_file.gsub(version_regexp, "\\1#{MINIMUM_SUPPORTED_SDK_LEVEL}") }
+ def update_project_properties_target_level(prop_file, target_level)
+ if (project_property_file = File.read(prop_file)) =~ TARGET_VERSION_REGEXP
+ min_sdk = $2.to_i
+ if target_level
+ unless target_level == min_sdk
+ puts "Changing project target from #{min_sdk} to #{MINIMUM_SUPPORTED_SDK_LEVEL}."
+ new_target_level = target_level
+ end
+ elsif min_sdk < MINIMUM_SUPPORTED_SDK_LEVEL
+ puts "Upgrading project target from #{min_sdk} to #{MINIMUM_SUPPORTED_SDK_LEVEL}."
+ new_target_level = MINIMUM_SUPPORTED_SDK_LEVEL
end
+ if new_target_level
+ File.open(prop_file, 'w') { |f| f << project_property_file.gsub(TARGET_VERSION_REGEXP, "\\1#{new_target_level}") }
+ end
end
-
- system "android update project -p #{root} -n #{name} --subprojects"
- raise "android update project failed with return code #{$?}" unless $? == 0
end
- def update_test(force = nil)
+ def update_test(force, target_level = nil)
root = Dir.getwd
if !File.exists?("#{root}/test") || !File.exists?("#{root}/test/AndroidManifest.xml") || !File.exists?("#{root}/test/ant.properties")
name = verify_strings.root.elements['string'].text.gsub(' ', '')
puts "\nGenerating Android test project #{name} in #{root}..."
system %Q{android create test-project -m "#{root.gsub('"', '\"')}" -n "#{name}Test" -p "#{root.gsub('"', '\"')}/test"}
FileUtils.rm_rf File.join(root, 'test', 'src', verify_package.split('.'))
puts 'Done'
end
Dir.chdir File.join(root, 'test') do
+ update_project_properties_target_level('project.properties', target_level)
instrumentation_property = "test.runner=org.ruboto.test.InstrumentationTestRunner\n"
prop_file = 'ant.properties'
prop_lines = (prop_lines_org = File.read(prop_file)).dup
prop_lines.gsub!(/^tested.project.dir=.*$/, 'tested.project.dir=../')
prop_lines << instrumentation_property unless prop_lines.include? instrumentation_property
@@ -130,25 +144,25 @@
raise 'Bad ANT script' unless ant_script.gsub!(/\s*(<\/project>)/, "\n\n#{run_tests_override}\n\n\\1")
File.open('build.xml', 'w') { |f| f << ant_script }
end
end
- def update_jruby(force=nil, explicit = false)
+ def update_jruby(force, version, explicit = false)
installed_jruby_core = Dir.glob('libs/jruby-core-*.jar')[0]
installed_jruby_stdlib = Dir.glob('libs/jruby-stdlib-*.jar')[0]
- unless force
- if !installed_jruby_core || !installed_jruby_stdlib
- puts "Cannot find existing jruby jars in libs. Make sure you're in the root directory of your app." if explicit
- return false
- end
+ unless force || (installed_jruby_core && installed_jruby_stdlib)
+ puts "Cannot find existing jruby jars in libs. Make sure you're in the root directory of your app." if explicit
+ return false
end
- install_jruby_jars_gem
+ install_jruby_jars_gem(version)
begin
+ gem('jruby-jars', version) if version
require 'jruby-jars'
rescue LoadError
+ puts $!
puts "Could not find the jruby-jars gem. You need it to include JRuby in your app. Please install it using\n\n gem install jruby-jars\n\n"
return false
end
new_jruby_version = JRubyJars::VERSION
@@ -165,11 +179,10 @@
copier = AssetCopier.new Ruboto::ASSETS, File.expand_path('.')
log_action("Removing #{installed_jruby_core}") { File.delete *Dir.glob('libs/jruby-core-*.jar') } if installed_jruby_core
log_action("Removing #{installed_jruby_stdlib}") { File.delete *Dir.glob('libs/jruby-stdlib-*.jar') } if installed_jruby_stdlib
log_action("Copying #{JRubyJars::core_jar_path} to libs") { FileUtils.cp JRubyJars::core_jar_path, "libs/jruby-core-#{new_jruby_version}.jar" }
- log_action("Copying #{JRubyJars::stdlib_jar_path} to libs") { FileUtils.cp JRubyJars::stdlib_jar_path, "libs/jruby-stdlib-#{new_jruby_version}.jar" }
unless File.read('project.properties') =~ /^dex.force.jumbo=/
log_action('Setting JUMBO dex file format') do
File.open('project.properties', 'a') { |f| f << "dex.force.jumbo=true\n" }
end
@@ -183,33 +196,25 @@
puts "JRuby version is now: #{new_jruby_version}"
true
end
- def install_jruby_jars_gem
- if (jars_version_from_env = ENV['JRUBY_JARS_VERSION'])
- version_requirement = " -v #{jars_version_from_env}"
+ def install_jruby_jars_gem(jruby_jars_version = ENV['JRUBY_JARS_VERSION'])
+ if jruby_jars_version
+ version_requirement = " -v #{jruby_jars_version}"
end
`gem query -i -n jruby-jars#{version_requirement}`
unless $? == 0
local_gem_dir = ENV['LOCAL_GEM_DIR'] || Dir.getwd
- local_gem_file = "#{local_gem_dir}/jruby-jars-#{jars_version_from_env}.gem"
+ local_gem_file = "#{local_gem_dir}/jruby-jars-#{jruby_jars_version}.gem"
if File.exists?(local_gem_file)
system "gem install -l #{local_gem_file} --no-ri --no-rdoc"
else
system "gem install -r jruby-jars#{version_requirement} --no-ri --no-rdoc"
end
end
raise "install of jruby-jars failed with return code #$?" unless $? == 0
- if jars_version_from_env
- exclusion_clause = %Q{-v "!=#{jars_version_from_env}"}
- `gem query -i -n jruby-jars #{exclusion_clause}`
- if $? == 0
- system %Q{gem uninstall jruby-jars --all #{exclusion_clause}}
- raise "Uninstall of jruby-jars failed with return code #$?" unless $? == 0
- end
- end
Gem.refresh
end
def update_dx_jar(force=nil)
# FIXME(uwe): Remove when we stop updating from Ruboto 0.8.1 and older.
@@ -232,10 +237,16 @@
def update_assets
puts "\nCopying files:"
weak_copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.', false
%w{.gitignore Rakefile ruboto.yml}.each { |f| log_action(f) { weak_copier.copy f } }
+ # FIXME(uwe): Only present in Ruboto 1.0.3. Remove when we stop supporting updating from Ruboto 1.0.3
+ FileUtils.mv('rakelib/stdlib.rake', 'rakelib/ruboto.stdlib.rake') if File.exists?('rakelib/stdlib.rake')
+ FileUtils.mv('rakelib/stdlib.yml', 'rakelib/ruboto.stdlib.yml') if File.exists?('rakelib/stdlib.yml')
+ FileUtils.mv('rakelib/stdlib_dependencies.rb', 'ruboto.stdlib.rb') if File.exists?('rakelib/stdlib_dependencies.rb')
+ # EMXIF
+
copier = Ruboto::Util::AssetCopier.new Ruboto::ASSETS, '.'
%w{assets rakelib res/layout test}.each do |f|
log_action(f) { copier.copy f }
end
end
@@ -322,14 +333,16 @@
end
app_element = verify_manifest.elements['application']
app_element.attributes['android:icon'] ||= '@drawable/ic_launcher'
+ # FIXME(uwe): Simplify when we stop supporting Android 2.3.x
if min_sdk.to_i >= 11
app_element.attributes['android:hardwareAccelerated'] ||= 'true'
app_element.attributes['android:largeHeap'] ||= 'true'
end
+ # EMXIF
unless app_element.elements["activity[@android:name='org.ruboto.RubotoActivity']"]
app_element.add_element 'activity', {'android:name' => 'org.ruboto.RubotoActivity', 'android:exported' => 'false'}
end
@@ -358,11 +371,11 @@
def update_core_classes(force = nil)
generate_core_classes(:class => 'all', :method_base => 'on', :method_include => '', :method_exclude => '', :force => force, :implements => '')
if File.exists?('ruboto.yml')
sleep 1
FileUtils.touch 'ruboto.yml'
- system 'rake jruby_adapter'
+ system 'rake build_xml jruby_adapter'
end
end
def read_ruboto_version
version_file = File.expand_path("./#{SCRIPTS_DIR}/ruboto/version.rb")
@@ -395,18 +408,19 @@
FileUtils.cp "#{new_sources_dir}/#{from}", to
end
end
end
- def reconfigure_jruby_libs(jruby_core_version)
- reconfigure_jruby_core(jruby_core_version)
- reconfigure_jruby_stdlib
+ def reconfigure_jruby_libs(jruby_version)
+ reconfigure_jruby_core(jruby_version)
+ reconfigure_jruby_stdlib(jruby_version)
reconfigure_dx_jar
end
# - Removes unneeded code from jruby-core
# - Split into smaller jars that can be used separately
+ # FIXME(uwe): Refactor to take a Gem::Version as the parameter.
def reconfigure_jruby_core(jruby_core_version)
Dir.chdir 'libs' do
jruby_core = Dir['jruby-core-*.jar'][-1]
log_action("Removing unneeded classes from #{jruby_core}") do
FileUtils.rm_rf 'tmp'
@@ -414,11 +428,11 @@
Dir.chdir 'tmp' do
FileUtils.move "../#{jruby_core}", '.'
`jar -xf #{jruby_core}`
raise "Unpacking jruby-core jar failed: #$?" unless $? == 0
File.delete jruby_core
- gem_version = Gem::Version.new(jruby_core_version.tr('-', '.'))
+ gem_version = Gem::Version.new(jruby_core_version.to_s.tr('-', '.'))
if gem_version >= Gem::Version.new('9000.dev')
#noinspection RubyLiteralArrayInspection
excluded_core_packages = [
'**/*Darwin*',
'**/*Solaris*',
@@ -430,23 +444,26 @@
'com/headius/options/example',
'com/kenai/constantine',
'com/kenai/jffi',
'com/kenai/jnr/x86asm',
'com/martiansoftware',
+ 'com/oracle/truffle',
'jni',
'jnr/constants/platform/darwin',
'jnr/constants/platform/fake',
'jnr/constants/platform/freebsd',
'jnr/constants/platform/openbsd',
'jnr/constants/platform/sunos',
+ 'jnr/enxio',
'jnr/ffi/annotations',
'jnr/ffi/byref',
'jnr/ffi/mapper',
'jnr/ffi/provider',
'jnr/ffi/util',
'jnr/ffi/Struct$*',
'jnr/ffi/types',
+ # 'jnr/netdb',
'jnr/posix/Aix*',
'jnr/posix/FreeBSD*',
'jnr/posix/MacOS*',
'jnr/posix/OpenBSD*',
'jnr/x86asm',
@@ -457,30 +474,37 @@
'org/jruby/compiler/util',
'org/jruby/demo',
'org/jruby/embed/bsf',
'org/jruby/embed/jsr223',
'org/jruby/embed/osgi',
+ 'org/jruby/ext/ffi/Enums*',
# 'org/jruby/ext/tracepoint',
'org/jruby/javasupport/bsf',
# 'org/jruby/management', # should be excluded
# 'org/jruby/runtime/invokedynamic', # Should be excluded
# 'org/jruby/runtime/opto', # What is this?
# 'org/jruby/runtime/opto/OptoFactory*', # What is this?
'org/jruby/truffle',
'org/yecht',
+ 'yaml.rb', # This looks like 1.8 stdlib...
]
elsif gem_version >= Gem::Version.new('1.7.12')
- excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/kenai/constantine com/kenai/jffi com/kenai/jnr/x86asm com/martiansoftware jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/mapper jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/Aix* jnr/posix/FreeBSD* jnr/posix/MacOS* jnr/posix/OpenBSD* jnr/x86asm org/jruby/ant org/jruby/cext org/jruby/compiler/impl/BaseBodyCompiler* org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/AbstractMemory* org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/tracepoint org/jruby/javasupport/bsf org/yecht)
+ excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius/invokebinder com/headius/options/example com/kenai/constantine com/kenai/jffi com/kenai/jnr/x86asm com/martiansoftware jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/enxio jnr/ffi/annotations jnr/ffi/byref jnr/ffi/mapper jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/Aix* jnr/posix/FreeBSD* jnr/posix/MacOS* jnr/posix/OpenBSD* jnr/x86asm org/jruby/ant org/jruby/cext org/jruby/compiler/impl/BaseBodyCompiler* org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/AbstractMemory* org/jruby/ext/ffi/Enums* org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/tracepoint org/jruby/javasupport/bsf org/yecht yaml.rb)
elsif gem_version >= Gem::Version.new('1.7.5')
+ # TODO(uwe): Remove when we stop supporting jruby-jars 1.7.5
excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/kenai/jnr/x86asm com/martiansoftware jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/mapper jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/Aix* jnr/posix/FreeBSD* jnr/posix/MacOS* jnr/posix/OpenBSD* jnr/x86asm org/jruby/ant org/jruby/cext org/jruby/compiler/impl/BaseBodyCompiler* org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/AbstractMemory* org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/tracepoint org/jruby/javasupport/bsf org/yecht)
elsif gem_version >= Gem::Version.new('1.7.4')
+ # TODO(uwe): Remove when we stop supporting jruby-jars 1.7.4
excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/kenai/jnr/x86asm com/martiansoftware jline jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/mapper jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/Aix* jnr/posix/FreeBSD* jnr/posix/MacOS* jnr/posix/OpenBSD* jnr/x86asm org/apache org/fusesource org/jruby/ant org/jruby/cext org/jruby/compiler/impl/BaseBodyCompiler* org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/AbstractMemory* org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/ripper org/jruby/ext/tracepoint org/jruby/javasupport/bsf org/yecht)
elsif gem_version >= Gem::Version.new('1.7.3')
+ # TODO(uwe): Remove when we stop supporting jruby-jars 1.7.3
excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/kenai/jnr/x86asm com/martiansoftware jline jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/FreeBSD* jnr/posix/MacOS* jnr/posix/OpenBSD* jnr/x86asm org/apache org/fusesource org/jruby/ant org/jruby/cext org/jruby/compiler/impl/BaseBodyCompiler* org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/AbstractMemory* org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/javasupport/bsf org/yecht)
elsif gem_version >= Gem::Version.new('1.7.2')
+ # TODO(uwe): Remove when we stop supporting jruby-jars 1.7.2
excluded_core_packages = %w(**/*Darwin* **/*Ruby20* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/martiansoftware jline jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/MacOS* jnr/posix/OpenBSD* org/apache org/fusesource org/jruby/ant org/jruby/cext org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/javasupport/bsf)
elsif gem_version >= Gem::Version.new('1.7.1')
+ # TODO(uwe): Remove when we stop supporting jruby-jars 1.7.1
excluded_core_packages = %w(**/*Darwin* **/*Ruby20* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/martiansoftware jline jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/MacOS* jnr/posix/OpenBSD* org/apache org/fusesource org/jruby/ant org/jruby/cext org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/openssl org/jruby/javasupport/bsf org/jruby/org/bouncycastle)
elsif gem_version >= Gem::Version.new('1.7.0')
# TODO(uwe): Remove when we stop supporting jruby-jars 1.7.0
excluded_core_packages = %w(**/*Darwin* **/*Solaris* **/*windows* **/*Windows* META-INF com/headius com/kenai/constantine com/kenai/jffi com/martiansoftware jline jni jnr/constants/platform/darwin jnr/constants/platform/fake jnr/constants/platform/freebsd jnr/constants/platform/openbsd jnr/constants/platform/sunos jnr/ffi/annotations jnr/ffi/byref jnr/ffi/provider jnr/ffi/util jnr/ffi/Struct$* jnr/ffi/types jnr/posix/MacOS* jnr/posix/OpenBSD* org/apache org/bouncycastle org/fusesource org/jruby/ant org/jruby/cext org/jruby/compiler/util org/jruby/demo org/jruby/embed/bsf org/jruby/embed/jsr223 org/jruby/embed/osgi org/jruby/ext/ffi/io org/jruby/ext/ffi/jffi org/jruby/ext/openssl org/jruby/javasupport/bsf)
# ODOT
@@ -543,11 +567,17 @@
end
end
end
# - Moves ruby stdlib to the root of the jruby-stdlib jar
- def reconfigure_jruby_stdlib
- abort "cannot find rakelib/stdlib.rake; make sure you update your app (ruboto update app)" unless File.exists?("rakelib/stdlib.rake")
+ def reconfigure_jruby_stdlib(jruby_version)
+ # FIXME(uwe): Introduced in Ruboto 1.0.3. Remove when we stop supporting upgrading from Ruboto 1.0.3.
+ unless File.exists?('rakelib/ruboto.stdlib.rake') || File.exists?('rakelib/stdlib.rake')
+ abort 'cannot find rakelib/ruboto.stdlib.rake; make sure you update your app (ruboto update app)'
+ end
+ # EMXIF
+
+ ENV['JRUBY_JARS_VERSION'] = jruby_version
system 'rake libs:reconfigure_stdlib'
end
# - Removes unneeded code from dx.jar
def reconfigure_dx_jar