lib/sprout/executable.rb in sprout-1.0.32.pre vs lib/sprout/executable.rb in sprout-1.0.35.pre
- old
+ new
@@ -25,11 +25,11 @@
# external command line process.
#
# Following is an example of how one could define an executable Ruby
# application using this module:
#
- # :include: ../../test/fixtures/examples/echo_inputs.rb
+ # :include: ../../test/fixtures/examples/echo_inputs.rb
#
module Executable
include RubyFeature
DEFAULT_FILE_EXPRESSION = '/**/**/*'
@@ -75,11 +75,11 @@
#
# In the case of a Ruby executable, command line parameters will be interpreted
# in the order they are defined using +add_param+.
#
def add_param(name, type, options=nil) # :yields: Sprout::Executable::Param
- raise Sprout::Errors::UsageError.new("[DEPRECATED] add_param no longer uses closures, you can provide the same values as a hash in the optional last argument.") if block_given?
+ raise Sprout::Errors::UsageError.new "[DEPRECATED] add_param no longer uses closures, you can provide the same values as a hash in the optional last argument." if block_given?
raise Sprout::Errors::UsageError.new "The first parameter (name:SymbolOrString) is required" if name.nil?
raise Sprout::Errors::UsageError.new "The second parameter (type:Class) is required" if type.nil?
raise Sprout::Errors::UsageError.new "The type parameter must be a Class by reference" if !type.is_a?(Class)
options ||= {}
@@ -293,12 +293,11 @@
# Call the provided executable delegate.
#
# This method is generally called from Rake task wrappers.
#
def execute_delegate
- exe = Sprout::Executable.load(executable, pkg_name, pkg_version).path
- Sprout.current_system.execute exe, to_shell
+ system_execute binary_path, to_shell
end
def prepare
params.each do |param|
param.prepare
@@ -306,29 +305,27 @@
end
def to_rake *args
# Define the file task first - so that
# desc blocks hook up to it...
- file_task = file *args do
- execute
- end
+ outer_task = create_outer_task *args
update_rake_task_name_from_args *args
yield self if block_given?
prepare
# TODO: Tried auto-updating with library
# prerequisites, but this led to strange
# behavior with multiple registrations.
- handle_library_prerequisites file_task.prerequisites
+ handle_library_prerequisites outer_task.prerequisites
# Add the library resolution rake task
# as a prerequisite
- file_task.prerequisites << task(Sprout::Library::TASK_NAME)
+ outer_task.prerequisites << task(Sprout::Library::TASK_NAME)
prerequisites.each do |prereq|
- file_task.prerequisites << prereq
+ outer_task.prerequisites << prereq
end
- file_task
+ outer_task
end
##
# This will create a hash of ONLY values that are created
# using +add_param+, properties that are created with
@@ -380,13 +377,37 @@
@default_file_expression ||= Sprout::Executable::DEFAULT_FILE_EXPRESSION
end
protected
+ ##
+ # Create the outer rake task.
+ # For most executables, this will be a Rake::File task,
+ # This is a template method that should be overridden
+ # for executables that do not result in the creation of
+ # a file.
+ #
+ # @see update_rake_task_name_from_args
+ def create_outer_task *args
+ file *args do
+ execute
+ end
+ end
+
+ ##
+ # This method will add the current task to the Rake CLEAN
+ # collection.
+ #
+ # Any Executable that does not create a Rake::File task
+ # should also override this method and prevent it from
+ # calling +CLEAN.add+.
+ #
+ # @see create_outer_task
def update_rake_task_name_from_args *args
self.rake_task_name = parse_rake_task_arg args.last
CLEAN.add(self.rake_task_name)
+ self.rake_task_name
end
def parse_rake_task_arg arg
return arg if arg.is_a?(Symbol) || arg.is_a?(String)
arg.each_pair do |key, value|
@@ -415,10 +436,18 @@
# a String path to a file (or folder), or it can
# be an Array of paths to files (or folders).
def library_added path_or_paths
end
+ def system_execute binary, params
+ Sprout.current_system.execute binary, params
+ end
+
private
+
+ def binary_path
+ Sprout::Executable.load(executable, pkg_name, pkg_version).path
+ end
def handle_library_prerequisites items
items.each do |task_name|
t = Rake.application[task_name]
if(!t.sprout_entity.nil?)