BuildMaster 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. data/README +6 -29
  2. data/lib/buildmaster.rb +0 -2
  3. data/lib/buildmaster/ant_driver.rb +13 -12
  4. data/lib/buildmaster/build_number_file.rb +2 -12
  5. data/lib/buildmaster/buildnumber +1 -1
  6. data/lib/buildmaster/cotta.rb +4 -0
  7. data/lib/buildmaster/cotta/command_error.rb +5 -0
  8. data/lib/buildmaster/cotta/cotta.rb +35 -0
  9. data/lib/buildmaster/cotta/cotta_dir.rb +73 -0
  10. data/lib/buildmaster/cotta/cotta_file.rb +99 -0
  11. data/lib/buildmaster/cotta/file_not_found_error.rb +13 -0
  12. data/lib/buildmaster/cotta/in_memory_system.rb +160 -0
  13. data/lib/buildmaster/cotta/physical_system.rb +64 -0
  14. data/lib/buildmaster/cvs_driver.rb +5 -13
  15. data/lib/buildmaster/file_processor.rb +34 -33
  16. data/lib/buildmaster/java_manifest.rb +3 -3
  17. data/lib/buildmaster/site/site.rb +11 -22
  18. data/lib/buildmaster/site_spec.rb +15 -13
  19. data/lib/buildmaster/source_file_handler.rb +1 -1
  20. data/lib/buildmaster/svn_driver.rb +14 -20
  21. data/lib/buildmaster/{template_exception.rb → template_error.rb} +1 -1
  22. data/lib/buildmaster/template_runner.rb +2 -2
  23. data/lib/buildmaster/templatelets/attribute.rb +1 -1
  24. data/lib/buildmaster/templatelets/href.rb +1 -1
  25. data/lib/buildmaster/templatelets/text.rb +1 -1
  26. data/lib/buildmaster/templatelets/when.rb +1 -1
  27. data/lib/buildmaster/windows.rb +3 -0
  28. data/lib/buildmaster/windows/iis_driver.rb +33 -0
  29. data/lib/buildmaster/windows/sql_server_driver.rb +27 -0
  30. data/test/buildmaster/cotta/content.txt +3 -0
  31. data/test/buildmaster/cotta/cotta_specifications.rb +172 -0
  32. data/test/buildmaster/cotta/physical_system_stub.rb +85 -0
  33. data/test/buildmaster/cotta/system_file_specifications.rb +131 -0
  34. data/test/buildmaster/cotta/tc_cotta.rb +33 -0
  35. data/test/buildmaster/cotta/tc_cotta_dir_in_memory.rb +23 -0
  36. data/test/buildmaster/cotta/tc_cotta_dir_physical.rb +17 -0
  37. data/test/buildmaster/cotta/tc_cotta_file_in_memory.rb +20 -0
  38. data/test/buildmaster/cotta/tc_cotta_file_physical.rb +17 -0
  39. data/test/buildmaster/cotta/tc_in_memory_system.rb +25 -0
  40. data/test/buildmaster/cotta/tc_physical_system.rb +26 -0
  41. data/test/buildmaster/manifest.mf +1 -1
  42. data/test/buildmaster/site/tc_site.rb +58 -34
  43. data/test/buildmaster/site/tc_template_builder.rb +32 -31
  44. data/test/buildmaster/tc_ant_driver.rb +11 -13
  45. data/test/buildmaster/tc_build_number_file.rb +21 -16
  46. data/test/buildmaster/tc_cvs_driver.rb +35 -37
  47. data/test/buildmaster/tc_file_processor.rb +58 -34
  48. data/test/buildmaster/tc_java_manifest.rb +37 -9
  49. data/test/buildmaster/tc_site_spec.rb +20 -15
  50. data/test/buildmaster/tc_source_file_handler.rb +4 -4
  51. data/test/buildmaster/tc_svn_driver.rb +51 -38
  52. data/test/buildmaster/tc_template_runner.rb +19 -18
  53. data/test/buildmaster/tc_tree_to_object.rb +47 -46
  54. data/test/buildmaster/tc_xtemplate.rb +52 -38
  55. data/test/buildmaster/templatelets/common_templatelet_test.rb +9 -8
  56. data/test/buildmaster/templatelets/tc_attribute.rb +26 -23
  57. data/test/buildmaster/templatelets/tc_each.rb +27 -26
  58. data/test/buildmaster/templatelets/tc_href.rb +14 -13
  59. data/test/buildmaster/templatelets/tc_include.rb +11 -4
  60. data/test/buildmaster/templatelets/tc_link.rb +18 -12
  61. data/test/buildmaster/templatelets/tc_text.rb +12 -7
  62. data/test/buildmaster/templatelets/tc_when.rb +11 -5
  63. data/test/buildmaster/windows/tc_iis_driver.rb +29 -0
  64. data/test/buildmaster/windows/tc_sql_server_driver.rb +24 -0
  65. data/test/spec_runner.rb +27 -0
  66. data/test/ts_buildmaster.rb +2 -19
  67. metadata +34 -10
  68. data/lib/buildmaster/release_control.rb +0 -22
  69. data/lib/buildmaster/shell_command.rb +0 -39
  70. data/test/buildmaster/tc_release_control.rb +0 -27
  71. data/test/buildmaster/ts_site.rb +0 -4
  72. data/test/buildmaster/ts_templatelets.rb +0 -10
