-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Rakefile
146 lines (117 loc) · 3.47 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
# Rakefile for GRATR -*- ruby -*-
begin
require 'rubygems'
require 'rake/gempackagetask'
rescue Exception
nil
end
require 'rake/clean'
require 'rake/testtask'
require 'rake/rdoctask'
SPEC = eval(File.read(File.join(File.dirname(__FILE__), 'gratr.gemspec')))
# Determine the current version of the software
SOURCES = FileList['lib/**/*.rb']
RDOC_DIR = './gratr'
# The default task is run if rake is given no explicit arguments.
desc "Default Task"
task :default => :test
# Define a test task.
Rake::TestTask.new { |t|
t.libs << "tests"
t.pattern = 'tests/Test*.rb'
t.verbose = true
}
task :test
# Define a test that will run all the test targets.
desc "Run all test targets"
task :testall => [:test ]
# Install gratr using the standard install.rb script.
desc "Install the application"
task :install do
ruby "install.rb"
end
# CVS Tasks ----------------------------------------------------------
desc "Tag all the CVS files with the latest release number (TAG=x)"
task :tag do
rel = "REL_" + GRATR::VERSION.gsub(/\./, '_')
rel << ENV['TAG'] if ENV['TAG']
puts rel
sh %{cvs commit -m 'pre-tag commit'}
sh %{cvs tag #{rel}}
end
# Create a task to build the RDOC documentation tree.
rd = Rake::RDocTask.new("rdoc") { |rdoc|
rdoc.rdoc_dir = RDOC_DIR
rdoc.title = SPEC.summary
rdoc.options << '--line-numbers' << '--inline-source' <<
'--main' << 'README'
rdoc.rdoc_files.include(SOURCES, 'README' ) #, 'examples/examples.rb')
}
# ====================================================================
# Create a task that will package the gratr software into distributable
# tar, zip and gem files.
if ! defined?(Gem)
puts "Package Target requires RubyGEMs"
else
Rake::GemPackageTask.new(SPEC) do |pkg|
#pkg.need_zip = true
pkg.need_tar = true
end
end
# TAGS ---------------------------------------------------------------
file 'tags' => SOURCES do
print "Running ctags..."
sh %{ctags #{SOURCES.join(' ')}} # vi tags
puts "done."
end
file 'TAGS' => SOURCES do
sh %{ctags -e #{SOURCES.join(' ')}} # emacs TAGS
end
# Misc tasks =========================================================
def count_lines(filename)
lines = 0
codelines = 0
open(filename) { |f|
f.each do |line|
lines += 1
next if line =~ /^\s*$/
next if line =~ /^\s*#/
codelines += 1
end
}
[lines, codelines]
end
def show_line(msg, lines, loc)
printf "%6s %6s %s\n", lines.to_s, loc.to_s, msg
end
desc "Count lines in the main files"
task :lines do
total_lines = 0
total_code = 0
show_line("File Name", "LINES", "LOC")
SOURCES.each do |fn|
lines, codelines = count_lines(fn)
show_line(fn, lines, codelines)
total_lines += lines
total_code += codelines
end
show_line("TOTAL", total_lines, total_code)
end
ARCHIVEDIR = '/mnt/flash'
task :archive => [:package] do
cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR
end
desc "Copy rdoc html to rubyforge"
task :rdoc2rf => [:rdoc] do
sh "scp -r #{RDOC_DIR} monora@rubyforge.org:/var/www/gforge-projects/gratr"
sh "scp examples/*.jpg monora@rubyforge.org:/var/www/gforge-projects/gratr/examples"
end
STATS_DIRECTORIES = [
%w(Libraries lib/gratr),
%w(Unit\ tests tests),
].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
require 'stats/code_statistics'
CodeStatistics.new(*STATS_DIRECTORIES).to_s
end