module Dev module Cmd class Replace < Hash def refresh(dep_hash) puts_debug "Dev::Cmd::Replace.refresh" refresh_start_time=Time.now # remove all auto generated entries self.each { |k,v| self.delete k if v.kind_of?(Hash) && v.has_key?(:auto) && v[:auto] } # auto generate replace entry based on dep values #if File.exists?(".svn") || File.exists?(".git") if(Scm.get_default_scm_type == "svn" || Scm.get_default_scm_type =="git") ["vcxproj","csproj"].each { |ext| if(Dir.glob("**/*.#{ext}").length > 0) puts_debug "Dev::Cmd::Replace.refresh found file with extension #{ext}" puts_debug "dep_hash nil" if dep_hash.nil? puts_debug "dep_hash is empty" if dep_hash.empty? dep_hash.each{ |k,v| puts_debug "Dev::Cmd::Replace.refresh found dep of key #{k.to_s}" if !v.nil? && v.kind_of?(Hash) && v.has_key?(:rev) && v.has_key?(:dir) && !has_key?(k) puts_debug "adding key #{k.to_s}" if(v[:dir].include?('@')) words=v[:dir].split('@') parts=words[0].split('/'); searchRegex=Regexp.new "#{parts[0]}\\\\#{parts[1]}\\\\#{parts[2]}@[\\d]+" #searchRegex=Regexp.new "#{words[0].gsub('/','\\\\')}@[\\d]+" self[k]={ glob: "**/*.#{ext}", search: searchRegex, replace: "#{words[0].gsub('/','\\')}@#{v[:rev]}", auto: true } else group=v[:dir].split('/')[0] name=v[:dir].split('/')[1] searchRegex=Regexp.new "#{group}\\\\#{name}\\\\[\\d]+" self[k]={ glob: "**/*.#{ext}", search: searchRegex, replace: "#{group}\\#{name}\\#{v[:rev]}", auto: true } end else puts_debug "skipping key #{k.to_s}" end } end } end refresh_end_time=Time.now puts_debug "replace refresh elapsed time " + (refresh_end_time-refresh_start_time).to_s end def execute self.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 # class Replace end # module Cmd end # module Dev