require 'rexml/document' module BuildMaster class SvnInfo attr_reader :path, :repository_root def initialize(path) @path = path analyze_entry_file(File.join(path, ".svn", "entries")) end def analyze_entry_file(file) xml = REXML::Document.new(File.open(file)) xml.root.each_element_with_attribute('name', '', 1) do |element| @repository_root = element.attributes['repos'] end end end class SvnDriver include Shell def SvnDriver::from_path(directory) return SvnDriver.new(SvnInfo.new(directory)) end def initialize(svn_info, &command_runner) @svn_info = svn_info if (command_runner) @command_runner = command_runner else @command_runner = Proc.new {|command| run(command)} end 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) run_command("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"") end def checkout(output) run_command("svn checkout #{@svn_info.repository_root}/trunk #{output}") end def command(command) command_for_path(command) end private def command_for_path(svn_command, argument='') run_command("svn #{svn_command} #{@svn_info.path}#{argument}") end end end