BuildMaster 0.7.0 → 0.8.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 (56) hide show
  1. data/README +26 -0
  2. data/lib/buildmaster.rb +2 -1
  3. data/lib/buildmaster/build_number_file.rb +27 -0
  4. data/lib/buildmaster/buildnumber +1 -0
  5. data/lib/buildmaster/file_processor.rb +114 -25
  6. data/lib/buildmaster/java_manifest.rb +4 -0
  7. data/lib/buildmaster/{site.rb → site/site.rb} +11 -46
  8. data/lib/buildmaster/site/template/buildmaster.css +340 -0
  9. data/lib/buildmaster/site/template/buildmaster_template.xml +130 -0
  10. data/lib/buildmaster/site/template_builder.rb +276 -0
  11. data/lib/buildmaster/site_server.rb +33 -0
  12. data/lib/buildmaster/site_spec.rb +74 -22
  13. data/lib/buildmaster/site_tester.rb +14 -2
  14. data/lib/buildmaster/source_content.rb +11 -0
  15. data/lib/buildmaster/source_file_handler.rb +7 -2
  16. data/lib/buildmaster/svn_driver.rb +23 -11
  17. data/lib/buildmaster/template_exception.rb +8 -0
  18. data/lib/buildmaster/template_runner.rb +19 -86
  19. data/lib/buildmaster/templatelets.rb +23 -0
  20. data/lib/buildmaster/templatelets/attribute.rb +16 -0
  21. data/lib/buildmaster/templatelets/each.rb +43 -0
  22. data/lib/buildmaster/templatelets/href.rb +39 -0
  23. data/lib/buildmaster/templatelets/include.rb +30 -0
  24. data/lib/buildmaster/templatelets/link.rb +41 -0
  25. data/lib/buildmaster/templatelets/text.rb +14 -0
  26. data/lib/buildmaster/templatelets/when.rb +24 -0
  27. data/lib/buildmaster/tree_to_object.rb +76 -0
  28. data/lib/buildmaster/xtemplate.rb +10 -11
  29. data/test/buildmaster/manifest.mf +1 -1
  30. data/test/buildmaster/{content → site/content}/index.html +0 -0
  31. data/test/buildmaster/site/content/markdown.markdown +0 -0
  32. data/test/buildmaster/site/content/textile.textile +0 -0
  33. data/test/buildmaster/{tc_site.rb → site/tc_site.rb} +1 -1
  34. data/test/buildmaster/site/tc_template_builder.rb +128 -0
  35. data/test/buildmaster/tc_build_number_file.rb +31 -0
  36. data/test/buildmaster/tc_file_processor.rb +81 -14
  37. data/test/buildmaster/tc_site_spec.rb +26 -42
  38. data/test/buildmaster/tc_source_file_handler.rb +55 -0
  39. data/test/buildmaster/tc_template_runner.rb +42 -1
  40. data/test/buildmaster/tc_tree_to_object.rb +120 -0
  41. data/test/buildmaster/tc_xtemplate.rb +13 -233
  42. data/test/buildmaster/templatelets/common_templatelet_test.rb +27 -0
  43. data/test/buildmaster/templatelets/tc_attribute.rb +57 -0
  44. data/test/buildmaster/templatelets/tc_each.rb +69 -0
  45. data/test/buildmaster/templatelets/tc_href.rb +48 -0
  46. data/test/buildmaster/templatelets/tc_include.rb +34 -0
  47. data/test/buildmaster/templatelets/tc_link.rb +70 -0
  48. data/test/buildmaster/templatelets/tc_text.rb +36 -0
  49. data/test/buildmaster/templatelets/tc_when.rb +59 -0
  50. data/test/buildmaster/ts_site.rb +4 -0
  51. data/test/buildmaster/ts_templatelets.rb +10 -0
  52. data/test/tmp/output/index.html +8 -0
  53. data/test/tmp/output/markdown.html +8 -0
  54. data/test/tmp/output/textile.html +8 -0
  55. data/test/ts_buildmaster.rb +15 -3
  56. metadata +102 -53
