puts_debug "read " + __FILE__.foreground(:green) require 'semver' require 'rake' module Dev class Project < Hash def initialize defaults.each { |name,value| self[name]=value } db = Dev::Database.new db.set_branch_uri(self[:fullname],self[:scm_uri]) 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},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},Jamfile,.semver,Gemfile,README,LICENSE}" if RUBY_PLATFORM.include?("darwin") puts_debug "Dev::Project.defaults :dev_root" h[:dev_root]= "#{Dev::Environment.dev_root}" 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" self[:dep].refresh #update_default_values #db = Dev::Database.new #db.set_branch_uri(self[:fullname],self[:scm_uri]) 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('/').count==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 DEV=Dev::Project.new#(nil,true) #DEV.refresh #PROJECT=DEV DEV[:start_time]=Time.now