@@ -0,0 +1,64 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'file_not_found_error'
4
+ require 'command_error'
5
+ require 'fileutils'
6
+
7
+ module BuildMaster
8
+ class PhysicalSystem
9
+ def initialize
10
+ end
11
+
12
+ def shell(command)
13
+ raise CommandError.new, command, caller unless system(command)
14
+ end
15
+
16
+ def environment!(variable)
17
+ value = ENV[variable]
18
+ raise "#{variable} environment variable not found" unless value
19
+ return value
20
+ end
21
+
22
+ def environment(variable, default)
23
+ value = ENV[variable]
24
+ value = default unless value
25
+ return value
26
+ end
27
+
28
+ def dir_exists?(dir_path)
29
+ return FileTest.directory?(dir_path)
30
+ end
31
+
32
+ def file_exists?(file_path)
33
+ return FileTest.file?(file_path)
34
+ end
35
+
36
+ def list(dir_path)
37
+ Dir.entries(dir_path).find_all {|item| item != '.' && item != '..'}
38
+ end
39
+
40
+ def mkdir(dir_path)
41
+ Dir.mkdir(dir_path)
42
+ end
43
+
44
+ def io(file_path, argument)
45
+ return File.open(file_path, argument)
46
+ end
47
+
48
+ def delete_file(file_path)
49
+ return File.delete(file_path)
50
+ end
51
+
52
+ def delete_dir(dir_path)
53
+ return Dir.delete(dir_path)
54
+ end
55
+
56
+ def copy(source, target)
57
+ FileUtils.copy(source, target)
58
+ end
59
+
60
+ def move(source, target)
61
+ FileUtils.move(source, target)
62
+ end
63
+ end
64
+ end
@@ -10,36 +10,28 @@ class CvsInfo
10
10
  end
11
11
 
12
12
  def CvsInfo.load(folder)
13
- return CvsInfo.new(read("#{folder}/Root").strip!, read("#{folder}/Repository").strip!)
14
- end
15
-
16
- private
17
- def CvsInfo.read(file)
18
- File.open(file) do |file|
19
- return file.gets
20
- end
13
+ return CvsInfo.new(folder.file('ROOT').load.strip, folder.file('Repository').load.strip)
21
14
  end
22
15
 
23
16
  end
24
17
 
25
18
  class CvsDriver
26
- include Shell
27
19
  def CvsDriver.from_path(working_directory)
28
20
  return CvsDriver.new(CvsInfo.load("#{working_directory}/CVS"), working_directory)
29
21
  end
30
22
 
31
- def initialize(cvs_info, working_directory, &command_runner)
23
+ def initialize(cvs_info, working_directory)
32
24
  @cvs_info = cvs_info
33
25
  @working_directory = working_directory
34
- @command_runner = command_runner
26
+ @cotta = @working_directory.cotta
35
27
  end
36
28
 
37
29
  def command(command)
38
- run_command "cvs -d #{@cvs_info.root} #{command} #{@working_directory}"
30
+ @cotta.shell "cvs -d #{@cvs_info.root} #{command} #{@working_directory.path}"
39
31
  end
40
32
 
41
33
  def checkout()
42
- run_command("cvs -d #{@cvs_info.root} co -d #{@working_directory} #{@cvs_info.repository}")
34
+ @cotta.shell("cvs -d #{@cvs_info.root} co -d #{@working_directory.path} #{@cvs_info.repository}")
43
35
  end
44
36
 
45
37
  def update(option='')
@@ -18,13 +18,13 @@ class FileProcessor
18
18
  return result
19
19
  end
20
20
 
21
- attr_reader :path_to_content_file, :path_to_target_file
21
+ attr_reader :content_file, :target_file
22
22
 