@@ -0,0 +1,27 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "..", "lib")
2
+
3
+ require 'rexml/xpath'
4
+ require 'rexml/document'
5
+ require 'test/unit'
6
+ require 'buildmaster/site_spec'
7
+ require 'buildmaster/source_content'
8
+ require 'buildmaster/template_exception'
9
+ require 'buildmaster/templatelets'
10
+
11
+ module BuildMaster
12
+ class CommonTemplateletTest < Test::Unit::TestCase
13
+ def setup
14
+ @site_spec = SiteSpec.new
15
+ @site_spec.content_dir = '/tmp/workingdir/content'
16
+ end
17
+
18
+ def create_element(name)
19
+ element = REXML::Element.new
20
+ element.name=name
21
+ return element
22
+ end
23
+
24
+ def test_dummy
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'buildmaster/template_exception'
8
+ require 'buildmaster/templatelets/attribute'
9
+
10
+ module BuildMaster
11
+ class AttributeTest < CommonTemplateletTest
12
+ def test_should_set_attribute_based_on_evaluation
13
+ templatelet = Attribute.new(AttributeForTest.new(self))
14
+ target = create_element('a')
15
+ template_element = create_attribute_element('attr-name', 'expression')
16
+ expected_pathname = Pathname.new('/path')
17
+ @source_path = SourceContent.new(expected_pathname, nil)
18
+ templatelet.process(target, template_element, @source_path)
19
+ assert_equal('value', target.attributes['attr-name'])
20
+ assert_equal(expected_pathname, @path_logged)
21
+ end
22
+
23
+ def test_should_check_for_expression_responder
24
+ target = create_element('a')
25
+ template_element = create_attribute_element('name', 'eval')
26
+ source_path = SourceContent.new(Pathname.new('./'), create_element('name'))
27
+ begin
28
+ Attribute.new(self).process(target, template_element, source_path)
29
+ fail('template exception should have been thrown')
30
+ rescue TemplateException => e
31
+ assert_equal(true, e.message.include?('eval'))
32
+ end
33
+ end
34
+
35
+ def create_attribute_element(name, eval)
36
+ element = create_element('attribute')
37
+ element.attributes['name'] = name
38
+ element.attributes['eval'] = eval
39
+ return element
40
+ end
41
+
42
+ def expression_called_with(path)
43
+ @path_logged = path
44
+ end
45
+ end
46
+
47
+ class AttributeForTest
48
+ def initialize(logger)
49
+ @logger = logger
50
+ end
51
+
52
+ def expression(path)
53
+ @logger.expression_called_with(path)
54
+ return 'value'
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,69 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'buildmaster/template_runner'
8
+
9
+ module BuildMaster
10
+
11
+ class EachTest < CommonTemplateletTest
12
+ def test_should_iteration_through_selected_elements
13
+ template_content = <<CONTENT
14
+ <each source="rss" select="/rss/item" count="2">
15
+ <div class="NewsItem">
16
+ <p class="Title"><include elements="./title/text()"/></p>
17
+ <p class="Date"><include elements="./pubDate/text()"/></p>
18
+ </div>
19
+ </each>
20
+ CONTENT
21
+ target = create_element('test')
22
+ template = REXML::XPath.first(REXML::Document.new(template_content), '/each')
23
+ site = MySite.new
24
+ each_processor = Each.new(site)
25
+ each_processor.process(target, template, SourceContent.new('doc/doc.html', nil))
26
+ assert_equal('NewsItem', REXML::XPath.first(target, 'div').attributes['class'])
27
+ assert_equal(2, REXML::XPath.match(target, 'div').size)
28
+ end
29
+
30
+ def on_line_test_rss_uri_need_start_a_server
31
+ template_content = <<CONTENT
32
+ <each source="http://localhost:2000/news-rss2.xml" select="/rss/item" count="2">
33
+ <div class="NewsItem">
34
+ <p class="Title"><include elements="./title/text()"/></p>
35
+ <p class="Date"><include elements="./pubDate/text()"/></p>
36
+ </div>
37
+ </each>
38
+ CONTENT
39
+ target = create_element('test')
40
+ template = REXML::XPath.first(REXML::Document.new(template_content), '/each')
41
+ site = MySite.new
42
+ each_processor = Each.new(site)
43
+ each_processor.process(target, template, SourceContent.new('doc/doc.html', nil))
44
+ assert_equal('NewsItem', REXML::XPath.first(target, 'div').attributes['class'])
45
+ assert_equal(2, REXML::XPath.match(target, 'div').size)
46
+
47
+ end
48
+ end
49
+
50
+ class MySite < SiteSpec
51
+ def load_document(path)
52
+ content = <<CONTENT
53
+ <rss>
54
+ <item>
55
+ <title>Title One</title>
56
+ <pubDate>Today</pubDate>
57
+ </item>
58
+ <item>
59
+ <title>Title Two</title>
60
+ <pubDate>Tomorrow</pubDate>
61
+ </item>
62
+ </rss>
63
+ CONTENT
64
+
65
+ return REXML::Document.new(content)
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,48 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ module BuildMaster
8
+ class HrefTest < CommonTemplateletTest
9
+ def setup
10
+ super
11
+ @template_element = create_element('href')
12
+ @target_element = create_element('a')
13
+ @href = Href.new(@site_spec)
14
+ end
15
+
16
+ def source(path)
17
+ SourceContent.new(Pathname.new(path), nil)
18
+ end
19
+
20
+ def test_should_populate_href_attribute_with_full_url
21
+ expected_url = 'http://www.rubyforge.org'
22
+ @template_element.attributes['url']=expected_url
23
+ @href.process(@target_element, @template_element, source('index.html'))
24
+ assert_equal(expected_url, @target_element.attributes['href'])
25
+ end
26
+
27
+ def test_should_populate_href_attribute_with_relative_path
28
+ @template_element.attributes['url']='doc/doc.html'
29
+ @href.process(@target_element, @template_element, source('download/index.html'))
30
+ assert_equal('../doc/doc.html', @target_element.attributes['href'])
31
+ end
32
+
33
+ def test_should_support_image_tag_by_generating_src_attribute
34
+ @template_element.attributes['url']='doc/doc.gif'
35
+ @target_element = create_element('img')
36
+ @href.process(@target_element, @template_element, source('download/download.html'))
37
+ assert_equal('../doc/doc.gif', @target_element.attributes['src'])
38
+ end
39
+
40
+ def test_should_handle_external_links
41
+ @template_element.attributes['url'] = 'http://www.google.com'
42
+ @target_element = create_element('img')
43
+ @href.process(@target_element, @template_element, source('download/download.html'))
44
+ assert_equal('http://www.google.com', @target_element.attributes['src'])
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,34 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'rexml/document'
8
+ require 'rexml/element'
9
+ require 'buildmaster/site_spec'
10
+ require 'buildmaster/source_content'
11
+ require 'buildmaster/templatelets/include'
12
+
13
+ module BuildMaster
14
+ class IncludeTest < CommonTemplateletTest
15
+ def test_should_include_the_source
16
+ target = create_element('target')
17
+ template = create_element('include')
18
+ template.attributes['elements'] = '/item/*'
19
+ source_content = <<CONTENT
20
+ <item>
21
+ text
22
+ <one>test</one>
23
+ <two></two>
24
+ </item>
25
+ CONTENT
26
+ source = SourceContent.new(Pathname.new('doc/index.html'), REXML::Document.new(source_content))
27
+ include = Include.new(SiteSpec.new)
28
+ include.process(target, template, source)
29
+ assert_equal('test', REXML::XPath.first(target, 'one').text)
30
+ assert_equal('text', target.text.strip!)
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,70 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'rexml/document'
8
+ require 'rexml/xpath'
9
+ require 'buildmaster/site_spec'
10
+ require 'buildmaster/source_content'
11
+
12
+ module BuildMaster
13
+ class LinkTest < CommonTemplateletTest
14
+ def test_should_generate_link_with_relative_path
15
+ target = create_element('div')
16
+ template_content = <<CONTENT
17
+ <?xml ?>
18
+ <root>
19
+ <link href="content/path.html">text</link>
20
+ </root>
21
+ CONTENT
22
+ template_document = REXML::Document.new(template_content)
23
+ template = REXML::XPath.first(template_document, '/root/link')
24
+ source = create_element('source')
25
+ link = Link.new(SiteSpec.new)
26
+ link.process(target, template, SourceContent.new(Pathname.new('doc/doc.html'), source))
27
+ actual = REXML::XPath.first(target, 'a')
28
+ assert_equal('../content/path.html', actual.attributes['href'])
29
+ assert_equal('text', actual.text)
30
+ end
31
+
32
+ def test_should_copy_all_attributes
33
+ target = create_element('div')
34
+ template = create_element('link')
35
+ template.attributes['href'] = 'content/path.html'
36
+ template.attributes['attribute1'] = 'value1'
37
+ template.attributes['attribute2'] = 'value2'
38
+ source = create_element('source')
39
+ link = Link.new(SiteSpec.new)
40
+ link.process(target, template, SourceContent.new(Pathname.new('doc/doc.html'), source))
41
+ actual = REXML::XPath.first(target, 'a')
42
+ assert_equal('value1', actual.attributes['attribute1'])
43
+ assert_equal('value2', actual.attributes['attribute2'])
44
+ end
45
+
46
+ def test_should_handle_absolute_path
47
+ target = create_element('div')
48
+ template = create_element('link')
49
+ template.attributes['href'] = '/content/path.html'
50
+ source = create_element('source')
51
+ link = Link.new(SiteSpec.new)
52
+ link.process(target, template, SourceContent.new(Pathname.new('doc/iste/doc.html'), source))
53
+ actual = REXML::XPath.first(target, 'a')
54
+ assert_equal('../../content/path.html', actual.attributes['href'])
55
+ end
56
+
57
+ def test_should_generate_div_with_current_class_attribute_if_link_is_on_current_page
58
+ target = create_element('div')
59
+ template = create_element('link')
60
+ template.attributes['href'] = '/content/path.html'
61
+ source = create_element('source')
62
+ link = Link.new(SiteSpec.new)
63
+ link.process(target, template, SourceContent.new(Pathname.new('content/path.html'), source))
64
+ actual = REXML::XPath.first(target, 'div')
65
+ assert_equal(nil, actual.attributes['href'])
66
+ assert_equal('current', actual.attributes['class'])
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,36 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'rexml/document'
8
+ require 'rexml/xpath'
9
+ require 'buildmaster/site_spec'
10
+ require 'buildmaster/source_content'
11
+
12
+ module BuildMaster
13
+ class TextTest < CommonTemplateletTest
14
+ def test_should_generate_text_based_on_property
15
+ target = create_element('target')
16
+ template = create_element('text')
17
+ template.attributes['property'] = 'property'
18
+ text = Text.new({'property' => 'text'})
19
+ text.process(target, template, nil)
20
+ assert_equal('text', target.text)
21
+ end
22
+
23
+ def test_should_throw_exception_if_property_not_set
24
+ target = create_element('target')
25
+ template = create_element('text')
26
+ template.attributes['property'] = 'one'
27
+ text = Text.new(Hash.new)
28
+ begin
29
+ text.process(target, template, nil)
30
+ fail('TemplateException should have been thrown')
31
+ rescue TemplateException => exception
32
+ assert_equal(true, exception.message.include?('one'))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,59 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'common_templatelet_test'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
6
+
7
+ require 'rexml/document'
8
+ require 'rexml/xpath'
9
+ require 'buildmaster/site_spec'
10
+ require 'buildmaster/templatelets'
11
+
12
+ module BuildMaster
13
+ class WhenTest < CommonTemplateletTest
14
+ def test_should_process_child_when_evaluated_true
15
+ target = create_element('target')
16
+ template_content = <<CONTENT
17
+ <when test='expression_for_true'>
18
+ <h1>Header</h1>
19
+ </when>
20
+ CONTENT
21
+ template_document = REXML::Document.new(template_content)
22
+ template = REXML::XPath.first(template_document, '/when')
23
+ when_processor = When.new(self, self)
24
+ when_processor.process(target, template, self)
25
+ actual = REXML::XPath.first(target, 'h1')
26
+ assert_equal('Header', actual.text)
27
+ end
28
+
29
+ def test_should_not_process_child_when_evaluated_false
30
+ target = create_element('target')
31
+ template_content = <<CONTENT
32
+ <when test='expression_for_false'>
33
+ <h1>Header</h1>
34
+ </when>
35
+ CONTENT
36
+ template_document = REXML::Document.new(template_content)
37
+ template = REXML::XPath.first(template_document, '/when')
38
+ when_processor = When.new(self, self)
39
+ when_processor.process(target, template, self)
40
+ assert_equal(0, target.size)
41
+ end
42
+
43
+ def path
44
+ return Pathname.new('index.html')
45
+ end
46
+
47
+ def expression_for_true(path)
48
+ return true
49
+ end
50
+
51
+ def expression_for_false(path)
52
+ return false
53
+ end
54
+
55
+ def load_templatelets
56
+ return Hash.new
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'site')
2
+
3
+ require 'tc_template_builder'
4
+ require 'tc_site'
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'test/unit'
3
+
4
+ require 'templatelets/tc_attribute'
5
+ require 'templatelets/tc_each'
6
+ require 'templatelets/tc_href'
7
+ require 'templatelets/tc_include'
8
+ require 'templatelets/tc_link'
9
+ require 'templatelets/tc_text'
10
+ require 'templatelets/tc_when'
@@ -0,0 +1,8 @@
1
+ <html xmlns:template='http://buildmaster.rubyforge.org/xtemplate/1.0' xmlns='http://www.w3.org/1999/xhtml'>
2
+ <head>
3
+ <title>Title</title>
4
+ </head>
5
+ <body>
6
+ </body>
7
+ </html>
8
+
@@ -0,0 +1,8 @@
1
+ <html xmlns:template='http://buildmaster.rubyforge.org/xtemplate/1.0' xmlns='http://www.w3.org/1999/xhtml'>
2
+ <head>
3
+ <title>Title</title>
4
+ </head>
5
+ <body>
6
+ </body>
7
+ </html>
8
+