BuildMaster 0.5.0 → 0.6.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.
- data/lib/buildmaster/ant_client.rb +4 -0
- data/lib/buildmaster/cvs_client.rb +4 -0
- data/lib/buildmaster/release_control.rb +3 -0
- data/lib/buildmaster/site.rb +39 -12
- data/lib/buildmaster/site_tester.rb +129 -0
- data/lib/buildmaster/source_file_handler.rb +8 -7
- data/test/buildmaster/tc_ant_client.rb +4 -0
- data/test/buildmaster/tc_cvs_client.rb +4 -0
- data/test/buildmaster/tc_release_control.rb +4 -0
- metadata +3 -2
data/lib/buildmaster/site.rb
CHANGED
@@ -2,7 +2,6 @@ $:.unshift File.dirname(__FILE__)
|
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'redcloth'
|
5
|
-
require 'webrick'
|
6
5
|
require 'source_file_handler'
|
7
6
|
require 'file_processor'
|
8
7
|
|
@@ -10,6 +9,12 @@ module BuildMaster
|
|
10
9
|
#todo match only beginning of the file
|
11
10
|
TEXTILE_REGX = /---(-)*\n(.*)\n(-)*---/
|
12
11
|
|
12
|
+
class NullLogger
|
13
|
+
def << message
|
14
|
+
puts "IGNORED: #{message}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
13
18
|
class SiteSpec
|
14
19
|
def self.get_instance
|
15
20
|
self.new()
|
@@ -73,29 +78,49 @@ TEXTILE_REGX = /---(-)*\n(.*)\n(-)*---/
|
|
73
78
|
|
74
79
|
def build
|
75
80
|
@count = 0
|
76
|
-
ensure_directory_exists(@spec.output_dir)
|
77
81
|
build_directory(@spec.output_dir, @spec.content_dir, @template)
|
78
82
|
puts "Generated file count: #{@count}"
|
79
83
|
end
|
80
84
|
|
81
|
-
def server
|
85
|
+
def server(port_number=2000, log_file=$stdout, level=WEBrick::Log::INFO, access_log=nil)
|
86
|
+
require 'webrick'
|
82
87
|
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes.update(
|
83
88
|
{"textile" => "text/plain"}
|
84
89
|
)
|
85
|
-
server = WEBrick::HTTPServer.new(
|
86
|
-
:Port =>
|
87
|
-
:Logger => WEBrick::Log.new(
|
88
|
-
:MimeTypes => mime_types
|
90
|
+
@server = WEBrick::HTTPServer.new(
|
91
|
+
:Port => port_number,
|
92
|
+
:Logger => WEBrick::Log.new(log_file, level),
|
93
|
+
:MimeTypes => mime_types,
|
94
|
+
:AccessLog => access_log
|
89
95
|
)
|
90
|
-
server.mount('/', SourceFileHandler, @spec)
|
91
|
-
server.mount('/source', WEBrick::HTTPServlet::FileHandler, @spec.content_dir, true)
|
96
|
+
@server.mount('/', SourceFileHandler, @spec)
|
97
|
+
@server.mount('/source', WEBrick::HTTPServlet::FileHandler, @spec.content_dir, true)
|
92
98
|
['INT', 'TERM'].each { |signal|
|
93
|
-
trap(signal){ server.shutdown}
|
94
|
-
}
|
95
|
-
server.start
|
99
|
+
trap(signal){ @server.shutdown}
|
100
|
+
}
|
101
|
+
@server.start
|
102
|
+
end
|
103
|
+
|
104
|
+
def test(port_number=2000)
|
105
|
+
launch_server(port_number) {|port_number| SiteTester.test("http://localhost:#{port_number}")}
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_offline(port_number=2000)
|
109
|
+
launch_server(port_number) {|port_number| SiteTester.test_offline("http://localhost:#{port_number}")}
|
96
110
|
end
|
97
111
|
|
98
112
|
private
|
113
|
+
|
114
|
+
def launch_server(port_number)
|
115
|
+
require 'buildmaster/site_tester'
|
116
|
+
Thread.new() {server(port_number, NullLogger.new, 0, NullLogger.new)}
|
117
|
+
begin
|
118
|
+
yield port_number
|
119
|
+
ensure
|
120
|
+
@server.stop
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
99
124
|
def ensure_directory_exists(dir_name)
|
100
125
|
if (not File.exist?(dir_name))
|
101
126
|
ensure_directory_exists(File.join(dir_name, '..'))
|
@@ -104,6 +129,7 @@ TEXTILE_REGX = /---(-)*\n(.*)\n(-)*---/
|
|
104
129
|
end
|
105
130
|
|
106
131
|
def build_directory(out_dir, content_dir, template)
|
132
|
+
ensure_directory_exists(out_dir)
|
107
133
|
Dir.foreach(content_dir) do |item|
|
108
134
|
content_path = File.join(content_dir, item)
|
109
135
|
if (item == '.' || item == '..' || item == '.svn' || item == 'CVS')
|
@@ -144,4 +170,5 @@ TEXTILE_REGX = /---(-)*\n(.*)\n(-)*---/
|
|
144
170
|
end
|
145
171
|
|
146
172
|
end
|
173
|
+
|
147
174
|
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module BuildMaster
|
2
|
+
|
3
|
+
require 'watir'
|
4
|
+
require 'set'
|
5
|
+
|
6
|
+
class SiteTester
|
7
|
+
URL_PATTERN = /^https?\:\/\/([^\/]*)/
|
8
|
+
|
9
|
+
def SiteTester.test(url)
|
10
|
+
for_url(url, true).start
|
11
|
+
end
|
12
|
+
|
13
|
+
def SiteTester.test_offline(url)
|
14
|
+
for_url(url, false).start
|
15
|
+
end
|
16
|
+
|
17
|
+
def SiteTester.for_url(url, check_external_link)
|
18
|
+
ie = Watir::IE.start(url)
|
19
|
+
return SiteTester.new(ie, check_external_link)
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(ie, check_external_link)
|
23
|
+
@ie = ie
|
24
|
+
@host = get_host(@ie.url)
|
25
|
+
@errors = Hash.new
|
26
|
+
@visited_pages = Set.new
|
27
|
+
@check_external_link = check_external_link
|
28
|
+
end
|
29
|
+
|
30
|
+
def start
|
31
|
+
check_page
|
32
|
+
@ie.close
|
33
|
+
if (@errors.size == 0)
|
34
|
+
puts "SUCCESS: NO BROKEN LINK FOUND"
|
35
|
+
else
|
36
|
+
puts "FAILED"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def get_host(url)
|
42
|
+
url =~ URL_PATTERN
|
43
|
+
return $1
|
44
|
+
end
|
45
|
+
|
46
|
+
def check_page
|
47
|
+
if (@visited_pages.include?(@ie.url))
|
48
|
+
return
|
49
|
+
end
|
50
|
+
@visited_pages.add(@ie.url)
|
51
|
+
check_links
|
52
|
+
errors = @errors[@ie.url]
|
53
|
+
if (errors && errors.length > 0)
|
54
|
+
report(@ie.url, errors)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_links
|
59
|
+
current = @ie.url
|
60
|
+
@ie.links.each do |link|
|
61
|
+
if (@host == get_host(link.href))
|
62
|
+
click_link(link) {check_page}
|
63
|
+
elsif (@check_external_link == true)
|
64
|
+
click_link(link) { }
|
65
|
+
else
|
66
|
+
flash(link)
|
67
|
+
next
|
68
|
+
end
|
69
|
+
go_back(current)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def go_back(expected_url)
|
74
|
+
@ie.goto(expected_url)
|
75
|
+
end
|
76
|
+
|
77
|
+
def log
|
78
|
+
yield
|
79
|
+
end
|
80
|
+
|
81
|
+
def flash(element)
|
82
|
+
element.flash
|
83
|
+
end
|
84
|
+
|
85
|
+
def click_link(link)
|
86
|
+
from_location = @ie.url
|
87
|
+
link_string = link.to_s
|
88
|
+
begin
|
89
|
+
link.click
|
90
|
+
yield
|
91
|
+
rescue Watir::Exception::NavigationException => e
|
92
|
+
register_broken_link(from_location, link_string)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def flash(link) #copied from watir because it is private there
|
97
|
+
ole = link.getOLEObject
|
98
|
+
original_color = ole.style.backgroundColor
|
99
|
+
high_light(ole, 'yellow')
|
100
|
+
high_light(ole, original_color)
|
101
|
+
end
|
102
|
+
|
103
|
+
def high_light(ole_object, color)
|
104
|
+
ole_object.style.backgroundColor = color
|
105
|
+
sleep(0.05)
|
106
|
+
end
|
107
|
+
|
108
|
+
def register_broken_link(from_location, link_string)
|
109
|
+
links = @errors[from_location]
|
110
|
+
if (not links)
|
111
|
+
links = []
|
112
|
+
@errors[from_location] = links
|
113
|
+
end
|
114
|
+
links.push(link_string)
|
115
|
+
end
|
116
|
+
|
117
|
+
def report(url, links)
|
118
|
+
puts "#{url}"
|
119
|
+
puts "--------------------------------"
|
120
|
+
links.each do |link|
|
121
|
+
puts "#{link}"
|
122
|
+
puts "--------------------------------"
|
123
|
+
end
|
124
|
+
puts "################################"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -7,10 +7,10 @@ module BuildMaster
|
|
7
7
|
|
8
8
|
class SourceFileHandler < WEBrick::HTTPServlet::AbstractServlet
|
9
9
|
# uncomment the following for automatic servlet reloading
|
10
|
-
def SourceFileHandler.get_instance config, *options
|
11
|
-
load __FILE__
|
12
|
-
SourceFileHandler.new config, *options
|
13
|
-
end
|
10
|
+
# def SourceFileHandler.get_instance config, *options
|
11
|
+
# load __FILE__
|
12
|
+
# SourceFileHandler.new config, *options
|
13
|
+
# end
|
14
14
|
|
15
15
|
def initialize(server, spec)
|
16
16
|
super
|
@@ -47,17 +47,18 @@ class SourceFileHandler < WEBrick::HTTPServlet::AbstractServlet
|
|
47
47
|
textile_file = "#{file_path}.textile"
|
48
48
|
html_file = "#{file_path}.html"
|
49
49
|
if File.file? textile_file
|
50
|
-
stats = File::stat(textile_file)
|
50
|
+
# stats = File::stat(textile_file)
|
51
51
|
document = FileProcessor.new(@spec.load_template, textile_file, @spec).process_textile()
|
52
52
|
elsif File.file? html_file
|
53
|
-
stats = File::stat(html_file)
|
53
|
+
# stats = File::stat(html_file)
|
54
54
|
document = FileProcessor.new(@spec.load_template, html_file, @spec).process_html()
|
55
55
|
end
|
56
56
|
if (document)
|
57
57
|
content = document.to_s
|
58
58
|
res['content-type'] = 'text/html'
|
59
59
|
res['content-length'] = content.length
|
60
|
-
res['last-modified'] = stats.mtime.httpdate
|
60
|
+
# res['last-modified'] = stats.mtime.httpdate
|
61
|
+
res['last-modified'] = DateTime.now
|
61
62
|
res.body = content
|
62
63
|
else
|
63
64
|
@delegate.service(req, res)
|
@@ -3,6 +3,8 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'buildmaster'
|
5
5
|
|
6
|
+
module BuildMaster
|
7
|
+
|
6
8
|
class AntTest < Test::Unit::TestCase
|
7
9
|
protected
|
8
10
|
def setup
|
@@ -25,3 +27,5 @@ class AntTest < Test::Unit::TestCase
|
|
25
27
|
assert_raise(RuntimeError) {@ant.target('failing')}
|
26
28
|
end
|
27
29
|
end
|
30
|
+
|
31
|
+
end
|
@@ -3,6 +3,8 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
|
|
3
3
|
require 'test/unit'
|
4
4
|
require 'buildmaster'
|
5
5
|
|
6
|
+
module BuildMaster
|
7
|
+
|
6
8
|
class CvsClientTest < Test::Unit::TestCase
|
7
9
|
protected
|
8
10
|
def setUp()
|
@@ -60,3 +62,5 @@ class CvsClientTest < Test::Unit::TestCase
|
|
60
62
|
end
|
61
63
|
|
62
64
|
end
|
65
|
+
|
66
|
+
end
|
@@ -4,6 +4,8 @@ require 'test/unit'
|
|
4
4
|
require 'buildmaster'
|
5
5
|
require 'mock'
|
6
6
|
|
7
|
+
module BuildMaster
|
8
|
+
|
7
9
|
class ReleaseTest < Test::Unit::TestCase
|
8
10
|
def testRelease
|
9
11
|
cvs_mock = Mock.new(CvsClient)
|
@@ -20,4 +22,6 @@ class ReleaseTest < Test::Unit::TestCase
|
|
20
22
|
cvs_mock.verify
|
21
23
|
builder_mock.verify
|
22
24
|
end
|
25
|
+
end
|
26
|
+
|
23
27
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: BuildMaster
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-06-
|
6
|
+
version: 0.6.0
|
7
|
+
date: 2006-06-20
|
8
8
|
summary: "A project that hosts a series of scripts to be used in project building, project
|
9
9
|
releasing, and site building."
|
10
10
|
require_paths:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/buildmaster/run_ant.rb
|
41
41
|
- lib/buildmaster/shell_command.rb
|
42
42
|
- lib/buildmaster/site.rb
|
43
|
+
- lib/buildmaster/site_tester.rb
|
43
44
|
- lib/buildmaster/source_file_handler.rb
|
44
45
|
- lib/buildmaster/svn_driver.rb
|
45
46
|
- lib/buildmaster/template_runner.rb
|