23
- def initialize(template, path_to_content_file, sitespec)
23
+ def initialize(template, content_file, sitespec)
24
24
  @template = template
25
- @path_to_content_file = path_to_content_file
25
+ @content_file = content_file
26
26
  @sitespec = sitespec
27
- extension = File.extname(path_to_content_file)
27
+ extension = content_file.extname
28
28
  if (extension == '.html')
29
29
  @convert_method = 'process_html'
30
30
  elsif (extension == '.textile')
@@ -33,53 +33,54 @@ class FileProcessor
33
33
  @convert_method = 'process_markdown'
34
34
  end
35
35
  if @convert_method
36
- basename = File.basename(path_to_content_file, extension).to_s
37
- @path = sitespec.relative_to_root(path_to_content_file).parent.join("#{basename}.html")
38
- @path_to_target_file = FileProcessor.join(sitespec.output_dir, @path)
36
+ basename = content_file.basename
37
+ @path = sitespec.relative_to_root(content_file).parent.join("#{basename}.html")
38
+ @target_file = sitespec.output_dir.file(@path)
39
39
  else
40
- @path_to_target_file = FileProcessor.join(sitespec.output_dir, sitespec.relative_to_root(path_to_content_file))
40
+ @target_file = sitespec.output_dir.file(sitespec.relative_to_root(content_file))
41
41
  end
42
42
  end
43
43
 
44
44
  def FileProcessor::for_request_path(request_path, site_spec)
45
45
  template = site_spec.load_template
46
- relative_to_root = Pathname.new("#{request_path}")
47
- dir = relative_to_root.parent
48
- extension = relative_to_root.extname.to_s
49
- result = nil
50
- path_to_content = nil
51
- if (extension == '.html')
52
- basename = relative_to_root.basename(extension).to_s
53
- source_directory = join(site_spec.content_dir, dir)
54
- ['textile', 'markdown', 'html'].find do |extension_candidate|
55
- filename = "#{basename}.#{extension_candidate}"
56
- candidate = File.join(source_directory, filename)
57
- if (FileTest.file? candidate)
58
- path_to_content = candidate
59
- true
60
- else
61
- false
62
- end
63
- end
46
+ if (request_path[0,1] == '/')
47
+ request_path = request_path[1, request_path.length - 1]
64
48
  end
65
- if (not path_to_content)
66
- path_to_content = join(site_spec.content_dir, relative_to_root)
49
+ file = site_spec.content_dir.file(request_path)
50
+ if (file.extname == '.html')
51
+ file = check_source(file)
67
52
  end
68
- return FileProcessor.new(template, path_to_content, site_spec)
53
+ return FileProcessor.new(template, file, site_spec)
54
+ end
55
+
56
+ def FileProcessor::check_source(file)
57
+ result = file
58
+ basename = file.basename
59
+ dir = file.parent
60
+ ['textile', 'markdown', 'html'].find do |extension|
61
+ candidate = dir.file("#{basename}.#{extension}")
62
+ if (candidate.exists?)
63
+ result = candidate
64
+ true
65
+ else
66
+ false
67
+ end
68
+ end
69
+ return result
69
70
  end
70
71
 
71
72
  def is_html?
72
- return File.extname(path_to_target_file) == '.html'
73
+ return target_file.extname == '.html'
73
74
  end
74
75
 
75
76
  def write_to_target
76
77
  document = generate_document
77
78
  if (document)
78
- File.open(path_to_target_file, 'w') do |file|
79
+ target_file.write do |file|
79
80
  document.write(file, 0, false, true)
80
81
  end
81
82
  else
82
- FileUtils.cp path_to_content_file, path_to_target_file
83
+ content_file.copy_to(target_file)
83
84
  end
84
85
  end
85
86
 
@@ -89,7 +90,7 @@ class FileProcessor
89
90
 
90
91
 
91
92
  def load_content
92
- return IO.read(path_to_content_file)
93
+ return content_file.load
93
94
  end
94
95
 
95
96
  def process_textile(textile_content)
@@ -11,7 +11,7 @@ class JavaManifest
11
11
  def version
12
12
  number = nil
13
13
  build = nil
14
- IO.foreach(@manifest_file) do |line|
14
+ @manifest_file.foreach do |line|
15
15
  name_value = NameValue.parse(line)
16
16
  if (name_value.name== "Implementation-Version")
17
17
  number = name_value.value
@@ -26,7 +26,7 @@ class JavaManifest
26
26
  content = ""
27
27
  number = nil
