puts_debug "read " + __FILE__.foreground(:green) require 'rake' if("#{RUBY_VERSION}">"1.9.1") include Rake::DSL end def task_start(task_name) puts " " puts "[:#{task_name}]".foreground(:yellow).bright + " " + Dir.pwd end task :clean do; task_start "clean"; puts " cleaning tmp dir (max 30 seconds)" Dev::SystemCall.clean_tmp_files Dev::Cmd::Clean.clean_tmp end task :clobber do; task_start "clobber"; end require 'rake/clean' CLEAN.include('doc','*.gem','*.taskstamp*','**/*.{suo,sdf}') CLOBBER.include('bin','obj') def generate_task_hash(project) task_hash = { :info=> { :desc=> 'display information about the rakefile' }, #:test=> { :desc=> 'run unit tests' }, :loc=> { :desc=> 'count the lines of code' }, #:setup=> { :desc=> 'setup the project environment' }, :pull=> { :desc=> 'rake working copies of dependencies' }, :check=> { :desc=> 'checks if the project default task may be skipped' } } if(!CMD[:setup].nil? && CMD[:setup].length > 0) task_hash[:setup]={ :desc=> 'setup the project environment' } end if(project[:scm_type]=="svn" || project[:scm_type]=="git") task_hash[:add] ={ :desc=> 'add files defined by src_glob to source code management' } task_hash[:commit]={ :desc=> 'commit changes to source code management' } task_hash[:update]={ :desc=> 'updates changes from source code management' } end task_hash[:compile] = { :desc=> 'compile source code' } if CMD.has_key?(:compile) && CMD[:compile].length > 0 #project.has_key?(:compile) && project[:compile].length > 0 task_hash[:replace] = { :desc=> 'replace text' } if CMD.has_key?(:replace) && CMD[:replace].length > 0 task_hash[:test]={:desc=>'run unit tests'} if CMD.has_key?(:test) && CMD[:test].length > 0 if project[:type]=="gem" || project[:type]=="ruby" task_hash[:features] = { :desc=> 'tests cucumber features' } end return task_hash end def generate_tasks(project) puts_debug "generate_tasks" hash=generate_task_hash project hash.each do |k,v| name=k.to_s puts_debug "checking if task #{name} should be autogenerated" desc=nil desc=v[:desc] if v.has_key?(:desc) #ruby="task :#{name} do; task_start '#{name}'; PROJECT.#{name}; end" if PROJECT.respond_to?(name) ruby="task :#{name} do; task_start '#{name}'; CMD.#{name}; end" ruby="desc '#{desc}'; " + ruby unless desc.nil? if !task_exists?(name) puts_debug "defining task #{name} with '#{ruby}'" eval(ruby) end end # generate default task if(!defined?(DEV_NO_DEFAULT_TASK)) Rake.application.instance_variable_get('@tasks').delete('default') task_list="" ["check","add","setup","replace","compile","post_compile","test","commit","update"].each {|t| if(hash.has_key?(t.to_sym) || task_exists?(t) || (CMD.has_key?(t.to_sym) && CMD[t.to_sym].count > 0) ) task_list = "#{task_list}," if task_list.length > 0 task_list = "#{task_list} :#{t}" default_code = "#{default_code} :#{t}," end } desc="desc '#{task_list}'".gsub(' ',"").gsub(':',"") eval("#{desc}; task :default => [#{task_list}] do; task_start('default'); end") end end def task_exists?(name) if("#{RUBY_VERSION}">"1.9.1") return Rake::Task.task_defined?(name) else return false end end module Dev class Tasks < Hash def refresh puts_debug "Dev::Tasks.refresh" DEV.refresh CMD.refresh generate_tasks(DEV) end end # class Tasks end # module Dev TASKS=Dev::Tasks.new TASKS.refresh