lib/buildmaster/svn_driver.rb in BuildMaster-0.9.0 vs lib/buildmaster/svn_driver.rb in BuildMaster-0.9.1

- old
+ new

@@ -1,45 +1,36 @@ require 'stringio' require 'rexml/document' module BuildMaster -class SvnInfo - attr_reader :work_dir, :repository_root - - def initialize(work_dir) - @work_dir = work_dir - entries = work_dir.dir('.svn').file('entries') - analyze_entry_file(entries) - end - - def analyze_entry_file(entry_file) - @repository_root = entry_file.read do |file| - parse_xml_load_repository_root(file) - end - end - - private - def parse_xml_load_repository_root(file) - xml = REXML::Document.new(file) - xml.root.each_element_with_attribute('name', '', 1) do |element| - return element.attributes['repos'] - end - end - -end - class SvnDriver def SvnDriver::from_path(directory) - return SvnDriver.new(SvnInfo.new(directory)) + return SvnDriver.new(directory) end - def initialize(svn_info) - @svn_info = svn_info - @system = svn_info.work_dir.system + 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 @@ -49,23 +40,39 @@ def commit(comment) command_for_path('commit', " -m \"#{comment}\"") end def tag(tag_name) - @system.shell("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"") + @system.shell("svn copy #{repository_url} #{repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"") end def checkout(output) - @system.shell("svn checkout #{@svn_info.repository_root}/trunk #{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} #{@svn_info.work_dir.path}#{argument}") + @system.shell("svn #{svn_command} #{@work_dir.path}#{argument}") end end end \ No newline at end of file