28
28
  build = nil
29
- IO.foreach(@manifest_file) do |line|
29
+ @manifest_file.foreach do |line|
30
30
  name_value = NameValue.parse(line)
31
31
  if (name_value.name== "Implementation-Version")
32
32
  number = name_value.value
@@ -38,7 +38,7 @@ class JavaManifest
38
38
  content = content + line
39
39
  end
40
40
  end
41
- File.open(@manifest_file, "w") do |file|
41
+ @manifest_file.write do |file|
42
42
  file.printf(content)
43
43
  end
44
44
  return Version.new(number, build)
@@ -60,34 +60,23 @@ require 'buildmaster/site_tester'
60
60
  end
61
61
  end
62
62
 
63
- def ensure_directory_exists(dir_name)
64
- if (not File.exist?(dir_name))
65
- ensure_directory_exists(File.join(dir_name, '..'))
66
- Dir.mkdir dir_name
67
- end
68
- end
69
-
70
63
  def build_directory(out_dir, content_dir, template)
71
- ensure_directory_exists(out_dir)
72
- Dir.foreach(content_dir) do |item|
73
- content_path = File.join(content_dir, item)
74
- if (item == '.' || item == '..' || item == '.svn' || item == 'CVS')
75
- elsif (File.directory? content_path)
76
- build_directory(File.join(out_dir, item), content_path, template)
77
- else
78
- @current_file_name = content_path
79
- process_file(content_path, out_dir, content_dir, item)
64
+ out_dir.mkdirs
65
+ content_dir.list.each do |item|
66
+ if (item.name == '.svn' || item.name == 'CVS' || item.name == '_svn')
67
+ elsif (item.respond_to? 'list')
68
+ build_directory(out_dir.dir(item.name), item, template)
69
+ elsif (item.respond_to? 'read')
70
+ @current_file_name = item
71
+ process_file(item, out_dir, content_dir, item)
80
72
  @count = @count + 1
81
73
  end
82
74
  end
83
75
  end
84
76
 
85
- def process_file(path_to_content, out_dir, content_dir, item)
86
- print ">> #{path_to_content}\n"
87
- extension = File.extname(path_to_content)
88
- isIndex = @current_file_name =~ /^index/
89
- file_processor = FileProcessor.new(@template, path_to_content, @spec)
90
- file_processor.write_to_target
77
+ def process_file(content_file, out_dir, content_dir, item)
78
+ print ">> #{content_file.path.to_s}\n"
79
+ FileProcessor.new(@template, content_file, @spec).write_to_target
91
80
  end
92
81
 
93
82
  end
@@ -4,6 +4,7 @@ require 'pathname'
4
4
  require 'templatelets'
5
5
  require 'tree_to_object'
6
6
  require 'site/template_builder'
7
+ require 'cotta'
7
8
 
8
9
  module BuildMaster
9
10
 
@@ -11,8 +12,9 @@ module BuildMaster
11
12
  attr_reader :output_dir
12
13
  attr_accessor :content_dir, :template, :template_file
13
14
 
14
- def initialize(file = nil)
15
- @root = File.dirname(file) if file
15
+ def initialize(file = nil, cotta = Cotta.new())
16
+ @root = cotta.file(file).parent if file
17
+ @cotta = cotta
16
18
  if (block_given?)
17
19
  yield self
18
20
  end
@@ -20,17 +22,17 @@ module BuildMaster
20
22
 
21
23
  def output_dir=(path)
22
24
  if (@root)
23
- @output_dir = File.join(@root, path)
25
+ @output_dir = @root.dir(path)
24
26
  else
25
- @output_dir = path
27
+ @output_dir = @cotta.dir(path)
26
28
  end
27
29
  end
28
30
 
29
31
  def content_dir=(path)
30
32
  if (@root)
31
- @content_dir = File.join(@root, path)
33
+ @content_dir = @root.dir(path)
32
34
  else
33
- @content_dir = path
35
+ @content_dir = @cotta.dir(path)
34
36
  end
35
37
  end
36
38
 
@@ -44,7 +46,7 @@ module BuildMaster
44
46
  end
45
47
 
46
48
  def validate_inputs
47
- validate_dir(@content_dir, :content_dir)
49
+ validate_dir(content_dir, :content_dir)
48
50
  end
49
51
 
50
52
  def load_template
@@ -69,17 +71,17 @@ module BuildMaster
69
71
  if (@template)
70
72
  return @template
71
73
  else
72
- return File.open(@template_file)
74
+ return @template_file.load
73
75
  end
74
76
  end
