require 'stringio' require 'rexml/document' module BuildMaster class SvnDriver def SvnDriver::from_path(directory) return SvnDriver.new(directory) end attr_reader :work_dir, :repository_url def initialize(work_dir, repository_root = nil, repository_url = nil) @system = work_dir.system @work_dir = work_dir @repository_root = repository_root @repository_url = repository_url end def repository_root load_svn_info unless @repository_root return @repository_root end def repository_url if (not @repository_url) @repository_url = "#{repository_root}/trunk" end return @repository_url end def status command_for_path('status') end def update command_for_path('update') end def commit(comment) command_for_path('commit', " -m \"#{comment}\"") end def tag(tag_name) @system.shell("svn copy #{repository_url} #{repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"") end def checkout(output) @system.shell("svn checkout #{repository_root}/trunk #{output}") end def command(command) command_for_path(command) end private def load_svn_info info = @system.shell_output("svn info #{work_dir.path}") StringIO.new(info).each_line do |line| index = line.index(':') if (index) property = line[0, index].strip value = line[index + 1, line.length - index - 1].strip if (property == 'Repository Root') @repository_root = value elsif (property == 'URL') @repository_url = value end end end end def command_for_path(svn_command, argument='') @system.shell("svn #{svn_command} #{@work_dir.path}#{argument}") end end end