#require 'rake' #require 'rake/tasklib' require 'rbconfig' require 'fileutils' require 'facet/fileutils/safe_ln' require 'facet/string/tabto' require 'facet/module/basename' require 'carat/filelist' require 'reap/projectinfo' # Base class for reap tasks. # # Here's an oh so simple example: # # class MyTask < Reap::Task # # register 'mytask' # # default_desc 'this is a custom reap task' # # attr_accessor :message # # def init # @message ||= master['default'] || 'None Found!' # end # # def run # puts @message # end # end # # The corresponding settings in the ProjectInfo file will then be: # # default: Default text, if any. # # myname: # TASK: mytask # message: Message text, if any. # module Reap def self.registry ; @registry ; end def self.register( name, klass ) @registry ||= {} if klass.verify @registry[name.to_s.downcase] = klass end end def self.tasks ; @tasks ; end def self.initialize_all @tasks ||= {} registry.each do |name, klass| @tasks[name] = klass.new end end class Task #< ::Rake::TaskLib include ::Config include ::FileUtils RUBY = CONFIG['ruby_install_name'] # class methods def self.inherited( task_class ) Reap::register( task_class.task_name, task_class ) end def self.task_desc ; '(no desciption given)' ; end def self.task_name ; basename.downcase ; end def self.section_required( val ) ; @section_required = val ;end def self.section_required? ; @section_required ; end def self.verify assume = true if section_required? assume = ::ProjectInfo.info.key?(task_name) end assume end # instance methods def task_name ; self.class.task_name ; end def task_desc ; self.class.task_desc ; end def master ; ::ProjectInfo.info ; end def section ; @section ; end def section_required? ; self.class.section_required? ; end def initialize sect = master[task_name] if sect.is_a?(Array) sect.each do |s| section_parameters_set( s ) init end else section_parameters_set( sect || {} ) init end end def section_parameters_set( s ) @section = s @section.each { |k,v| send("#{k}=", v) } end def init raise "not implemented for '#{task_name}' task" end def run( *args ) raise "no action defined for task #{task_name}" end # task support methods def sh( arg ) puts arg system arg unless $PRETEND end # o = nil # o = yld.call(self) if yld # if String === o # begin # section( o ).each { |k,v| send("#{k}=", v ) } # end # end # # init # # task_name ||= default_name # task_desc = @desc || default_desc # # if subtask # desc task_desc # task task_name => subtask do # run # end # else # desc task_desc # task task_name do # run # end # end # end end #class Task end #module Reap ## # Convenience methods for built-in rake tasks ## # module RakeTask # extend self # # def gem_package_task(*args,&blk) # ::Rake::GemPackageTask.new(*args,&blk) # end # # def package_task(*args,&blk) # ::Rake::PackageTask.new(*args,&blk) # end # # def test_task(*args,&blk) # ::Rake::TestTask.new(*args,&blk) # end # # def rdoc_task(*args,&blk) # ::Rake::RDocTask.new(*args,&blk) # end # # end