require_relative('internet.rb') class Publish < Array def update if(Internet.available?) Dir.glob('*.gemspec').each{|gemspec_file| add "gem push #{Gemspec.gemfile(gemspec_file)}" if !Gemspec.published? gemspec_file } if(defined?(PUBLISH_PATH)) if(PUBLISH_PATH.include?('svn://') && File.exists?('.svn') && defined?(ARTIFACTS)) latestRev=Publish.svn_latest_revision svn_publish_uri="#{PUBLISH_PATH}/#{Publish.relative_directory}-#{latestRev}" local_dir="#{Command.dev_root}/tmp/#{Publish.relative_directory}@#{latestRev}" FileUtils.mkdir_p(File.dirname(local_dir)) if(!File.exists?(File.dirname(local_dir))) dep_dir="#{Command.dev_root}/dep/#{Publish.relative_directory}@#{latestRev}" svn_info=`svn info #{svn_publish_uri} 2>&1` if(svn_info.include?('URL:')) #puts "#{svn_publish_uri} already exists." else #Console.debug "adding publish commands.." add "svn mkdir #{svn_publish_uri} --parents -m\"publish\"" add "svn checkout #{svn_publish_uri} #{local_dir}" add "<%Publish.copy_files(ARTIFACTS,'#{local_dir}')%>" add "<%Publish.svn_add_all('#{local_dir}')%>" add "svn commit #{local_dir}@ -m\"publish\"" add "<%FileUtils.rm_r('#{local_dir}')%>" end end end end end def self.copy_files files,dest #Console.debug("Environment.copy_files([#{files.to_s}],'#{dest}'')") files.each{|f| if(File.directory?(dest)) dest_file = "#{dest}/#{f}" #Console.debug "copying #{f} to #{dest_file}" FileUtils.mkdir_p(File.dirname(dest_file)) if(!File.exists?(File.dirname(dest_file))) FileUtils.cp(f,dest_file) end } end def self.svn_add_all dir Dir.chdir(dir) do Dir.glob('**/*').each{|f| puts `svn add #{f} --parents` if(!File.directory?(f)) } end end def self.svn_latest_revision if(Dir.exists?(".svn")) `svn info`.scan(/Last Changed Rev: ([\d]+)/).each{|m| return m.first.to_s } end "0" end def self.context dir =Rake.application.original_dir.gsub(Command.dev_root + '/','') return dir.split('/').first end def self.relative_directory Rake.application.original_dir.gsub(Command.dev_root + '/' + Publish.context + '/','') end end