puts_debug "read " + __FILE__.foreground(:green) require 'semver' UNITTESTS=Array.new module Dev class Project < Hash def initialize(hash,init_defaults=true) puts_debug "initialize, copying hash values" hash.each { |name,value| self[name]=value } update_default_values if init_defaults end def array_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 self.get_value(string_name).each{ |c| # expand the command here.... command=expand_command(c) puts_debug "command: " + command if c.include?('<%') && c.include?('%>') #puts "Command: " + c eval(c.gsub("<%","").gsub("%>","")) else # can the command be converted to a hash? hash=Dev::Environment.s_to_hash(command) call=nil if(hash.nil?) call=Dev::SystemCall.new(command) else call=Dev::SystemCall.new(hash) end call.puts_summary end } end def method_missing( name, *args ); array_method(name); end def expand_command(command); expand_project_variables(command); end def expand_project_variables(str) result=Dev::Environment.expand_string_variables(str) # expands ruby variables, e.g. '#{name}' to 'widget' if result.include?('<') && result.include?('>') result.scan(/(<[\w,]+>)/).each { |pvar| # expand project variables, e.g. '' to 'widget key = pvar[0].gsub("<","").gsub(">","") # '' to 'C:/wherever/NUnit.exe' result = result.gsub(pvar[0],get_value(key)) } end result end def loc_cmd cmd="countloc --recurse ." cmd="countloc --recurse --mode ruby ." if self[:type]=="ruby" || self[:type]=="gem" cmd="countloc --recurse --mode csharp ." if self[:type]=="C#" cmd="countloc --recurse --mode cpp ." if self[:type]=="c++" return cmd end def loc system(loc_cmd) end def loc_total # parse the output for TOTAL LOC call=Dev::SystemCall.new(loc_cmd) words=call.output.split if(words.length>6) return words[words.length-6] end "?" end def check if !has_diff and File.exists?("default.taskstamp") puts " no differences detected." puts " default.taskstamp exists." exit end puts " detected differences" if has_diff puts " default.taskstamp does not exist" unless File.exists?("default.taskstamp") end def stamp_task(name) File.open("#{name}.taskstamp","w") { |f| f.write(Time.now.to_s) } end def replace #puts " " #puts "replace".foreground(:yellow).bright hash=self[:replace] if hash.nil? puts " no replace directives" end unless hash.nil? hash.each do |k,v| unless v.nil? file=v[:file] search=v[:search] replace=v[:replace] glob=v[:glob] unless search.nil? || replace.nil? unless file.nil? Dev::Environment.replace_text_in_file(file,search,replace) end unless glob.nil? Dev::Environment.replace_text_in_glob(glob,search,replace) end end end end end end def features if self[:type]=="C#" && File.exists?("bin/x86/Release/#{self[:name]}.Features.dll") call=Dev::SystemCall.new(expand_project_variables(" /nologo bin/x86/Release/#{self[:name]}.Features.dll")) puts call.command puts call.output raise "exit_code=#{call.status.to_s}" + call.error unless call.status==0 end array_method("features") end def has_build_products end def has_diff call=nil call=Dev::SystemCall.new('git diff') if File.exists?(".git") call=Dev::SystemCall.new('svn diff') if File.exists?(".svn") unless call.nil? || call.output.length==0 return true # differences detected else return false # no differences end end def update array_method("update") end def commit puts " no differences detected" unless has_diff array_method("commit") if has_diff end def rake_working_deps unless dep_hash.nil? dep_hash.each do |key,value| if value.kind_of?(Hash) # potential hash keys: uri, dir, rake # uri is required unless value.get_value("uri").nil? uri=expand_project_variables(value.get_value("uri")) uri_words=uri.split('/') while(uri_words.length > 3) do uri_words.shift end dir=self[:dev_root] + "/wrk/" + uri_words.join('/') unless value.get_value("rake").nil? if(File.exist?(dir)) rake_task=value.get_value("rake") cmd_hash = {:cmd=> "rake #{rake_task}", :dir=> "#{dir}"} end end end end # unless value.get_value("uri").nil? end end # unless dep_hash.nil? end def pull update unless has_diff array_method("pull") filename=Dir.pwd + "/rakefile.rb" puts " updating revision variables for " + filename Dev::Svn::update_revision_variables(filename) end def info [ "file_count","loc" ].each do |k| puts_debug "set_default_value(#{k})" set_default_value(k) end puts " " Hash.print_hash("",self) puts " " end def set_default_value(key) set_value(key,get_default_value(key)) if get_value(key).nil? && !get_default_value(key).nil? end def get_default_value(key) system_call = Dev::SystemCall.new("semver init") if(!File.exist?(".semver")) version = SemVer.find value="#{Dev::Environment.dev_root}" if key=="dev_root" value="C#" if key=="type" value="**/*.{rb,feature,semver}" if key=="src_glob" value="**/*.{cs,xaml,rb,resx,settings,feature,semver}" if key=="src_glob" && self[:type]=="C#" value="**/*.{c,cpp,h,hpp,semver}" if key=="src_glob" && (self[:type]=="C++" || self[:type]=="c++" || self[:type]=="cpp") value="**/*.{rb,feature,semver}" if key=="src_glob" && self[:type]=="ruby" value="**/*.{rb,feature,gemspec,semver}" if key=="src_glob" && self[:type]=="gem" value=loc_total if key=="loc" value="svn" if key=="scm_type" && File.exists?(".svn") value="git" if key=="scm_type" && File.exists?(".git") value="#{version.major}.#{version.minor}.#{version.patch}" if key=="version" if key=="file_count" unless Dir.glob(self[:src_glob]).nil? value=Dir.glob(self[:src_glob]).length.to_s end end hash=Hash.new if(key=="paths") if(self[:type]=="C#") hash.set_value("msbuild","C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe") nunit_version="2.5.10.11092" hash.set_value("nunit","#{Dev::Environment.dev_root}/dep/ThirdParty/NUnit/#{nunit_version}/bin/net-2.0/nunit-console-x86.exe") end end value=hash if hash.length > 0 array=Array.new if(key=="setup") array << "bundle install" if File.exists?("Gemfile") # dep,svn directives dep_hash=self.get_value("dep") unless dep_hash.nil? dep_hash.each do |key,value| if value.kind_of?(Hash) dep=Dev::Dep.new(value) dep.setup_commands.each{|cmd| array << cmd} end end end end if(key=="pull") # dep,svn directives dep_hash=self.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 end if(key=="compile") Dir.glob("*.gemspec").each { |gs| array << "gem build #{gs}" } if self[:type]=="gem" if self[:type]=="C#" if(!has_key?(:x86_release_compile_flags)) self[:x86_release_compile_flags]="/property:Configuration=Release /property:Platform=\"x86\" /p:OutputPath=./bin/x86/Release" end end Dir.glob("*.csproj").each{|cs|array<<" #{cs} "} end if(key=="test") #Dir.glob("*.gemspec").each { |gs| array << "gem uninstall #{gs.gsub('.gemspec','')} -v #{self[:version]}" } if self[:type]=="gem" Dir.glob("*.gemspec").each { |gs| array << "gem install ./#{gs.gsub('.gemspec','')}-#{self[:version]}.gem" } if self[: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" } end end if(key=="features") array << "cucumber features" if File.exists?("features") && Dir.glob("features/**/*.rb").length > 0 end if(key=="has_diff") array << 'git diff' if File.exists?(".git") array << 'svn diff' if File.exists?(".svn") end if(key=="commit") array << 'git commit -a -m "rake commit all"' if File.exists?(".git") array << 'svn commit -m "rake commit all"' if File.exists?(".svn") end if(key=="update") array << 'svn update' if File.exists?(".svn") end value=array if array.length > 0 return value end def update_default_values puts_debug "update_default_values" self[:type]="C#" if self[:type].nil? [ "version","dev_root","src_glob","scm_type", "paths","add","pull","setup","compile","test","features","commit","update" ].each do |k| puts_debug "set_default_value(#{k})" set_default_value(k) end generate_tasks(self) end end end # module Dev