nio 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/tasks/git.rake ADDED
@@ -0,0 +1,40 @@
1
+
2
+ if HAVE_GIT
3
+
4
+ namespace :git do
5
+
6
+ # A prerequisites task that all other tasks depend upon
7
+ task :prereqs
8
+
9
+ desc 'Show tags from the Git repository'
10
+ task :show_tags => 'git:prereqs' do |t|
11
+ puts %x/git tag/
12
+ end
13
+
14
+ desc 'Create a new tag in the Git repository'
15
+ task :create_tag => 'git:prereqs' do |t|
16
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
17
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
18
+
19
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
20
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
21
+
22
+ puts "Creating Git tag '#{tag}'"
23
+ unless system "git tag -a -m '#{msg}' #{tag}"
24
+ abort "Tag creation failed"
25
+ end
26
+
27
+ if %x/git remote/ =~ %r/^origin\s*$/
28
+ unless system "git push origin #{tag}"
29
+ abort "Could not push tag to remote Git repository"
30
+ end
31
+ end
32
+ end
33
+
34
+ end # namespace :git
35
+
36
+ task 'gem:release' => 'git:create_tag'
37
+
38
+ end # if HAVE_GIT
39
+
40
+ # EOF
@@ -0,0 +1,48 @@
1
+
2
+ require 'find'
3
+
4
+ namespace :manifest do
5
+
6
+ desc 'Verify the manifest'
7
+ task :check do
8
+ fn = PROJ.manifest_file + '.tmp'
9
+ files = manifest_files
10
+
11
+ File.open(fn, 'w') {|fp| fp.puts files}
12
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
13
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
14
+ lines.map! do |line|
15
+ case line
16
+ when %r/^(-{3}|\+{3})/; nil
17
+ when %r/^@/; ANSICode.blue line
18
+ when %r/^\+/; ANSICode.green line
19
+ when %r/^\-/; ANSICode.red line
20
+ else line end
21
+ end
22
+ end
23
+ puts lines.compact
24
+ rm fn rescue nil
25
+ end
26
+
27
+ desc 'Create a new manifest'
28
+ task :create do
29
+ files = manifest_files
30
+ unless test(?f, PROJ.manifest_file)
31
+ files << PROJ.manifest_file
32
+ files.sort!
33
+ end
34
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
35
+ end
36
+
37
+ task :assert do
38
+ files = manifest_files
39
+ manifest = File.read(PROJ.manifest_file).split($/)
40
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
41
+ end
42
+
43
+ end # namespace :manifest
44
+
45
+ desc 'Alias to manifest:check'
46
+ task :manifest => 'manifest:check'
47
+
48
+ # EOF
data/tasks/notes.rake ADDED
@@ -0,0 +1,27 @@
1
+
2
+ if HAVE_BONES
3
+
4
+ desc "Enumerate all annotations"
5
+ task :notes do |t|
6
+ id = if t.application.top_level_tasks.length > 1
7
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
8
+ end
9
+ Bones::AnnotationExtractor.enumerate(
10
+ PROJ, PROJ.notes.tags.join('|'), id, :tag => true)
11
+ end
12
+
13
+ namespace :notes do
14
+ PROJ.notes.tags.each do |tag|
15
+ desc "Enumerate all #{tag} annotations"
16
+ task tag.downcase.to_sym do |t|
17
+ id = if t.application.top_level_tasks.length > 1
18
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
19
+ end
20
+ Bones::AnnotationExtractor.enumerate(PROJ, tag, id)
21
+ end
22
+ end
23
+ end
24
+
25
+ end # if HAVE_BONES
26
+
27
+ # EOF
data/tasks/nuweb.rake CHANGED
@@ -1,69 +1,125 @@
1
1
  # nuweb build tasks
2
+ namespace :nuweb do
2
3
 
3
- desc "Generate Ruby code"
4
- task :tangle => Dir['source/*.w'].collect{|fn| fn.gsub /\.w/,'.ws'}+Dir['source/lib/**/*.rb'].collect{|fn| fn.gsub('source/lib/','lib/')}+[:test]
4
+ desc "Generate Ruby code from nuweb source"
5
+ task :tangle => Dir['source/*.w'].collect{|fn| fn.gsub /\.w/,'.ws'}+
6
+ Dir['source/lib/**/*.rb'].collect{|fn| fn.gsub('source/lib/','lib/')}+
7
+ Dir['source/test/**/*'].collect{|fn| fn.gsub('source/test/','test/')}+
8
+ [:test]
5
9
 
