-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
96 lines (80 loc) · 3.5 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
require 'bundler'
require 'English'
require 'rake/testtask'
require 'pp'
Bundler::GemHelper.install_tasks
task default: 'test'
Rake::TestTask.new do |t|
t.description = 'Run test suite'
t.test_files = Dir['test/**/*'].select { |f| f.match(/\.rb$/) }
t.warning = true
end
desc 'Run test suite with simplecov'
task :simplecov do
ENV['SIMPLECOV'] = 'true'
Rake::Task['test'].invoke
end
desc 'Add or update yardoc'
task :doc do
run_docgen
end
task build: :boilerplate
desc 'Add or update license boilerplate in source files'
task :boilerplate do
run_boilerplate
end
def run_docgen
$stderr.puts 'Building docs'
`yardoc lib/`
$stderr.puts 'Docs done'
end
def run_boilerplate
boilerplate = <<END
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
# #
# Copyright (C) 2007-#{Time.now.year} Martin Asser Hansen ([email protected]). #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, #
# USA. #
# #
# http://www.gnu.org/copyleft/gpl.html #
# #
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
# #
# This software is part of BioDSL (http://maasha.github.io/BioDSL). #
# #
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
END
files = Rake::FileList.new('bin/**/*', 'lib/**/*.rb', 'test/**/*.rb')
files.each do |file|
body = ''
File.open(file) do |ios|
body = ios.read
end
if body.match(/Copyright \(C\) 2007-(\d{4}) Martin Asser Hansen/) &&
Regexp.last_match[1].to_i != Time.now.year
STDERR.puts "Updating boilerplate: #{file}"
body.sub!(/Copyright \(C\) 2007-(\d{4}) Martin Asser Hansen/,
"Copyright (C) 2007-#{Time.now.year} Martin Asser Hansen")
File.open(file, 'w') do |ios|
ios.puts body
end
end
next if body.match('Copyright')
STDERR.puts "Warning: missing boilerplate in #{file}"
STDERR.puts body.split($RS).first(10).join($RS)
exit
end
end