comp_tree 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +5 -0
- data/MANIFEST +26 -0
- data/devel/jumpstart.rb +634 -1
- data/lib/comp_tree/driver.rb +14 -6
- data/lib/comp_tree/error.rb +3 -0
- data/lib/comp_tree/node.rb +1 -1
- data/lib/comp_tree.rb +1 -1
- data/test/test_exception.rb +22 -6
- data/test/test_throw.rb +22 -0
- metadata +8 -5
- data/devel/jumpstart/jumpstart.rb +0 -606
@@ -1,606 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'ostruct'
|
5
|
-
require 'rbconfig'
|
6
|
-
|
7
|
-
require 'rake/gempackagetask'
|
8
|
-
require 'rake/contrib/sshpublisher'
|
9
|
-
require 'rake/clean'
|
10
|
-
|
11
|
-
require 'rdoc/rdoc'
|
12
|
-
|
13
|
-
require 'jumpstart/ruby'
|
14
|
-
require 'jumpstart/lazy_attribute'
|
15
|
-
require 'jumpstart/simple_installer'
|
16
|
-
|
17
|
-
class Jumpstart
|
18
|
-
include LazyAttribute
|
19
|
-
|
20
|
-
def not_provided(param)
|
21
|
-
raise "#{self.class}##{param} not provided"
|
22
|
-
end
|
23
|
-
|
24
|
-
def must_define(*params)
|
25
|
-
params.each { |param|
|
26
|
-
attribute param do
|
27
|
-
not_provided(param)
|
28
|
-
end
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def initialize(project_name)
|
33
|
-
must_define :authors, :email
|
34
|
-
|
35
|
-
attribute :name do
|
36
|
-
project_name
|
37
|
-
end
|
38
|
-
|
39
|
-
attribute :version do
|
40
|
-
str = "VERSION"
|
41
|
-
begin
|
42
|
-
require name
|
43
|
-
if mod = Object.const_get(to_camel_case(name))
|
44
|
-
if mod.constants.include? str
|
45
|
-
mod.const_get str
|
46
|
-
else
|
47
|
-
raise
|
48
|
-
end
|
49
|
-
else
|
50
|
-
raise
|
51
|
-
end
|
52
|
-
rescue Exception
|
53
|
-
"0.0.0"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
attribute :rubyforge_name do
|
58
|
-
name.gsub('_', '')
|
59
|
-
end
|
60
|
-
|
61
|
-
attribute :rubyforge_user do
|
62
|
-
email.first[%r!^.*(?=@)!]
|
63
|
-
end
|
64
|
-
|
65
|
-
attribute :readme_file do
|
66
|
-
"README.rdoc"
|
67
|
-
end
|
68
|
-
|
69
|
-
attribute :history_file do
|
70
|
-
"CHANGES.rdoc"
|
71
|
-
end
|
72
|
-
|
73
|
-
attribute :doc_dir do
|
74
|
-
"documentation"
|
75
|
-
end
|
76
|
-
|
77
|
-
attribute :spec_files do
|
78
|
-
Dir["spec/*_{spec,example}.rb"]
|
79
|
-
end
|
80
|
-
|
81
|
-
attribute :test_files do
|
82
|
-
Dir["test/test_*.rb"]
|
83
|
-
end
|
84
|
-
|
85
|
-
attribute :rcov_dir do
|
86
|
-
"coverage"
|
87
|
-
end
|
88
|
-
|
89
|
-
attribute :spec_output do
|
90
|
-
"spec.html"
|
91
|
-
end
|
92
|
-
|
93
|
-
%w[gem tgz].map { |ext|
|
94
|
-
attribute ext.to_sym do
|
95
|
-
"pkg/#{name}-#{version}.#{ext}"
|
96
|
-
end
|
97
|
-
}
|
98
|
-
|
99
|
-
attribute :rcov_options do
|
100
|
-
# workaround for the default rspec task
|
101
|
-
Dir["*"].select { |f| File.directory? f }.inject(Array.new) { |acc, dir|
|
102
|
-
if dir == "lib"
|
103
|
-
acc
|
104
|
-
else
|
105
|
-
acc + ["--exclude", dir + "/"]
|
106
|
-
end
|
107
|
-
} + ["--text-report"]
|
108
|
-
end
|
109
|
-
|
110
|
-
attribute :readme_file do
|
111
|
-
"README.rdoc"
|
112
|
-
end
|
113
|
-
|
114
|
-
attribute :files do
|
115
|
-
if File.exist?(manifest = "Manifest.txt")
|
116
|
-
File.read(manifest).split("\n")
|
117
|
-
elsif File.directory? ".git"
|
118
|
-
`git ls-files`.split("\n")
|
119
|
-
elsif File.directory? ".svn"
|
120
|
-
`svn status --verbose`.split("\n").map { |t|
|
121
|
-
t.split[3]
|
122
|
-
}.select { |t|
|
123
|
-
t and File.file?(t)
|
124
|
-
}
|
125
|
-
else
|
126
|
-
[]
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
attribute :rdoc_files do
|
131
|
-
Dir["lib/**/*.rb"]
|
132
|
-
end
|
133
|
-
|
134
|
-
attribute :extra_rdoc_files do
|
135
|
-
[readme_file]
|
136
|
-
end
|
137
|
-
|
138
|
-
attribute :rdoc_options do
|
139
|
-
[
|
140
|
-
"--main",
|
141
|
-
readme_file,
|
142
|
-
"--title",
|
143
|
-
"#{name}: #{summary}",
|
144
|
-
] + (files - rdoc_files).inject(Array.new) { |acc, file|
|
145
|
-
acc + ["--exclude", file]
|
146
|
-
}
|
147
|
-
end
|
148
|
-
|
149
|
-
attribute :browser do
|
150
|
-
if Config::CONFIG["host"] =~ %r!darwin!
|
151
|
-
app = %w[Firefox Safari].map { |t|
|
152
|
-
"/Applications/#{t}.app"
|
153
|
-
}.select { |t|
|
154
|
-
File.exist? t
|
155
|
-
}.first
|
156
|
-
if app
|
157
|
-
["open", app]
|
158
|
-
else
|
159
|
-
not_provided(:browser)
|
160
|
-
end
|
161
|
-
else
|
162
|
-
"firefox"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
attribute :gemspec do
|
167
|
-
Gem::Specification.new { |g|
|
168
|
-
g.has_rdoc = true
|
169
|
-
%w[
|
170
|
-
name
|
171
|
-
authors
|
172
|
-
email
|
173
|
-
summary
|
174
|
-
version
|
175
|
-
description
|
176
|
-
files
|
177
|
-
extra_rdoc_files
|
178
|
-
rdoc_options
|
179
|
-
].each { |param|
|
180
|
-
value = send(param) and (
|
181
|
-
g.send("#{param}=", value)
|
182
|
-
)
|
183
|
-
}
|
184
|
-
|
185
|
-
if rubyforge_name
|
186
|
-
g.rubyforge_project = rubyforge_name
|
187
|
-
end
|
188
|
-
|
189
|
-
if url
|
190
|
-
g.homepage = url
|
191
|
-
end
|
192
|
-
}
|
193
|
-
end
|
194
|
-
|
195
|
-
attribute :readme_contents do
|
196
|
-
File.read(readme_file)
|
197
|
-
end
|
198
|
-
|
199
|
-
attribute :sections do
|
200
|
-
begin
|
201
|
-
pairs = Hash[*readme_contents.split(%r!^== (\w+).*?$!)[1..-1]].map {
|
202
|
-
|section, contents|
|
203
|
-
[section.downcase, contents.strip]
|
204
|
-
}
|
205
|
-
Hash[*pairs.flatten]
|
206
|
-
rescue
|
207
|
-
nil
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
attribute :description_section do
|
212
|
-
"description"
|
213
|
-
end
|
214
|
-
|
215
|
-
attribute :summary_section do
|
216
|
-
"summary"
|
217
|
-
end
|
218
|
-
|
219
|
-
attribute :description_sentences do
|
220
|
-
1
|
221
|
-
end
|
222
|
-
|
223
|
-
attribute :summary_sentences do
|
224
|
-
1
|
225
|
-
end
|
226
|
-
|
227
|
-
[:summary, :description].each { |section|
|
228
|
-
attribute section do
|
229
|
-
begin
|
230
|
-
sections[send("#{section}_section")].
|
231
|
-
gsub("\n", " ").
|
232
|
-
split(%r!\.\s*!m).
|
233
|
-
first(send("#{section}_sentences")).
|
234
|
-
join(". ") << "."
|
235
|
-
rescue
|
236
|
-
if section == :description
|
237
|
-
summary
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
}
|
242
|
-
|
243
|
-
attribute :url do
|
244
|
-
begin
|
245
|
-
readme_contents.match(%r!^\*.*?(http://\S+)!)[1]
|
246
|
-
rescue
|
247
|
-
"http://#{rubyforge_name}.rubyforge.org"
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
yield self
|
252
|
-
|
253
|
-
self.class.instance_methods(false).select { |t|
|
254
|
-
t.to_s =~ %r!\Adefine_!
|
255
|
-
}.each { |method_name|
|
256
|
-
send(method_name)
|
257
|
-
}
|
258
|
-
end
|
259
|
-
|
260
|
-
def developer(name, email)
|
261
|
-
self.authors rescue self.authors = []
|
262
|
-
self.email rescue self.email = []
|
263
|
-
self.authors << name
|
264
|
-
self.email << email
|
265
|
-
end
|
266
|
-
|
267
|
-
def author=(name)
|
268
|
-
self.authors = [name]
|
269
|
-
end
|
270
|
-
|
271
|
-
def define_clean
|
272
|
-
task :clean do
|
273
|
-
Rake::Task[:clobber].invoke
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
def define_package
|
278
|
-
task :package => :clean
|
279
|
-
Rake::GemPackageTask.new(gemspec) { |t|
|
280
|
-
t.need_tar = true
|
281
|
-
}
|
282
|
-
end
|
283
|
-
|
284
|
-
def define_spec
|
285
|
-
unless spec_files.empty?
|
286
|
-
require 'spec/rake/spectask'
|
287
|
-
|
288
|
-
desc "run specs"
|
289
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
290
|
-
t.spec_files = spec_files
|
291
|
-
end
|
292
|
-
|
293
|
-
desc "run specs with text output"
|
294
|
-
Spec::Rake::SpecTask.new('text_spec') do |t|
|
295
|
-
t.spec_files = spec_files
|
296
|
-
t.spec_opts = ['-fs']
|
297
|
-
end
|
298
|
-
|
299
|
-
desc "run specs with html output"
|
300
|
-
Spec::Rake::SpecTask.new('full_spec') do |t|
|
301
|
-
t.spec_files = spec_files
|
302
|
-
t.rcov = true
|
303
|
-
t.rcov_opts = rcov_options
|
304
|
-
t.spec_opts = ["-fh:#{spec_output}"]
|
305
|
-
end
|
306
|
-
|
307
|
-
desc "run full_spec then open browser"
|
308
|
-
task :show_spec => :full_spec do
|
309
|
-
open_browser(spec_output, rcov_dir + "/index.html")
|
310
|
-
end
|
311
|
-
|
312
|
-
desc "run specs individually"
|
313
|
-
task :spec_deps do
|
314
|
-
run_ruby_on_each(*spec_files)
|
315
|
-
end
|
316
|
-
|
317
|
-
task :prerelease => [:spec, :spec_deps]
|
318
|
-
task :default => :spec
|
319
|
-
|
320
|
-
CLEAN.include spec_output
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
def define_test
|
325
|
-
unless test_files.empty?
|
326
|
-
desc "run tests"
|
327
|
-
task :test do
|
328
|
-
test_files.each { |file|
|
329
|
-
require file
|
330
|
-
}
|
331
|
-
end
|
332
|
-
|
333
|
-
desc "run tests with rcov"
|
334
|
-
task :full_test do
|
335
|
-
verbose(false) {
|
336
|
-
sh("rcov", "-o", rcov_dir, "--text-report",
|
337
|
-
*(test_files + rcov_options)
|
338
|
-
)
|
339
|
-
}
|
340
|
-
end
|
341
|
-
|
342
|
-
desc "run full_test then open browser"
|
343
|
-
task :show_test => :full_test do
|
344
|
-
open_browser(rcov_dir + "/index.html")
|
345
|
-
end
|
346
|
-
|
347
|
-
desc "run tests individually"
|
348
|
-
task :test_deps do
|
349
|
-
run_ruby_on_each(*test_files)
|
350
|
-
end
|
351
|
-
|
352
|
-
task :prerelease => [:test, :test_deps]
|
353
|
-
task :default => :test
|
354
|
-
|
355
|
-
CLEAN.include rcov_dir
|
356
|
-
end
|
357
|
-
end
|
358
|
-
|
359
|
-
def define_doc
|
360
|
-
desc "run rdoc"
|
361
|
-
task :doc => :clean_doc do
|
362
|
-
args = (
|
363
|
-
gemspec.rdoc_options +
|
364
|
-
gemspec.require_paths.clone +
|
365
|
-
gemspec.extra_rdoc_files +
|
366
|
-
["-o", doc_dir]
|
367
|
-
).flatten.map { |t| t.to_s }
|
368
|
-
RDoc::RDoc.new.document args
|
369
|
-
end
|
370
|
-
|
371
|
-
task :clean_doc do
|
372
|
-
# normally rm_rf, but mimic rake/clean output
|
373
|
-
rm_r(doc_dir) rescue nil
|
374
|
-
end
|
375
|
-
|
376
|
-
desc "run rdoc then open browser"
|
377
|
-
task :show_doc => :doc do
|
378
|
-
open_browser(doc_dir + "/index.html")
|
379
|
-
end
|
380
|
-
|
381
|
-
task :rdoc => :doc
|
382
|
-
task :clean => :clean_doc
|
383
|
-
end
|
384
|
-
|
385
|
-
def define_publish
|
386
|
-
desc "upload docs"
|
387
|
-
task :publish => [:clean_doc, :doc] do
|
388
|
-
Rake::SshDirPublisher.new(
|
389
|
-
"#{rubyforge_user}@rubyforge.org",
|
390
|
-
"/var/www/gforge-projects/#{rubyforge_name}",
|
391
|
-
doc_dir
|
392
|
-
).upload
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
def define_install
|
397
|
-
desc "direct install (no gem)"
|
398
|
-
task :install do
|
399
|
-
SimpleInstaller.new.run([])
|
400
|
-
end
|
401
|
-
|
402
|
-
desc "direct uninstall (no gem)"
|
403
|
-
task :uninstall do
|
404
|
-
SimpleInstaller.new.run(["--uninstall"])
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
def define_debug
|
409
|
-
runner = Class.new do
|
410
|
-
def comment_src_dst(on)
|
411
|
-
on ? ["", "#"] : ["#", ""]
|
412
|
-
end
|
413
|
-
|
414
|
-
def comment_regions(on, contents, start)
|
415
|
-
src, dst = comment_src_dst(on)
|
416
|
-
contents.gsub(%r!^(\s+)#{src}#{start}.*?^\1#{src}(\}|end)!m) { |chunk|
|
417
|
-
indent = $1
|
418
|
-
chunk.gsub(%r!^#{indent}#{src}!, "#{indent}#{dst}")
|
419
|
-
}
|
420
|
-
end
|
421
|
-
|
422
|
-
def comment_lines(on, contents, start)
|
423
|
-
src, dst = comment_src_dst(on)
|
424
|
-
contents.gsub(%r!^(\s*)#{src}#{start}!) {
|
425
|
-
$1 + dst + start
|
426
|
-
}
|
427
|
-
end
|
428
|
-
|
429
|
-
def debug_info(enable)
|
430
|
-
Find.find("lib", "test") { |path|
|
431
|
-
if path =~ %r!\.rb\Z!
|
432
|
-
Jumpstart.replace_file(path) { |contents|
|
433
|
-
result = comment_regions(!enable, contents, "debug")
|
434
|
-
comment_lines(!enable, result, "trace")
|
435
|
-
}
|
436
|
-
end
|
437
|
-
}
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
desc "enable debug and trace calls"
|
442
|
-
task :debug_on do
|
443
|
-
runner.new.debug_info(true)
|
444
|
-
end
|
445
|
-
|
446
|
-
desc "disable debug and trace calls"
|
447
|
-
task :debug_off do
|
448
|
-
runner.new.debug_info(false)
|
449
|
-
end
|
450
|
-
end
|
451
|
-
|
452
|
-
def define_columns
|
453
|
-
desc "check for columns > 80"
|
454
|
-
task :check_columns do
|
455
|
-
Dir["**/*.rb"].each { |file|
|
456
|
-
File.read(file).scan(%r!^.{81}!) { |match|
|
457
|
-
unless match =~ %r!http://!
|
458
|
-
raise "#{file} greater than 80 columns: #{match}"
|
459
|
-
end
|
460
|
-
}
|
461
|
-
}
|
462
|
-
end
|
463
|
-
task :prerelease => :check_columns
|
464
|
-
end
|
465
|
-
|
466
|
-
def define_comments
|
467
|
-
task :comments do
|
468
|
-
file = "comments.txt"
|
469
|
-
write_file(file) {
|
470
|
-
Array.new.tap { |result|
|
471
|
-
(["Rakefile"] + Dir["**/*.{rb,rake}"]).each { |file|
|
472
|
-
File.read(file).scan(%r!\#[^\{].*$!) { |match|
|
473
|
-
result << match
|
474
|
-
}
|
475
|
-
}
|
476
|
-
}.join("\n")
|
477
|
-
}
|
478
|
-
CLEAN.include file
|
479
|
-
end
|
480
|
-
end
|
481
|
-
|
482
|
-
def define_check_directory
|
483
|
-
task :check_directory do
|
484
|
-
unless `git status` =~ %r!nothing to commit \(working directory clean\)!
|
485
|
-
raise "Directory not clean"
|
486
|
-
end
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
def define_ping
|
491
|
-
task :ping do
|
492
|
-
%w[github.com rubyforge.org].each { |server|
|
493
|
-
cmd = "ping " + (
|
494
|
-
if Config::CONFIG["host"] =~ %r!darwin!
|
495
|
-
"-c2 #{server}"
|
496
|
-
else
|
497
|
-
"#{server} 2 2"
|
498
|
-
end
|
499
|
-
)
|
500
|
-
unless `#{cmd}` =~ %r!0% packet loss!
|
501
|
-
raise "No ping for #{server}"
|
502
|
-
end
|
503
|
-
}
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
def define_update_jumpstart
|
508
|
-
url = ENV["RUBY_JUMPSTART"] || "git://github.com/quix/jumpstart.git"
|
509
|
-
task :update_jumpstart do
|
510
|
-
Dir.chdir("devel") {
|
511
|
-
rm_rf "jumpstart"
|
512
|
-
git "clone", url
|
513
|
-
rm_rf "jumpstart/.git"
|
514
|
-
git "commit", "jumpstart", "-m", "update jumpstart"
|
515
|
-
}
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
def git(*args)
|
520
|
-
sh("git", *args)
|
521
|
-
end
|
522
|
-
|
523
|
-
def rubyforge(command, file)
|
524
|
-
sh(
|
525
|
-
"rubyforge",
|
526
|
-
command,
|
527
|
-
rubyforge_name,
|
528
|
-
rubyforge_name,
|
529
|
-
version.to_s,
|
530
|
-
file
|
531
|
-
)
|
532
|
-
end
|
533
|
-
|
534
|
-
def define_release
|
535
|
-
task :prerelease => [:clean, :check_directory, :ping]
|
536
|
-
|
537
|
-
task :finish_release do
|
538
|
-
gem_md5, tgz_md5 = [gem, tgz].map { |file|
|
539
|
-
"#{file}.md5".tap { |md5|
|
540
|
-
sh("md5sum #{file} > #{md5}")
|
541
|
-
}
|
542
|
-
}
|
543
|
-
|
544
|
-
rubyforge("add_release", gem)
|
545
|
-
[gem_md5, tgz, tgz_md5].each { |file|
|
546
|
-
rubyforge("add_file", file)
|
547
|
-
}
|
548
|
-
|
549
|
-
git("tag", "#{name}-" + version.to_s)
|
550
|
-
git(*%w(push --tags origin master))
|
551
|
-
end
|
552
|
-
|
553
|
-
task :release => [:prerelease, :package, :publish, :finish_release]
|
554
|
-
end
|
555
|
-
|
556
|
-
def define_debug_gem
|
557
|
-
task :debug_gem do
|
558
|
-
puts gemspec.to_ruby
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
def open_browser(*files)
|
563
|
-
sh(*([browser].flatten + files))
|
564
|
-
end
|
565
|
-
|
566
|
-
def write_file(file)
|
567
|
-
yield.tap { |contents|
|
568
|
-
File.open(file, "wb") { |out|
|
569
|
-
out.print(contents)
|
570
|
-
}
|
571
|
-
}
|
572
|
-
end
|
573
|
-
|
574
|
-
def run_ruby_on_each(*files)
|
575
|
-
files.each { |file|
|
576
|
-
Ruby.run("-w", file)
|
577
|
-
}
|
578
|
-
end
|
579
|
-
|
580
|
-
def to_camel_case(str)
|
581
|
-
str.split('_').map { |t| t.capitalize }.join
|
582
|
-
end
|
583
|
-
|
584
|
-
class << self
|
585
|
-
def replace_file(file)
|
586
|
-
old_contents = File.read(file)
|
587
|
-
yield(old_contents).tap { |new_contents|
|
588
|
-
if old_contents != new_contents
|
589
|
-
File.open(file, "wb") { |output|
|
590
|
-
output.print(new_contents)
|
591
|
-
}
|
592
|
-
end
|
593
|
-
}
|
594
|
-
end
|
595
|
-
end
|
596
|
-
end
|
597
|
-
|
598
|
-
unless respond_to? :tap
|
599
|
-
class Object
|
600
|
-
def tap
|
601
|
-
yield self
|
602
|
-
self
|
603
|
-
end
|
604
|
-
end
|
605
|
-
end
|
606
|
-
|