6
- # directory 'lib'
7
- # directory 'lib/nio'
8
- # directory 'source/pdf'
10
+ # directory 'lib'
11
+ # directory 'lib/nio'
12
+ # directory 'source/pdf'
9
13
 
10
- rule '.ws' => ['.w'] do |t|
11
- puts "build dir: #{Dir.pwd}"
12
- puts "nuweb -t #{t.source}"
13
- puts `nuweb -t #{t.source}`
14
- File.open(t.name,'w'){|f| f.puts "sentinel"}
15
- end
14
+ rule '.ws' => ['.w'] do |t|
15
+ puts "build dir: #{Dir.pwd}"
16
+ puts "nuweb -t #{t.source}"
17
+ puts `nuweb -t #{t.source}`
18
+ File.open(t.name,'w'){|f| f.puts "sentinel"}
19
+ end
16
20
 
17
- clean_exts = ['*.tex','*.dvi','*.log','*.aux','*.out','*.ws']
21
+ clean_exts = ['*.tex','*.dvi','*.log','*.aux','*.out','*.ws']
22
+ clobber_dirs = ['lib', 'source/pdf', 'test']
23
+ clobber_exceptions = ['test/data.yaml', 'test/test_helper.rb']
18
24
 
19
- desc "clean up files"
20
- task :clean_nuweb do |t| # to do: integrate in hoe clean
21
- rm_r clean_exts.collect{|x| Dir.glob('*'+x)+Dir.glob('source/*'+x)+Dir.glob('source/pdf/*'+x)}.flatten
22
- end
25
+ desc "Remove all nuweb generated files"
26
+ task :clobber=>[:clean] do |t|
27
+ clobber_dirs.map{|dir| Dir["#{dir}/**/*"]}.flatten.each do |fn|
28
+ rm fn unless File.directory?(fn)
29
+ end
30
+ end
23
31
 
24
- desc "Generate source code (nuweb) documentation"
25
- task :weave => ['source/pdf'] + Dir['source/*.w'].collect{|fn| fn.gsub(/\.w/,'.pdf').gsub('source/','source/pdf/')}
32
+ desc "Clean up nuweb temporary files"
33
+ task :clean do |t|
34
+ rm_r clean_exts.collect{|x| Dir.glob('*'+x)+Dir.glob('source/*'+x)+Dir.glob('source/pdf/*'+x)}.flatten
35
+ end
26
36
 
27
- def rem_ext(fn, ext)
28
- ext = File.extname(fn) unless fn
29
- File.join(File.dirname(fn),File.basename(fn,ext))
30
- end
37
+ desc "Generate nuweb source code documentation"
38
+ task :weave => ['source/pdf'] + Dir['source/*.w'].collect{|fn| fn.gsub(/\.w/,'.pdf').gsub('source/','source/pdf/')}
31
39
 
32
- def sub_dir(dir, fn)
33
- d,n = File.split(fn)
34
- File.join(d,File.join(dir,n))
35
- end
40
+ def rem_ext(fn, ext)
41
+ ext = File.extname(fn) unless fn
42
+ File.join(File.dirname(fn),File.basename(fn,ext))
43
+ end
36
44
 
37
- def rep_dir(dir, fn)
38
- File.join(dir, File.basename(fn))
39
- end
45
+ def sub_dir(dir, fn)
46
+ d,n = File.split(fn)
47
+ File.join(d,File.join(dir,n))
48
+ end
40
49
 
