puts_debug "read " + __FILE__ require 'semver' require 'rake' module Dev class Project < Hash def initialize defaults.each { |name,value| self[name]=value } if(RUBY_VERSION != "1.8.7") db = Dev::Database.new db.set_branch_uri(self[:fullname],self[:scm_uri]) end end def defaults puts_debug "Dev::Project.defaults begin" system_call = Dev::SystemCall.new("semver init") if(!File.exist?(".semver")) h=Hash.new puts_debug "Dev::Project.defaults :scm_uri" h[:scm_uri] = Scm.get_default_scm_uri if !Scm.get_default_scm_uri.nil? puts_debug "Dev::Project.defaults :scm_type" h[:scm_type] = Scm.get_default_scm_type if !Scm.get_default_scm_type.nil? h[:directory]=Rake.original_dir() h[:fullname]=get_default_value_fullname h[:group]=get_default_value_group h[:name]=get_default_value_name h[:version]= "#{SemVer.find.major}.#{SemVer.find.minor}.#{SemVer.find.patch}" h[:src_glob]="**/{*.{rb,feature,spec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,xib,sln,filters,xaml,xml,resx,settings,txt,png,bmp,ico,config},Jamfile,.semver,Gemfile,README,LICENSE}" h[:src_glob]="**/{*.{rb,feature,spec,cs,c,m,cpp,cxx,h,hpp,i,jam,csproj,vcproj,snk,vcxproj,xcodeproj,plist,pch,strings,storyboard,xib,sln,filters,xaml,xml,resx,settings,txt,png,bmp,ico,config},Jamfile,.semver,Gemfile,README,LICENSE}" if RUBY_PLATFORM.include?("darwin") puts_debug "Dev::Project.defaults :dev_root" h[:dev_root]= "#{Dev::Environment.dev_root}" #h[:user_profile]= "#{Dev::Environment.user_profile}" puts_debug "Dev::Project.defaults default_toolset" default_toolset = Dev::BoostBuild.defaultToolset if !default_toolset.nil? puts_debug "Dev::Project.defaults :toolset" h[:toolset] = default_toolset ENV["VisualStudioVersion"]="11.0" if h[:toolset]=="msvc-11.0" end puts_debug "Dev::Project.defaults :type" h[:type]="gem" puts_debug "Dev::Project.defaults B" if(defined?(DEV_FILE_COUNT)) h[:type]=get_default_value_type h[:file_count]=Hash.new ["rb","spec","feature","cs","cpp","h","hpp","vcxproj","csproj"].each{ |ext| count=Dir.glob("**/*.#{ext}").count h[:file_count][ext.to_sym]=count if count > 0 } end puts_debug "Dev::Project.defaults C" h[:paths] = Dev::Paths.new h[:dep]=Deps.new puts_debug "Dev::Project.defaults end" return h end def refresh puts_debug "Dev::Project.refresh" start_time=Time.now self[:dep].refresh #update_default_values #db = Dev::Database.new #db.set_branch_uri(self[:fullname],self[:scm_uri]) puts_debug "DEV refresh elapsed time " + (Time.now-start_time).to_s begin updateProductsDB rescue end end def updateProductsDB filename = Dev::Environment.user_profile + "/Development.sql" if(File.exists?(filename) && !DEV[:scm_uri].nil? && DEV[:scm_uri].length > 0) db = SQLite3::Database.new filename insert = true id=nil db.execute("select * from Products where name='" + DEV[:fullname] + "';") do |row| id=row[0] name=row[1].to_s uri=row[2].to_s insert = false if(name==DEV[:fullname] && uri==DEV[:scm_uri]) end if(insert) sid="null" sid=id.to_s if !id.nil? sql="insert or replace into Products VALUES(" + sid + ",'" + DEV[:fullname].to_s + "','" + DEV[:scm_uri].to_s + "');" puts_debug "sql=#{sql}" db.execute(sql) db.close db=nil end end end def get_default_value_name dirs=::Rake.original_dir().split('/') return dirs[dirs.length-2] if(dirs.length > 3) return nil end def get_default_value_fullname wrk="#{Dev::Environment.dev_root}/wrk/" if(Rake.original_dir.include?(wrk)) name=Rake.original_dir.gsub(wrk,"") return name if(name.split('/').length==3) end nil end def get_default_value_group dirs=Rake.original_dir().split('/') return dirs[dirs.length-3] if(dirs.length > 3) return "unknown" end def get_default_value_type Dir.glob("**/*.{cpp,hpp}").each { |f| return "c++" } Dir.glob("**/*.{c,h}").each { |f| return "c" } Dir.glob("**/*.{cs}").each { |f| return "C#" } Dir.glob("**/*.{gemspec}").each { |f| return "gem" } return "ruby" 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=Array.new words=call.output.split if !call.nil? && !call.output.nil? if(words.length>6) return words[words.length-6] end "?" end def context Dev::Environment.user + "." + Dev::Environment.machine end def stamp_task(name) File.open("#{name}.taskstamp." + context,"w") { |f| f.write(Time.now.to_s) } end def dep? return self[:directory].include?("#{self[:dev_root]}/dep/") end def wrk? return self[:directory].include?("#{self[:dev_root]}/wrk/") end end end # module Dev puts_debug "creating DEV instance" DEV=Dev::Project.new#(nil,true) DEV[:start_time]=Time.now