forked from copiousfreetime/qup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
307 lines (265 loc) · 10 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# vim: syntax=ruby
This.name = "qup"
This.author = "Jeremy Hinegardner"
This.email = "[email protected]"
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
This.version = Util.version
#------------------------------------------------------------------------------
# If you want to Develop on this project just run 'rake develop' and you'll
# have all you need to get going. If you want to use bundler for development,
# then run 'rake develop:using_bundler'
#------------------------------------------------------------------------------
namespace :develop do
# Install all the development and runtime dependencies of this gem using the
# gemspec.
task :default do
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
# list these here instead of gem dependencies since there is not a way to
# sepcify ruby version specific dependencies
if RUBY_VERSION < "1.9.2"
Util.platform_gemspec.add_development_dependency( 'rcov', '~> 1.0.0' )
else
Util.platform_gemspec.add_development_dependency( 'simplecov', '~> 0.6.4' )
end
puts "Installing gem depedencies needed for development"
Util.platform_gemspec.dependencies.each do |dep|
if dep.matching_specs.empty? then
puts "Installing : #{dep}"
installer.install dep
else
puts "Skipping : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
end
end
puts "\n\nNow run 'rake test'"
end
# Create a Gemfile that just references the gemspec
file 'Gemfile' => :gemspec do
File.open( "Gemfile", "w+" ) do |f|
f.puts 'source :rubygems'
f.puts 'gemspec'
end
end
desc "Create a bundler Gemfile"
task :using_bundler => 'Gemfile' do
puts "Now you can 'bundle'"
end
# Gemfiles are build artifacts
CLOBBER << FileList['Gemfile*']
end
desc "Boostrap development"
task :develop => "develop:default"
#------------------------------------------------------------------------------
# RSpec - standard RSpec rake task
#------------------------------------------------------------------------------
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new( :test ) do |t|
t.ruby_opts = %w[ -w ]
t.rspec_opts = %w[ --color --format documentation ]
end
task :default => :test
rescue LoadError
Util.task_warning( 'test' )
end
#------------------------------------------------------------------------------
# RDoc - standard rdoc rake task, although we must make sure to use a more
# recent version of rdoc since it is the one that has 'tomdoc' markup
#------------------------------------------------------------------------------
begin
gem 'rdoc' # otherwise we get the wrong task from stdlib
require 'rdoc/task'
RDoc::Task.new do |t|
t.markup = 'tomdoc'
t.rdoc_dir = 'doc'
t.main = 'README.rdoc'
t.title = "#{This.name} #{This.version}"
t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
end
rescue LoadError
Util.task_warning( 'rdoc' )
end
#------------------------------------------------------------------------------
# Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
# for the moment only rcov is listed.
#------------------------------------------------------------------------------
if RUBY_VERSION < "1.9.2"
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new( :coverage ) do |t|
t.libs << 'spec'
t.pattern = 'spec/**/*_spec.rb'
t.verbose = true
t.rcov_opts << "-x ^/" # remove all the global files
t.rcov_opts << "--sort coverage" # so we see the worst files at the top
end
rescue LoadError
Util.task_warning( 'rcov' )
end
else
begin
require 'simplecov'
desc "Run tests with code coverage"
task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task[:test].execute
end
rescue LoadError
Util.task_warning( 'simplecov' )
end
end
#------------------------------------------------------------------------------
# Manifest - We want an explicit list of thos files that are to be packaged in
# the gem. Most of this is from Hoe.
#------------------------------------------------------------------------------
namespace 'manifest' do
desc "Check the manifest"
task :check => :clean do
files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
files = files.select{ |f| File.file?( f ) }
tmp = "Manifest.tmp"
File.open( tmp, 'w' ) do |f|
f.puts files.join("\n")
end
begin
sh "diff -du Manifest.txt #{tmp}"
ensure
rm tmp
end
puts "Manifest looks good"
end
desc "Generate the manifest"
task :generate => :clean do
files = %x[ git ls-files ].split("\n").sort
files.reject! { |f| f =~ This.exclude_from_manifest }
File.open( "Manifest.txt", "w" ) do |f|
f.puts files.join("\n")
end
end
end
#------------------------------------------------------------------------------
# Gem Specification
#------------------------------------------------------------------------------
This.gemspec = Hash.new
This.gemspec['ruby'] = Gem::Specification.new do |spec|
spec.name = This.name
spec.version = This.version
spec.author = This.author
spec.email = This.email
spec.homepage = This.homepage
spec.summary = This.summary
spec.description = This.description
spec.files = This.manifest
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^spec/)
spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc)$/)
spec.rdoc_options = [ "--main" , 'README.rdoc',
"--markup", "tomdoc" ]
# The Runtime Dependencies
spec.add_runtime_dependency( 'maildir', '~> 2.1.0' )
# Additional functionality if used
spec.add_development_dependency( 'kjess' , '~> 1.0.0' )
spec.add_development_dependency( 'redis' , '~> 3.0.2' )
# The Development Dependencies
spec.add_development_dependency( 'rake' , '~> 0.9.2.2')
spec.add_development_dependency( 'rspec' , '~> 2.11.0' )
spec.add_development_dependency( 'rdoc' , '~> 3.12' )
end
# The name of the gemspec file on disk
This.gemspec_file = "#{This.name}.gemspec"
# Really this is only here to support those who use bundler
desc "Build the #{This.name}.gemspec file"
task :gemspec do
File.open( This.gemspec_file, "wb+" ) do |f|
f.write Util.platform_gemspec.to_ruby
end
end
# the gemspec is also a dev artifact and should not be kept around.
CLOBBER << This.gemspec_file
# The standard gem packaging task, everyone has it.
require 'rubygems/package_task'
Gem::PackageTask.new( Util.platform_gemspec ) do
# nothing
end
#------------------------------------------------------------------------------
# Release - the steps we go through to do a final release, this is pulled from
# a compbination of mojombo's rakegem, hoe and hoe-git
#
# 1) make sure we are on the master branch
# 2) make sure there are no uncommitted items
# 3) check the manifest and make sure all looks good
# 4) build the gem
# 5) do an empty commit to have the commit message of the version
# 6) tag that commit as the version
# 7) push master
# 8) push the tag
# 7) pus the gem
#------------------------------------------------------------------------------
task :release_check do
unless `git branch` =~ /^\* master$/
abort "You must be on the master branch to release!"
end
unless `git status` =~ /^nothing to commit/m
abort "Nope, sorry, you have unfinished business"
end
end
desc "Create tag v#{This.version}, build and push #{Util.platform_gemspec.full_name} to rubygems.org"
task :release => [ :release_check, 'manifest:check', :gem ] do
sh "git commit --allow-empty -a -m 'Release #{This.version}'"
sh "git tag -a -m 'v#{This.version}' v#{This.version}"
sh "git push origin master"
sh "git push origin v#{This.version}"
sh "gem push pkg/#{Util.platform_gemspec.full_name}.gem"
end
#------------------------------------------------------------------------------
# Rakefile Support - This is all the guts and utility methods that are
# necessary to support the above tasks.
#
# Lots of Credit for this Rakefile goes to:
#
# Ara T. Howard - see the Rakefile in all of his projects -
# https://github.com/ahoward/
# Tom Preston Werner - his Rakegem project https://github.com/mojombo/rakegem
# Seattle.rb - Hoe - cuz it has relly good stuff in there
#------------------------------------------------------------------------------
BEGIN {
require 'ostruct'
require 'rake/clean'
require 'rubygems' unless defined? Gem
module Util
def self.version
line = File.read( "lib/#{ This.name }.rb" )[/^\s*VERSION\s*=\s*.*/]
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
end
# Partition an rdoc file into sections and return the text of the section
# as an array of paragraphs
def self.section_of( file, section_name )
re = /^=+ (.*)$/
parts = File.read( file ).split( re )[1..-1]
parts.map! { |p| p.strip }
sections = Hash.new
Hash[*parts].each do |k,v|
sections[k] = v.split("\n\n")
end
return sections[section_name]
end
def self.task_warning( task )
warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
end
def self.read_manifest
abort "You need a Manifest.txt" unless File.readable?( "Manifest.txt" )
File.readlines( "Manifest.txt" ).map { |l| l.strip }
end
def self.platform_gemspec
This.gemspec[This.platform]
end
end
# Hold all the metadata about this project
This = OpenStruct.new
This.platform = (RUBY_PLATFORM == "java") ? "java" : Gem::Platform::RUBY
desc = Util.section_of( 'README.rdoc', 'DESCRIPTION')
This.summary = desc.first
This.description = desc.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
This.exclude_from_manifest = %r/tmp$|\.(git|DS_Store)|^(doc|coverage|pkg)|\.gemspec$|\.swp$|\.jar|\.rvmrc$|^kestrel|~$/
This.manifest = Util.read_manifest
}