41
- #note that if latex is run from the base directory and the file is in a subdirectory (source)
42
- # .aux/.out/.log files are created in the subdirectory and won't be found by the second
43
- # pass of latex;
44
- def w_to_pdf(s)
45
- fn = rem_ext(s,'.w')
46
- puts "dir: #{File.dirname(fn)}"
47
- doc_dir = File.dirname(fn)!='.' ? './pdf' : '../source/pdf'
48
- cd(File.dirname(fn)) do
49
- fn = File.basename(fn)
50
- 2.times do
51
- puts "nuweb -o -l #{fn}.w"
52
- puts `nuweb -o -l #{fn}.w`
53
- puts "latex -halt-on-error #{fn}.tex"
54
- puts `latex -halt-on-error #{fn}.tex`
55
- puts "dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi"
56
- puts `dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi`
50
+ def rep_dir(dir, fn)
51
+ File.join(dir, File.basename(fn))
52
+ end
53
+
54
+ #note that if latex is run from the base directory and the file is in a subdirectory (source)
55
+ # .aux/.out/.log files are created in the subdirectory and won't be found by the second
56
+ # pass of latex;
57
+ def w_to_pdf(s)
58
+ fn = rem_ext(s,'.w')
59
+ puts "dir: #{File.dirname(fn)}"
60
+ doc_dir = File.dirname(fn)!='.' ? './pdf' : '../source/pdf'
61
+ cd(File.dirname(fn)) do
62
+ fn = File.basename(fn)
63
+ 2.times do
64
+ puts "nuweb -o -l #{fn}.w"
65
+ puts `nuweb -o -l #{fn}.w`
66
+ puts "latex -halt-on-error #{fn}.tex"
67
+ puts `latex -halt-on-error #{fn}.tex`
68
+ puts "dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi"
69
+ puts `dvipdfm -o #{rep_dir(doc_dir,fn)}.pdf #{fn}.dvi`
70
+ end
57
71
  end
58
72
  end
59
- end
60
73
 
