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") CLOBBER.include('bin','obj','TestResults') 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[:src_glob]="**/{*.{rb,feature,spec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,resx,settings,config},Jamfile,.semver,Gemfile,README,LICENSE}" self[:newest_src_file]=Dir.glob(self[:src_glob]).max_by {|f| File.mtime(f)} self[:command_order]=['pull','upgrade','add','build','test','commit','publish','push'] self[:relative_directory]=Environment.relative_directory self[:working_directory]=Environment.working_directory self[:context]=Environment.context self[:machine]=Environment.machine self[:platform]=RUBY_PLATFORM 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) allartifactsexist = true self[:artifacts].each{|f| allartifactsexist=false if !File.exists?(f)} self[:newest_artifact]=self[:artifacts].max_by { |f| File.mtime(f) } if allartifactsexist self[:commands]=Commands.new if !has_key?(:commands) self[:commands].update self[:up_to_date] = false if(allartifactsexist && !self[:newest_artifact].nil? && !self[:newest_src_file].nil? && File.exists?(self[:newest_artifact]) && File.exists?(self[:newest_src_file])) if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:command_order]=['upgrade'] if(File.mtime(self[:newest_artifact]) > File.mtime(self[:newest_src_file])) self[:up_to_date]=true end self[:newest_artifact_mtime]=File.mtime(self[:newest_artifact]).to_s self[:newest_src_file_mtime]=File.mtime(self[:newest_src_file]).to_s end update_tasks end def execute cmd self[:commands].execute_command cmd 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 'executes tasks in order of command_order, if they are defined' task :dev_tasks_default do DEV_TASKS[:command_order].each{|c| Rake::Task[c].invoke if(Rake::Task.task_defined?(c)) } puts "Total Time " + DEV_TASKS.timer.elapsed_str end 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