lib/ruboto/commands/base.rb in ruboto-1.1.2 vs lib/ruboto/commands/base.rb in ruboto-1.2.0
- old
+ new
@@ -17,10 +17,15 @@
module Commands
module Base
include Ruboto::SdkVersions
include Ruboto::Util::Verify
+ # FIXME(uwe): Remove "L" special case
+ API_LEVEL_PATTERN = /^android-(\d+|L)$/
+ API_NUMBER_PATTERN = /(\d+|L)/
+ # EMXIF
+
def self.main
Main do
mode 'gen' do
require 'ruboto/util/update'
@@ -49,18 +54,18 @@
# FIXME(uwe): Change to cast to integer for better comparison
option('target', 't') {
argument :required
defaults DEFAULT_TARGET_SDK
description "Android version to target (e.g., 'android-19' or '19' for kitkat)"
- cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
- validate { |t| t =~ /^android-\d+$/ }
+ cast { |t| t =~ API_NUMBER_PATTERN ? "android-#$1" : t }
+ validate { |t| t =~ API_LEVEL_PATTERN }
}
option('min-sdk') {
argument :required
description "Minimum android version supported. (e.g., 'android-19' or '19' for kitkat)"
- cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
- validate { |t| t =~ /^android-\d+$/ }
+ cast { |t| t =~ API_NUMBER_PATTERN ? "android-#$1" : t }
+ validate { |t| t =~ API_LEVEL_PATTERN }
}
option('with-jruby') {
description 'Install the JRuby jars in your libs directory. Optionally set the JRuby version to install. Otherwise the latest available version is installed.'
argument :optional
cast { |v| Gem::Version.new(v) }
@@ -88,13 +93,16 @@
with_jruby = params['with-jruby'].value
ruby_version = params['ruby-version'].value
force = params['force'].value
abort "Path (#{path}) must be to a directory that does not yet exist. It will be created." if !force && File.exists?(path)
- abort "Target must match android-<number>: got #{target}" unless target =~ /^android-(\d+)$/
- abort "Minimum Android api level is #{MINIMUM_SUPPORTED_SDK}: got #{target}" unless $1.to_i >= MINIMUM_SUPPORTED_SDK_LEVEL
+ abort "Target must match android-<number>: got #{target}" unless target =~ API_LEVEL_PATTERN
+ # FIXME(uwe): Remove the 'L' special case when Android L has been released
+ abort "Minimum Android api level is #{MINIMUM_SUPPORTED_SDK}: got #{target}" unless $1 == 'L' || $1.to_i >= MINIMUM_SUPPORTED_SDK_LEVEL
+ # EMXIF
+
root = File.expand_path(path)
puts "\nGenerating Android app #{name} in #{root}..."
system "android create project -n #{name} -t #{target} -p #{path} -k #{package} -a #{activity}"
exit $?.to_i unless $? == 0
unless File.exists? path
@@ -110,12 +118,12 @@
File.open('res/values/strings.xml', 'w') { |f| verify_strings.document.write(f, 4) }
end
puts 'Done'
Dir.chdir root do
- update_manifest min_sdk[/\d+/], target[/\d+/], true
- update_test true, target[/\d+/].to_i
+ update_manifest min_sdk[API_NUMBER_PATTERN], target[API_NUMBER_PATTERN], true
+ update_test true, target[API_NUMBER_PATTERN]
update_assets
if ruby_version
source = File.read('ruboto.yml')
pattern = %r{^#? ?ruby_version: 1.9$}
@@ -350,12 +358,12 @@
mode 'app' do
# FIXME(uwe): Change to cast to integer for better comparison
option('target', 't') {
argument :required
description "Android version to target (e.g., 'android-19' or '19' for kitkat)"
- cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
- validate { |t| t =~ /^android-\d+$/ }
+ cast { |t| t =~ API_NUMBER_PATTERN ? "android-#$1" : t }
+ validate { |t| t =~ API_LEVEL_PATTERN }
}
option('with-jruby') {
description 'Install the JRuby jars in your libs directory. Optionally set the JRuby version to install. Otherwise the latest available version is installed. If the JRuby jars are already present in your project, this option is implied.'
argument :optional
cast { |v| Gem::Version.new(v) }
@@ -377,13 +385,17 @@
system "ruboto _#{Ruboto::UPDATE_VERSION_LIMIT}_ update app"
raise "Ruboto update app to #{Ruboto::UPDATE_VERSION_LIMIT} failed!" unless $? == 0
end
if (target = params['target'].value)
- abort "Target must match android-<number>: got #{target}" unless target =~ /^android-(\d+)$/
- abort "Minimum Android api level is #{MINIMUM_SUPPORTED_SDK}: got #{target}" unless $1.to_i >= MINIMUM_SUPPORTED_SDK_LEVEL
- target_level = target[/\d+/].to_i
+ abort "Target must match android-<number>: got #{target}" unless target =~ API_LEVEL_PATTERN
+
+ # FIXME(uwe): Remove the 'L' special case when Android L has been released.
+ abort "Minimum Android api level is #{MINIMUM_SUPPORTED_SDK}: got #{target}" unless $1 == 'L' || $1.to_i >= MINIMUM_SUPPORTED_SDK_LEVEL
+ # EMXIF
+
+ target_level = target[API_NUMBER_PATTERN]
update_android(target_level)
update_test force, target_level
else
update_android
update_test force
@@ -427,12 +439,12 @@
option('target', 't') {
description 'sets the target Android API level to set up for (example: -t android-16)'
argument :required
default DEFAULT_TARGET_SDK
arity -1
- cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
- validate { |t| t =~ /^android-\d+$/ }
+ cast { |t| t =~ API_NUMBER_PATTERN ? "android-#$1" : t }
+ validate { |t| t =~ API_LEVEL_PATTERN }
}
option('yes', 'y') {
description 'answer "yes" to all interactive questions. Will automatically install needed components.'
}
@@ -453,11 +465,11 @@
description 'sets the target Android API level for the emulator'
examples Ruboto::SdkVersions::API_LEVEL_TO_VERSION.keys.join(', ')
required unless api_level
argument :required
default(api_level) if api_level
- cast { |t| t =~ /^(\d+)$/ ? "android-#$1" : t }
- validate { |t| t =~ /^android-(\d+)$/ && sdk_level_name($1.to_i) }
+ cast { |t| t =~ API_NUMBER_PATTERN ? "android-#$1" : t }
+ validate { |t| t =~ API_LEVEL_PATTERN && sdk_level_name($1.to_i) }
}
option('no-snapshot', 's') {
extend Ruboto::Util::Emulator
description 'do not use a snapshot when starting the emulator'