61
- rule '.pdf' => [proc{|tn| File.join('source',File.basename(tn,'.pdf')+'.w')}] do |t|
62
- w_to_pdf t.source
63
- end
74
+ rule '.pdf' => [proc{|tn| File.join('source',File.basename(tn,'.pdf')+'.w')}] do |t|
75
+ w_to_pdf t.source
76
+ end
77
+
78
+ rule /\Alib\/.*\.rb/ =>[proc{|tn| tn.sub(/\Alib\//, 'source/lib/') }] do |t|
79
+ cp t.source, t.name if t.source
80
+ end
81
+
82
+ rule /\Atest\/.*/ =>[proc{|tn| tn.sub(/\Atest\//, 'source/test/') }] do |t|
83
+ cp t.source, t.name if t.source
84
+ end
85
+
86
+ namespace :docs do
87
+
88
+ task :package=>['nuweb:weave']
89
+ Rake::PackageTask.new('nio-source-pdf', Nio::VERSION::STRING) do |p|
90
+ # generate same formats as for the gem contents
91
+ p.need_tar = PROJ.gem.need_tar
92
+ p.need_zip = PROJ.gem.need_zip
93
+ p.package_files.include "source/pdf/**/*.pdf"
94
+ end
95
+
96
+ end
97
+
98
+ Rake::PackageTask.new('nio-source', Nio::VERSION::STRING) do |p|
99
+ # generate same formats as for the gem contents
100
+ p.need_tar = PROJ.gem.need_tar
101
+ p.need_zip = PROJ.gem.need_zip
102
+ # to generate the strict source we could require the clobber task and then
103
+ # pack everything left... but we will just define what to pack
104
+ p.package_files.include "source/**/*.txt"
105
+ p.package_files.include "source/helpers/**/*"
106
+ p.package_files.include "source/lib/**/*"
107
+ p.package_files.include "source/test/**/*"
108
+ p.package_files.include "source/**/*.w"
109
+ p.package_files.exclude "source/pdf/**/*"
110
+ p.package_files.include 'History.txt', 'License.txt', 'Manifest.txt', 'Rakefile', 'README.txt', 'setup.rb'
111
+ p.package_files.include "tasks/**/*"
112
+ end
64
113
 
65
- rule /\Alib\/.*\.rb/ =>[proc{|tn| tn.sub(/\Alib\//, 'source/lib/') }] do |t|
66
- cp t.source, t.name if t.source
67
114
  end
68
115
 
116
+ task :clobber=>'nuweb:clobber'
117
+ task :clean=>'nuweb:clean'
118
+
119
+ Rake::Task['gem:package'].enhance ['nuweb:tangle']
120
+ Rake::Task['gem:release'].clear_prerequisites.enhance ['gem'] # remove clobber prerequisite
121
+
122
+ desc 'Generate code and documentation from nuweb sources'
123
+ task :nuweb => ['nuweb:tangle', 'nuweb:weave']
69
124
 
125
+ STDERR.puts "TTT #{Rake::Task['gem:package'].prerequisites.inspect}"
@@ -0,0 +1,39 @@
1
+
2
+ # This file does not define any rake tasks. It is used to load some project
3
+ # settings if they are not defined by the user.
4
+
5
+ PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
6
+ PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
7
+ "^#{Regexp.escape(PROJ.rdoc.dir)}/",
8
+ "^#{Regexp.escape(PROJ.rcov.dir)}/"]
9
+
10
+ flatten_arrays = lambda do |this,os|
11
+ os.instance_variable_get(:@table).each do |key,val|
12
+ next if key == :dependencies \
13
+ or key == :development_dependencies
14
+ case val
15
+ when Array; val.flatten!
16
+ when OpenStruct; this.call(this,val)
17
+ end
18
+ end
19
+ end
20
+ flatten_arrays.call(flatten_arrays,PROJ)
21
+
22
+ PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
23
+
24
+ PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
25
+
26
+ PROJ.summary ||= PROJ.description.split('.').first
27
+
28
+ PROJ.gem.files ||=
29
+ if test(?f, PROJ.manifest_file)
30
+ files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
31
+ files.delete ''
32
+ files
33
+ else [] end
34
+
35
+ PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
36
+
37
+ PROJ.rdoc.main ||= PROJ.readme_file
38
+
39
+ # EOF
data/tasks/rdoc.rake ADDED
@@ -0,0 +1,50 @@
1
+
2
+ require 'rake/rdoctask'
3
+
4
+ namespace :doc do
5
+
6
+ desc 'Generate RDoc documentation'
7
+ Rake::RDocTask.new do |rd|
8
+ rdoc = PROJ.rdoc
9
+ rd.main = rdoc.main
10
+ rd.rdoc_dir = rdoc.dir
11
+
12
+ incl = Regexp.new(rdoc.include.join('|'))
13
+ excl = Regexp.new(rdoc.exclude.join('|'))
14
+ files = PROJ.gem.files.find_all do |fn|
15
+ case fn
16
+ when excl; false
17
+ when incl; true
18
+ else false end
19
+ end
20
+ rd.rdoc_files.push(*files)
21
+
22
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
23
+
24
+ rf_name = PROJ.rubyforge.name
25
+ title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
26
+
27
+ rd.options << "-t #{title}"
28
+ rd.options.concat(rdoc.opts)
29
+ end
30
+
31
+ desc 'Generate ri locally for testing'
32
+ task :ri => :clobber_ri do
33
+ sh "#{RDOC} --ri -o ri ."
34
+ end
35
+
36
+ task :clobber_ri do
37
+ rm_r 'ri' rescue nil
38
+ end
39
+
40
+ end # namespace :doc
41
+
42
+ desc 'Alias to doc:rdoc'
43
+ task :doc => 'doc:rdoc'
44
+
45
+ desc 'Remove all build products'
46
+ task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
47
+
48
+ remove_desc_for_task %w(doc:clobber_rdoc)
49
+
50
+ # EOF
@@ -0,0 +1,55 @@
1
+
2
+ if PROJ.rubyforge.name.valid? && HAVE_RUBYFORGE
3
+
4
+ require 'rubyforge'
5
+ require 'rake/contrib/sshpublisher'
6
+
7
+ namespace :gem do
8
+ desc 'Package and upload to RubyForge'
9
+ task :release => [:clobber, 'gem'] do |t|
10
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
11
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
12
+ pkg = "pkg/#{PROJ.gem._spec.full_name}"
13
+
14
+ if $DEBUG then
15
+ puts "release_id = rf.add_release #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
16
+ puts "rf.add_file #{PROJ.rubyforge.name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
17
+ end
18
+
19
+ rf = RubyForge.new
20
+ rf.configure rescue nil
21
+ puts 'Logging in'
22
+ rf.login
23
+
24
+ c = rf.userconfig
25
+ c['release_notes'] = PROJ.description if PROJ.description
26
+ c['release_changes'] = PROJ.changes if PROJ.changes
27
+ c['preformatted'] = true
28
+
29
+ files = Dir.glob("#{pkg}*.*")
30
+
31
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
32
+ rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
33
+ end
34
+ end # namespace :gem
35
+
36
+
37
+ namespace :doc do
38
+ desc "Publish RDoc to RubyForge"
39
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
40
+ config = YAML.load(
41
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
42
+ )
43
+
44
+ host = "#{config['username']}@rubyforge.org"
45
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
46
+ remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
47
+ local_dir = PROJ.rdoc.dir
48
+
49
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
50
+ end
51
+ end # namespace :doc
52
+
53
+ end # if HAVE_RUBYFORGE
54
+
55
+ # EOF
data/tasks/setup.rb ADDED
@@ -0,0 +1,279 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/clean'
5
+ require 'fileutils'
6
+ require 'ostruct'
7
+
8
+ class OpenStruct; undef :gem; end
9
+
10
+ # TODO: make my own openstruct type object that includes descriptions
11
+ # TODO: use the descriptions to output help on the available bones options
12
+
13
+ PROJ = OpenStruct.new(
14
+ # Project Defaults
15
+ :name => nil,
16
+ :summary => nil,
17
+ :description => nil,
18
+ :changes => nil,
19
+ :authors => nil,
20
+ :email => nil,
21
+ :url => "\000",
22
+ :version => ENV['VERSION'] || '0.0.0',
23
+ :exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
24
+ :release_name => ENV['RELEASE'],
25
+
26
+ # System Defaults
27
+ :ruby_opts => %w(-w),
28
+ :libs => [],
29
+ :history_file => 'History.txt',
30
+ :manifest_file => 'Manifest.txt',
31
+ :readme_file => 'README.txt',
32
+
33
+ # Announce
34
+ :ann => OpenStruct.new(
35
+ :file => 'announcement.txt',
36
+ :text => nil,
37
+ :paragraphs => [],
38
+ :email => {
39
+ :from => nil,
40
+ :to => %w(ruby-talk@ruby-lang.org),
41
+ :server => 'localhost',
42
+ :port => 25,
43
+ :domain => ENV['HOSTNAME'],
44
+ :acct => nil,
45
+ :passwd => nil,
46
+ :authtype => :plain
47
+ }
48
+ ),
49
+
50
+ # Gem Packaging
51
+ :gem => OpenStruct.new(
52
+ :dependencies => [],
53
+ :development_dependencies => [],
54
+ :executables => nil,
55
+ :extensions => FileList['ext/**/extconf.rb'],
56
+ :files => nil,
57
+ :need_tar => true,
58
+ :need_zip => false,
59
+ :extras => {}
60
+ ),
61
+
62
+ # File Annotations
63
+ :notes => OpenStruct.new(
64
+ :exclude => %w(^tasks/setup\.rb$),
65
+ :extensions => %w(.txt .rb .erb .rdoc) << '',
66
+ :tags => %w(FIXME OPTIMIZE TODO)
67
+ ),
68
+
69
+ # Rcov
70
+ :rcov => OpenStruct.new(
71
+ :dir => 'coverage',
72
+ :opts => %w[--sort coverage -T],
73
+ :threshold => 90.0,
74
+ :threshold_exact => false
75
+ ),
76
+
77
+ # Rdoc
78
+ :rdoc => OpenStruct.new(
79
+ :opts => [],
80
+ :include => %w(^lib/ ^bin/ ^ext/ \.txt$ \.rdoc$),
81
+ :exclude => %w(extconf\.rb$),
82
+ :main => nil,
83
+ :dir => 'doc',
84
+ :remote_dir => nil
85
+ ),
86
+
87
+ # Rubyforge
88
+ :rubyforge => OpenStruct.new(
89
+ :name => "\000"
90
+ ),
91
+
92
+ # Rspec
93
+ :spec => OpenStruct.new(
94
+ :files => FileList['spec/**/*_spec.rb'],
95
+ :opts => []
96
+ ),
97
+
98
+ # Subversion Repository
99
+ :svn => OpenStruct.new(
100
+ :root => nil,
101
+ :path => '',
102
+ :trunk => 'trunk',
103
+ :tags => 'tags',
104
+ :branches => 'branches'
105
+ ),
106
+
107
+ # Test::Unit
108
+ :test => OpenStruct.new(
109
+ :files => FileList['test/**/test_*.rb'],
110
+ :file => 'test/all.rb',
111
+ :opts => []
112
+ )
113
+ )
114
+
115
+ # Load the other rake files in the tasks folder
116
+ tasks_dir = File.expand_path(File.dirname(__FILE__))
117
+ post_load_fn = File.join(tasks_dir, 'post_load.rake')
118
+ rakefiles = Dir.glob(File.join(tasks_dir, '*.rake')).sort
119
+ rakefiles.unshift(rakefiles.delete(post_load_fn)).compact!
120
+ import(*rakefiles)
121
+
122
+ # Setup the project libraries
123
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
124
+
125
+ # Setup some constants
126
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
127
+
128
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
129
+
130
+ def quiet( &block )
131
+ io = [STDOUT.dup, STDERR.dup]
132
+ STDOUT.reopen DEV_NULL
133
+ STDERR.reopen DEV_NULL
134
+ block.call
135
+ ensure
136
+ STDOUT.reopen io.first
137
+ STDERR.reopen io.last
138
+ $stdout, $stderr = STDOUT, STDERR
139
+ end
140
+
141
+ DIFF = if WIN32 then 'diff.exe'
142
+ else
143
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
144
+ else 'diff' end
145
+ end unless defined? DIFF
146
+
147
+ SUDO = if WIN32 then ''
148
+ else
149
+ if quiet {system 'which sudo'} then 'sudo'
150
+ else '' end
151
+ end
152
+
153
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
154
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
155
+ GEM = WIN32 ? 'gem.bat' : 'gem'
156
+
157
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
158
+ begin
159
+ require lib
160
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
161
+ rescue LoadError
162
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
163
+ end
164
+ end
165
+ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
166
+ system("svn --version 2>&1 > #{DEV_NULL}"))
167
+ HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
168
+ system("git --version 2>&1 > #{DEV_NULL}"))
169
+
170
+ # Add bones as a development dependency
171
+ #
172
+ if HAVE_BONES
173
+ PROJ.gem.development_dependencies << ['bones', ">= #{Bones::VERSION}"]
174
+ end
175
+
176
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
177
+ # specified.
178
+ #
179
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
180
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
181
+ #
182
+ def paragraphs_of( path, *paragraphs )
183
+ title = String === paragraphs.first ? paragraphs.shift : nil
184
+ ary = File.read(path).delete("\r").split(/\n\n+/)
185
+
186
+ result = if title
187
+ tmp, matching = [], false
188
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
189
+ paragraphs << (0..-1) if paragraphs.empty?
190
+
191
+ ary.each do |val|
192
+ if val =~ rgxp
193
+ break if matching
194
+ matching = true
195
+ rgxp = %r/^=+/i
196
+ elsif matching
197
+ tmp << val
198
+ end
199
+ end
200
+ tmp
201
+ else ary end
202
+
203
+ result.values_at(*paragraphs)
204
+ end
205
+
206
+ # Adds the given gem _name_ to the current project's dependency list. An
207
+ # optional gem _version_ can be given. If omitted, the newest gem version
208
+ # will be used.
209
+ #
210
+ def depend_on( name, version = nil )
211
+ spec = Gem.source_index.find_name(name).last
212
+ version = spec.version.to_s if version.nil? and !spec.nil?
213
+
214
+ PROJ.gem.dependencies << case version
215
+ when nil; [name]
216
+ when %r/^\d/; [name, ">= #{version}"]
217
+ else [name, version] end
218
+ end
219
+
220
+ # Adds the given arguments to the include path if they are not already there
221
+ #
222
+ def ensure_in_path( *args )
223
+ args.each do |path|
224
+ path = File.expand_path(path)
225
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
226
+ end
227
+ end
228
+
229
+ # Find a rake task using the task name and remove any description text. This
230
+ # will prevent the task from being displayed in the list of available tasks.
231
+ #
232
+ def remove_desc_for_task( names )
233
+ Array(names).each do |task_name|
234
+ task = Rake.application.tasks.find {|t| t.name == task_name}
235
+ next if task.nil?
236
+ task.instance_variable_set :@comment, nil
237
+ end
238
+ end
239
+
240
+ # Change working directories to _dir_, call the _block_ of code, and then
241
+ # change back to the original working directory (the current directory when
242
+ # this method was called).
243
+ #
244
+ def in_directory( dir, &block )
245
+ curdir = pwd
246
+ begin
247
+ cd dir
248
+ return block.call
249
+ ensure
250
+ cd curdir
251
+ end
252
+ end
253
+
254
+ # Scans the current working directory and creates a list of files that are
255
+ # candidates to be in the manifest.
256
+ #
257
+ def manifest_files
258
+ files = []
259
+ exclude = Regexp.new(PROJ.exclude.join('|'))
260
+ Find.find '.' do |path|
261
+ path.sub! %r/^(\.\/|\/)/o, ''
262
+ next unless test ?f, path
263
+ next if path =~ exclude
264
+ files << path
265
+ end
266
+ files.sort!
267
+ end
268
+
269
+ # We need a "valid" method thtat determines if a string is suitable for use
270
+ # in the gem specification.
271
+ #
272
+ class Object
273
+ def valid?
274
+ return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
275
+ return false
276
+ end
277
+ end
278
+
279
+ # EOF