require_relative 'cmd/Compile.rb' module Dev class Commands < Hash def initialize refresh end def refresh puts_debug "Dev::Command.refresh" self.delete :setup if self.has_key? :setup #self.delete :compile if self.has_key? :compile ["add","pull","setup","compile","test","features","commit","update"].each { |key| if self.has_key?(key.to_sym) puts_debug "CMD has key #{key}" else value=get_default_value(key.to_sym) self[key.to_sym]=value if !value.nil? puts_debug "CMD[#{(key.to_sym).to_s}]=#{value.to_s}" if !value.nil? puts_debug "default value for #{key} was nil" end } end def get_default_value(key) return get_default_value_setup if key==:setup return get_default_value_commit if key==:commit return get_default_value_test if key==:test return Dev::Cmd::Compile.get_auto_compile_directives if key==:compile return get_default_value_update if key==:update return get_default_value_pull if key==:pull nil end def get_default_value_commit array=Array.new array << 'git commit -a -m "rake commit all"' if File.exists?(".git") array << 'svn commit -m "rake commit all"' if File.exists?(".svn") array=nil if array.empty? return array end def get_default_value_update array=Array.new array << 'svn update' if File.exists?(".svn") array=nil if array.empty? return array end def get_default_value_setup array=Array.new puts_debug "assigning default values for setup" #array << "bundle install" if File.exists?("Gemfile") array << "{ :cmd=> 'bundle install', :capture_output=> false}" if File.exists?("Gemfile") && "#{RUBY_VERSION}">="1.8.7" # dep,svn directives puts_debug "checking for :dep hash...." dep_hash=DEV.get_value(:dep) puts_debug "dep_hash is nil" if dep_hash.nil? unless dep_hash.nil? puts_debug "dep_hash is not nil" puts_debug "dep_hash is empty" if dep_hash.empty? dep_hash.each do |key,value| puts_debug ":dep[#{key.to_s}]" if value.kind_of?(Hash) dep=Dev::Dep.new(value) dep.setup_commands.each{|cmd| array << cmd} end end end puts_debug "mkdir directives..." if(!Dir.glob("*.csproj").nil? && Dir.glob("*.csproj").length > 0) array << "<%Dir.mkdir 'bin' unless File.exist?('bin')%>" array << "<%Dir.mkdir 'bin/Debug' unless File.exist?('bin/Debug')%>" array << "<%Dir.mkdir 'bin/Release' unless File.exist?('bin/Release')%>" end array=nil if array.empty? return array end def get_default_value_pull array=Array.new # dep,svn directives dep_hash=DEV.get_value("dep") unless dep_hash.nil? dep_hash.each do |key,value| if value.kind_of?(Hash) dep=Dev::Dep.new(value) dep.pull_commands.each{|cmd| array << cmd} #puts_debug "pull array: " + array.to_s end end end array=nil if array.empty? return array end def get_default_value_test puts_debug "Dev::Commands.get_default_value_test" array=Array.new array << "rspec --pattern='**/*.spec'" if DEV[:file_count].has_key?(:spec) && DEV[:file_count][:spec] > 0 Dir.glob("*.gemspec").each { |gs| array << "{cmd: 'gem install ./#{gs.gsub('.gemspec','')}-#{DEV[:version]}.gem', capture_output: true}" #array << "{cmd: 'gem install ./#{gs.gsub('.gemspec','')}-#{DEV[:version]}.gem', capture_output: false}" #array << "{:cmd=> 'gem install #{gs.gsub('.gemspec','')}-#{DEV[:version]}.gem', :capture_output=> false}" #array << "gem install ./#{gs.gsub('.gemspec','')}-#{DEV[:version]}.gem" } #if DEV[:type]=="gem" #if self[:type]=="C#" Dir.glob("*.{Test.csproj,Features.csproj}").each { |cs| dll_name="bin/x86/Release/#{File.basename(cs,'.csproj')}.dll" array << "\"\" /nologo #{dll_name} /xml:#{dll_name}.nunit-results.xml" if RUBY_PLATFORM.include?("w32") array << "mono \"\" #{dll_name}" if !RUBY_PLATFORM.include?("w32") } #end return array 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; DEV.replace; 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 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 info puts "DEV" Hash.print_hash("",DEV) puts " " puts "CMD" Hash.print_hash("",CMD) puts " " end def add unless self[:src_glob].nil? scm = Dev::Scm.new return if scm.scm_type == "none" if self[:src_glob].kind_of?(Hash) self[:src_glob].each do |name,value| puts " adding files " + value.to_s scm.add_file_glob(value) end else puts " adding files " + self[:src_glob].to_s scm.add_file_glob(self[: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") 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 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 File.exists?(".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:") end call=Dev::SystemCall.new('git diff --name-only') if File.exists?(".git") call=Dev::SystemCall.new('svn diff') 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()