75
77
 
76
78
  def load_document(path)
77
- return REXML::Document.new(File.open(File.join(content_dir, path)))
79
+ content_dir.file(path).read {|file| REXML::Document.new(file)}
78
80
  end
79
81
 
80
82
  def relative_to_root(path)
81
- to = path_name(path)
82
- from = path_name(@content_dir)
83
+ to = path_name(path.path.to_s)
84
+ from = path_name(@content_dir.path.to_s)
83
85
  return to.relative_path_from(from)
84
86
  end
85
87
 
@@ -109,10 +111,10 @@ module BuildMaster
109
111
  if not directory
110
112
  raise "Directory for #{symbol.id2name} not specified"
111
113
  end
112
- if not File.exists? directory
114
+ if not directory.exists?
113
115
  raise "Directory for #{symbol.id2name} -- <#{directory}> does not exist"
114
116
  end
115
- if not File.directory? directory
117
+ if not directory.exists?
116
118
  raise "<#{directory}> should be a directory for #{symbol.id2name}"
117
119
  end
118
120
  end
@@ -17,7 +17,7 @@ class SourceFileHandler < WEBrick::HTTPServlet::AbstractServlet
17
17
  @config = server.config
18
18
  @logger = @config[:Logger]
19
19
  @spec = spec
20
- @delegate = WEBrick::HTTPServlet::FileHandler.new(server, spec.content_dir, true)
20
+ @delegate = WEBrick::HTTPServlet::FileHandler.new(server, spec.content_dir.path, true)
21
21
  end
22
22
 
23
23
  def service(req, res)
@@ -4,15 +4,16 @@ require 'rexml/document'
4
4
  module BuildMaster
5
5
 
6
6
  class SvnInfo
7
- attr_reader :path, :repository_root
7
+ attr_reader :work_dir, :repository_root
8
8
 
9
- def initialize(path)
10
- @path = path
11
- analyze_entry_file(File.join(path, ".svn", "entries"))
9
+ def initialize(work_dir)
10
+ @work_dir = work_dir
11
+ entries = work_dir.dir('.svn').file('entries')
12
+ analyze_entry_file(entries)
12
13
  end
13
14
 
14
- def analyze_entry_file(path)
15
- File.open(path, 'r') do |file|
15
+ def analyze_entry_file(entry_file)
16
+ @repository_root = entry_file.read do |file|
16
17
  parse_xml_load_repository_root(file)
17
18
  end
18
19
  end
@@ -21,26 +22,20 @@ class SvnInfo
21
22
  def parse_xml_load_repository_root(file)
22
23
  xml = REXML::Document.new(file)
23
24
  xml.root.each_element_with_attribute('name', '', 1) do |element|
24
- @repository_root = element.attributes['repos']
25
+ return element.attributes['repos']
25
26
  end
26
27
  end
27
28
 
28
29
  end
29
30
 
30
- class SvnDriver
31
- include Shell
32
-
31
+ class SvnDriver
33
32
  def SvnDriver::from_path(directory)
34
33
  return SvnDriver.new(SvnInfo.new(directory))
35
34
  end
36
35
 
37
- def initialize(svn_info, &command_runner)
36
+ def initialize(svn_info)
38
37
  @svn_info = svn_info
39
- if (command_runner)
40
- @command_runner = command_runner
41
- else
42
- @command_runner = Proc.new {|command| run(command)}
43
- end
38
+ @system = svn_info.work_dir.system
44
39
  end
45
40
 
46
41
  def status
@@ -56,11 +51,11 @@ class SvnDriver
56
51
  end
57
52
 
58
53
  def tag(tag_name)
59
- run_command("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
54
+ @system.shell("svn copy #{@svn_info.repository_root}/trunk #{@svn_info.repository_root}/tags/#{tag_name} -m \"ruby buildmaster\"")
60
55
  end
61
56
 
62
57
  def checkout(output)
63
- run_command("svn checkout #{@svn_info.repository_root}/trunk #{output}")
58
+ @system.shell("svn checkout #{@svn_info.repository_root}/trunk #{output}")
64
59
  end
65
60
 
66
61
  def command(command)
@@ -68,9 +63,8 @@ class SvnDriver
68
63
  end
69
64
 
70
65
  private
71
-
72
66
  def command_for_path(svn_command, argument='')
73
- run_command("svn #{svn_command} #{@svn_info.path}#{argument}")
67
+ @system.shell("svn #{svn_command} #{@svn_info.work_dir.path}#{argument}")
74
68
  end
75
69
  end
76
70