/
rakefile
258 lines (222 loc) · 6.88 KB
/
rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
require "rubygems"
require "rake"
require "rake/testtask"
require "rake/rdoctask"
require "rake/packagetask"
require "rake/gempackagetask"
require "rake/contrib/rubyforgepublisher"
require "spec/rake/spectask"
require File.join(File.dirname(__FILE__), 'lib/gentlerest', 'version')
PKG_DISPLAY_NAME = 'GentleREST'
PKG_NAME = PKG_DISPLAY_NAME.downcase
PKG_VERSION = GentleREST::Version::STRING
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
RELEASE_NAME = "REL #{PKG_VERSION}"
RUBY_FORGE_PROJECT = PKG_NAME
RUBY_FORGE_USER = "sporkmonger"
RUBY_FORGE_PATH = "/var/www/gforge-projects/#{RUBY_FORGE_PROJECT}"
PKG_SUMMARY = "RESTful Web Framework"
PKG_DESCRIPTION = <<-TEXT
GentleREST is a web framework that is simple, fast, thread-safe and
completely magic-free.
TEXT
PKG_FILES = FileList[
"lib/**/*", "spec/**/*", "vendor/**/*",
"doc/**/*", "specdoc/**/*", "coverage/**/*",
"[A-Z]*", "rakefile"
].exclude(/[_\.]svn$/).exclude(/[_\.]git$/)
module Rake
def self.browse(filepath)
if RUBY_PLATFORM =~ /mswin/
system(filepath)
else
try_browsers = lambda do
result = true
if !(`which firefox 2>&1` =~ /no firefox/)
system("firefox #{filepath}")
elsif !(`which mozilla 2>&1` =~ /no mozilla/)
system("mozilla #{filepath}")
elsif !(`which netscape 2>&1` =~ /no netscape/)
system("netscape #{filepath}")
elsif !(`which links 2>&1` =~ /no links/)
system("links #{filepath}")
elsif !(`which lynx 2>&1` =~ /no lynx/)
system("lynx #{filepath}")
else
result = false
end
result
end
opened = false
if RUBY_PLATFORM =~ /darwin/
opened = true
system("open #{filepath}")
elsif !(`which gnome-open 2>&1` =~ /no gnome-open/)
success =
!(`gnome-open #{filepath} 2>&1` =~ /There is no default action/)
if !success
opened = try_browsers.call()
else
opened = true
end
else
opened = try_browsers.call()
end
if !opened
puts "Don't know how to browse to location."
end
end
end
end
task :default => [ "spec:run" ]
gem_spec = Gem::Specification.new do |s|
s.name = PKG_NAME
s.version = PKG_VERSION
s.summary = PKG_SUMMARY
s.description = PKG_DESCRIPTION
s.files = PKG_FILES.to_a
s.has_rdoc = true
s.extra_rdoc_files = %w( README )
s.rdoc_options.concat ['--main', 'README']
s.add_dependency('rake', '>= 0.7.2')
s.add_dependency('rspec', '>= 0.7.1')
s.add_dependency('haml', '>= 1.7.2')
s.add_dependency('addressable', '>= 1.0.3')
s.require_path = 'lib'
s.bindir = "bin"
s.executables = ["gentlerest"]
s.default_executable = "gentlerest"
s.author = "Bob Aman"
s.email = "bob@sporkmonger.com"
s.homepage = "http://sporkmonger.com/"
s.rubyforge_project = RUBY_FORGE_PROJECT
end
Rake::GemPackageTask.new(gem_spec) do |p|
p.gem_spec = gem_spec
p.need_tar = true
p.need_zip = true
end
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "GentleREST -- Web Framework Simplicity"
rdoc.options << '--line-numbers' << '--inline-source' <<
'--accessor' << 'cattr_accessor=object' << '--charset' << 'utf-8'
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
rdoc.rdoc_files.include('README', 'CHANGELOG', 'LICENSE')
rdoc.rdoc_files.include('lib/**/*.rb')
end
# TODO: I'd really like to use dcov here, but it's far too immature for the
# moment.
namespace :rcov do
desc 'Open the RCov code coverage report in a browser.'
task :browse do
if !File.exist?(File.expand_path(
File.dirname(__FILE__) + '/coverage/index.html'))
Rake::Task["spec:run"].invoke
end
Rake.browse(File.expand_path(
File.dirname(__FILE__) + '/coverage/index.html'))
end
end
namespace :spec do
desc "Run all the specs"
Spec::Rake::SpecTask.new(:run) do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = ['--color']
t.rcov = true
t.rcov_opts = [
# Don't include the actual spec files in the coverage report
'--exclude', '"spec\/.*"'
]
end
desc "Run all the specs"
Spec::Rake::SpecTask.new(:run_without_rcov) do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = ['--color']
end
# namespace :heckle do
# desc "Heckle the URI class"
# Spec::Rake::SpecTask.new(:foo) do |t|
# t.spec_files = FileList['spec/gentlerest/foo_spec.rb']
# t.spec_opts = ['--heckle', 'GentleREST::FOO']
# end
# end
# desc "Start up autotest for RSpec"
# task :autospec do
# require "autotest"
# require "autotest/growl"
# require "autotest/redgreen"
# require "vendor/autospec/lib/autospec"
# Autospec.run
# end
desc "Print Specdoc for all specs"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_files = FileList[
'spec/**/*_spec.rb'
]
t.spec_opts = ["--format", "specdoc"]
end
desc "Generate HTML Specdocs for all specs"
Spec::Rake::SpecTask.new(:html) do |t|
if !File.exist?(
File.expand_path(File.dirname(__FILE__) + '/specdoc/'))
puts "Creating specdoc folder..."
Dir.mkdir(File.expand_path(File.dirname(__FILE__) + '/specdoc/'))
end
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = ["--format", "html"]
t.out = File.expand_path(
File.dirname(__FILE__) + '/specdoc/index.html')
end
desc 'Open the RSpec HTML specifications in a browser.'
task :browse => [ "spec:html" ] do
Rake.browse(File.expand_path(
File.dirname(__FILE__) + '/specdoc/index.html'))
end
end
namespace :publish do
desc "Publish the coverage report"
task :coverage => [ "spec:run" ] do
Rake::SshDirPublisher.new(
"#{RUBY_FORGE_USER}@rubyforge.org",
"#{RUBY_FORGE_PATH}/coverage/",
"coverage"
).upload
end
desc "Publish the specifications"
task :specs => [ "spec:html" ] do
Rake::SshDirPublisher.new(
"#{RUBY_FORGE_USER}@rubyforge.org",
"#{RUBY_FORGE_PATH}/specdoc/",
"specdoc"
).upload
end
desc "Publish the API documentation"
task :api => [ "rdoc" ] do
Rake::SshDirPublisher.new(
"#{RUBY_FORGE_USER}@rubyforge.org",
"#{RUBY_FORGE_PATH}/api/",
"doc"
).upload
end
desc "Runs all of the publishing tasks"
task :all => ["publish:coverage", "publish:api", "publish:specs"] do
end
end
task :lines do
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
for file_name in FileList["lib/**/*.rb"]
f = File.open(file_name)
while line = f.gets
lines += 1
next if line =~ /^\s*$/
next if line =~ /^\s*#/
codelines += 1
end
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
total_lines += lines
total_codelines += codelines
lines, codelines = 0, 0
end
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
end