require 'rake' require 'rake/clean' require 'json' include Rake::DSL require_relative './environment.rb' require_relative './commands.rb' require_relative './dependencies.rb' require_relative './artifacts.rb' require_relative './console.rb' require_relative './timer.rb' require_relative './settings.rb' CLEAN.include("*.gem") class DevTasks < Hash attr_accessor :timer def initialize @timer = Timer.new #hash = JSON.parse File.read("#{File.dirname(__FILE__)}/spec.json") #self[:dev_tasks_gem]=JSON.parse File.read("#{File.dirname(__FILE__)}/spec.json") self[:name]=pwd.split('/').last#Rake.application.original_dir.split('/').last self[:scm]=Environment.scm self[:branch]=Environment.branch self[:relative_directory]=Environment.relative_directory self[:working_directory]=Environment.working_directory self[:context]=Environment.context self[:machine]=Environment.machine self[:dev_root]=Environment.dev_root self[:settings]=Settings.new update end def add hash hash.each do |key,value| self[key]=value if !has_key?(key) end end def update self[:dependencies]=Dependencies.new if !has_key?(:dependencies) self[:artifacts]=Artifacts.new if !has_key?(:artifacts) self[:commands]=Commands.new if !has_key?(:commands) update_tasks end def execute_task task timer=Timer.new #start_time=Time.now Console.announce_task_start task if(!self[:commands].has_key?(task)) puts "no commands discovered for task " + task else self[:commands][task].each {|c| self[:commands].execute_command(c) } end elapsed = timer.elapsed #end_time=Time.now #elapsed=end_time-start_time if elapsed > 30 elapsed_str="[" + "%.0f" %(elapsed) + "s]" Console.announce_task_end task, elapsed_str end end def define_task task_name if(!Rake::Task.task_defined?(task_name)) ruby="desc '#{task_name} task';task :#{task_name} do;DEV_TASKS.execute_task '#{task_name}';end" eval(ruby) end end def update_tasks dev_task_defaults=Array.new self[:commands].each do |key,array| if(array.length > 0) define_task key dev_task_defaults << key end end if(!Rake::Task.task_defined?('dev_tasks_default')) tasklist="" dev_task_defaults.each{|t| tasklist = tasklist + "," if tasklist.length > 0 tasklist = tasklist + ":" + t.to_s } ruby="desc 'dev_tasks_default task [#{tasklist}]';task :dev_tasks_default => [#{tasklist}] do;puts '[:dev_task_default] completed in ' + DEV_TASKS.timer.elapsed_str;end" eval(ruby) end end end DEV_TASKS=DevTasks.new desc 'displays information about current rake directory' task :info do Console.print_hash("",DEV_TASKS) end desc 'displays help for dev_task' task :help do puts "use rake -T to see available tasks" end