lib/ruboto/util/build.rb in ruboto-1.0.0 vs lib/ruboto/util/build.rb in ruboto-1.0.1
- old
+ new
@@ -1,11 +1,11 @@
module Ruboto
module Util
module Build
include Verify
SCRIPTS_DIR = 'src'
-
+
###########################################################################
#
# Build Subclass or Interface:
#
@@ -17,13 +17,13 @@
def build_file(src, package, name, substitutions, dest='.')
to = File.join(dest, "src/#{package.gsub('.', '/')}")
Dir.mkdir(to) unless File.directory?(to)
text = File.read(File.expand_path(Ruboto::GEM_ROOT + "/assets/src/#{src}.java"))
- substitutions.each {|k,v| text.gsub!(k, v)}
+ substitutions.each { |k, v| text.gsub!(k, v) }
- File.open(File.join(to, "#{name}.java"), 'w') {|f| f << text}
+ File.open(File.join(to, "#{name}.java"), 'w') { |f| f << text }
end
#
# get_class_or_interface: Opens the xml file and locates the specified class.
# Aborts if the class is not found or if it is not available for
@@ -33,18 +33,15 @@
element = verify_api.find_class_or_interface(klass, 'either')
abort "ERROR: #{klass} not found" unless element
unless force == 'include'
- abort "#{klass} not available in minSdkVersion, added in #{element.attribute('api_added')}; use '--force include' to create it" if
- element.attribute('api_added') and element.attribute('api_added').to_i > verify_min_sdk.to_i
- abort "#{klass} deprecated for targetSdkVersion, deprecated in #{element.attribute('deprecated')}; use '--force include' to create it" if
- element.attribute('deprecated') and element.attribute('deprecated').to_i <= verify_target_sdk.to_i
+ abort "#{klass} not available in minSdkVersion, added in #{element.attribute('api_added')}; use '--force include' to create it" if element.attribute('api_added') and element.attribute('api_added').to_i > verify_min_sdk.to_i
+ abort "#{klass} deprecated for targetSdkVersion, deprecated in #{element.attribute('deprecated')}; use '--force include' to create it" if element.attribute('deprecated') and element.attribute('deprecated').to_i <= verify_target_sdk.to_i
end
- abort "#{klass} removed for targetSdkVersion, removed in #{element.attribute('api_removed')}" if
- element.attribute('api_removed') and element.attribute('api_removed').to_i <= verify_target_sdk.to_i
+ abort "#{klass} removed for targetSdkVersion, removed in #{element.attribute('api_removed')}" if element.attribute('api_removed') and element.attribute('api_removed').to_i <= verify_target_sdk.to_i
element
end
#
@@ -53,13 +50,13 @@
def check_methods(methods, force=nil)
min_api = verify_min_sdk.to_i
target_api = verify_target_sdk.to_i
# Remove methods changed outside of the scope of the sdk versions
- methods = methods.select{|i| !i.attribute('api_added') || (i.attribute('api_added').to_i <= target_api)}
+ methods = methods.select { |i| !i.attribute('api_added') || (i.attribute('api_added').to_i <= target_api) }
# methods = methods.select{|i| !i.attribute('deprecated') || (i.attribute('deprecated').to_i > min_api)}
- methods = methods.select{|i| !i.attribute('api_removed') || (i.attribute('api_removed').to_i > min_api)}
+ methods = methods.select { |i| !i.attribute('api_removed') || (i.attribute('api_removed').to_i > min_api) }
# Inform and remove methods that do not exist in one of the sdk versions
methods = methods.select do |i|
if i.attribute('api_removed') and i.attribute('api_removed').to_i <= target_api
puts "Can't create #{i.method_signature} -- removed in #{i.attribute('api_removed')}"
@@ -122,22 +119,22 @@
'THE_ANDROID_CLASS' => (params[:class] || params[:interface]) +
(params[:implements] == '' ? '' : ((action != 'implements' ? ' implements ' : ', ') + params[:implements].split(',').join(', '))),
'THE_RUBOTO_CLASS' => params[:name],
'THE_CONSTRUCTORS' => class_desc.name == 'class' ?
class_desc.get_elements('constructor').map { |i| i.constructor_definition(params[:name]) }.join("\n\n") : '',
- 'THE_METHODS' => methods.map { |i| i.method_definition(params[:name]) }.join("\n\n")
+ 'THE_METHODS' => methods_header + methods.map { |i| i.method_definition(params[:name]) }.join("\n\n")
}
end
#
# generate_core_classe: generates RubotoActivity, RubotoService, etc. based
# on the API specifications.
#
def generate_core_classes(params)
hash = {:package => 'org.ruboto'}
- %w(method_base method_include implements force).inject(hash) {|h, i| h[i.to_sym] = params[i.to_sym]; h}
- hash[:method_exclude] = params[:method_exclude].split(',').push('onCreate').push('onDestroy').push('onBind').push('onStartCommand').join(',')
+ %w(method_base method_include implements force).inject(hash) { |h, i| h[i.to_sym] = params[i.to_sym]; h }
+ hash[:method_exclude] = params[:method_exclude]
%w(android.app.Activity android.app.Service android.content.BroadcastReceiver).each do |i|
name = i.split('.')[-1]
if params[:class] == name or params[:class] == 'all'
generate_subclass_or_interface(hash.merge({:template => "Ruboto#{name}", :class => i, :name => "Ruboto#{name}"}))
@@ -191,8 +188,23 @@
f << sample_test_source
end
puts "Added file #{test_file}."
end
end
+
+ def methods_header
+ <<EOF
+ private final ScriptInfo scriptInfo = new ScriptInfo();
+ public ScriptInfo getScriptInfo() {
+ return scriptInfo;
+ }
+
+ /****************************************************************************************
+ *
+ * Generated Methods
+ */
+EOF
+ end
+
end
end
end