["Clean","Compile","Replace","Setup","Test","Commit","Info","Update","Pull","Build"].each{ |f| require_relative("cmd/#{f}.rb") } module Dev class Commands < Hash def initialize self[:setup]=Dev::Cmd::Setup.new self[:replace]=Dev::Cmd::Replace.new self[:compile]=Dev::Cmd::Compile.new self[:test]=Dev::Cmd::Test.new self[:commit]=Dev::Cmd::Commit.new self[:update]=Dev::Cmd::Update.new self[:pull]=Dev::Cmd::Pull.new refresh end def refresh puts_debug "Dev::Command.refresh" self[:setup].refresh(DEV[:dep]) if self[:setup].respond_to?("refresh") self[:replace].refresh(DEV[:dep]) if self[:replace].respond_to?("refresh") self[:compile].refresh if self[:compile].respond_to?("refresh") self[:test].refresh if self[:test].respond_to?("refresh") self[:commit].refresh if self[:commit].respond_to?("refresh") self[:update].refresh if self[:update].respond_to?("refresh") self[:pull].refresh if self[:pull].respond_to?("refresh") end def info; Dev::Cmd::Info.execute; end def setup; execute_method "setup"; end def compile; execute_method "compile"; end def test; execute_method "test"; end def update;execute_method("update");end def replace self[:replace].execute if self[:replace].respond_to?("execute") end def execute_method(name) string_name=name.to_s puts_debug "method_missing name=" + string_name puts " no directives defined for #{string_name}" if self.get_value(string_name).nil? && string_name=="pull" return if(self.get_value(string_name).nil?) puts " no directives defined for #{string_name}" if self.get_value(string_name).length < 1 return if self.get_value(string_name).length < 1 value=self.get_value(string_name) if value.kind_of?(Hash) value.each { |name,value| Dev::Commands.execute_cmd(value); sleep(0.5) } else value.each { |c| Dev::Commands.execute_cmd(c); sleep(0.5) } end end def execute(c) Dev::Commands::execute_cmd(c) end def self.execute_cmd(c) # expand the command here.... command=Dev::Environment.expand_command(c) puts_debug "command: " + command.to_s + " (in Project.execute_cmd)" if c.include?('<%') && c.include?('%>') #puts "Command: " + c eval(c.gsub("<%","").gsub("%>","")) else # is the command a hash? hash=c if c.kind_of?(Hash) # can the command be converted to a hash? hash=Dev::Environment.s_to_hash(command) if hash.nil? call=nil if(hash.nil?) call=Dev::SystemCall.new(command) else call=Dev::SystemCall.new(hash) end call.puts_summary end end def add unless DEV[:src_glob].nil? scm = Dev::Scm.new return if scm.scm_type == "none" if DEV[:src_glob].kind_of?(Hash) DEV[:src_glob].each do |name,value| puts " adding files " + value.to_s scm.add_file_glob(value) end else puts " adding files " + DEV[:src_glob].to_s scm.add_file_glob(DEV[:src_glob]) end end end def commit scm = Dev::Scm.new return if scm.scm_type == "none" puts " no differences detected" unless has_diff execute_method("commit") if has_diff #if File.exists?(".svn") if Scm.get_default_scm_type == "svn" call=Dev::SystemCall.new('svn update') call=Dev::SystemCall.new('svn info') url = call.output.match(/URL: ([\d\w\.\:\/-]+)/)[1] rev = call.output.match(/Last Changed Rev: ([\d]+)/)[1] puts " #{url}@#{rev}" end FileUtils.rm "commit.message" if File.exists?("commit.message") end def check puts " default.taskstamp." + DEV.context + " exists." if File.exists?("default.taskstamp."+ DEV.context) puts " default.taskstamp." + DEV.context + " does not exist" unless File.exists?("default.taskstamp." +DEV.context) begin hasdiff = has_diff rescue puts "has_diff threw an exception." end puts " no differences detected." unless hasdiff puts " detected differences." if hasdiff if File.exists?("default.taskstamp."+DEV.context) && !hasdiff #puts " nothing to do" update exit end #if !has_diff and File.exists?("default.taskstamp."+context) # puts " no differences detected." # puts " default.taskstamp." + context + " exists." # exit #end #puts " detected differences" if has_diff #puts " default.taskstamp." + context + " does not exist" unless File.exists?("default.taskstamp." + context) end def has_diff call=nil if DEV[:scm_type] == "git" call=Dev::SystemCall.new('git status') return true if call.output.include?("new file:") return true if call.output.include?("deleted:") return true if call.output.include?("modified:") return false end #call=Dev::SystemCall.new('git diff --name-only') if File.exists?(".git") call=Dev::SystemCall.new('svn diff') if Scm.get_default_scm_type == "svn" #if File.exists?(".svn") unless call.nil? || call.output.length==0 puts_debug call.output return true # differences detected else return false # no differences end end end # class Tasks end # module Dev CMD=Dev::Commands.new()