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"; 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(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) || project.has_key?(:compile) task_hash[:replace] = { :desc=> 'replace text' } if CMD.has_key?(:replace) 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 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 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) ) task_list = "#{task_list}," if task_list.length > 0 task_list = "#{task_list} :#{t}" default_code = "#{default_code} :#{t}," end } eval("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