rubyw_helper 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 / 2008-12-24
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/rubyw_helper.rb
6
+ spec/.bacon
7
+ spec/helper.rb
8
+ spec/runner
9
+ spec/spec_rubyw_helper.rb
10
+ tasks/ann.rake
11
+ tasks/autospec.rake
12
+ tasks/bacon.rake
13
+ tasks/bones.rake
14
+ tasks/gem.rake
15
+ tasks/git.rake
16
+ tasks/manifest.rake
17
+ tasks/notes.rake
18
+ tasks/post_load.rake
19
+ tasks/rdoc.rake
20
+ tasks/rubyforge.rake
21
+ tasks/setup.rb
data/README.txt ADDED
@@ -0,0 +1,88 @@
1
+ rubyw_helper
2
+ by James Tucker
3
+ http://ra66i.org
4
+ http://github.com/raggi/rubyw_helper
5
+
6
+ == DESCRIPTION:
7
+
8
+ A simple redirector for use when you just want to safely redirect stdio.
9
+ Simply encapsulates a few different safety mechanisms when redirecting stdio,
10
+ with the primary goal of making it easier to write apps that run under
11
+ rubyw.exe, where ruby loads with stdio closed.
12
+
13
+ Whilst the primary intention for use is under win32, and was actually
14
+ developed as an external helper for specifically win32-service usage, this gem
15
+ may be useful to some other folks on other platforms. It is not win32
16
+ specific.
17
+
18
+ == FEATURES/PROBLEMS:
19
+
20
+ * Lacking any tertiary logging infrastructure specific to any platform.
21
+
22
+ == SYNOPSIS:
23
+
24
+ The following parameters are also the defaults:
25
+
26
+ stdout = File.join(Dir.pwd, 'logs', "#{app_name}.stdout.log"),
27
+ stderr = File.join(Dir.pwd, 'logs', "#{app_name}.stderr.log")
28
+ stdin = case RUBY_PLATFORM
29
+ when /mingw|mswin/
30
+ 'NUL:'
31
+ else
32
+ '/dev/null'
33
+ end
34
+
35
+ helper = RubywHelper.new(stdout, stderr, stdin)
36
+
37
+ You achieve basic redirection if you wrap your runner for your program in the
38
+ with_redirection block:
39
+
40
+ helper.with_redirection do
41
+ puts "hello logfile!"
42
+ end
43
+
44
+ Or you can simply just redirect them:
45
+
46
+ helper.redirect_stdio!
47
+
48
+ For your convenience, there is also a method which attempts to see if it may
49
+ be a good idea to redirect stdio, in other words, it returns true if all of
50
+ stdio is closed:
51
+
52
+ helper.stdio_danger?
53
+
54
+ This typically returns true under rubyw.exe and any equivalents.
55
+
56
+ == REQUIREMENTS:
57
+
58
+ * Ruby
59
+ * gem inst exception_string
60
+
61
+ == INSTALL:
62
+
63
+ * gem inst rubyw_helper
64
+
65
+ == LICENSE:
66
+
67
+ (The MIT License)
68
+
69
+ Copyright (c) 2008 James Tucker
70
+
71
+ Permission is hereby granted, free of charge, to any person obtaining
72
+ a copy of this software and associated documentation files (the
73
+ 'Software'), to deal in the Software without restriction, including
74
+ without limitation the rights to use, copy, modify, merge, publish,
75
+ distribute, sublicense, and/or sell copies of the Software, and to
76
+ permit persons to whom the Software is furnished to do so, subject to
77
+ the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be
80
+ included in all copies or substantial portions of the Software.
81
+
82
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
83
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ load 'tasks/setup.rb'
2
+
3
+ ensure_in_path 'lib'
4
+ require 'rubyw_helper'
5
+
6
+ task :default => 'spec:run'
7
+
8
+ PROJ.name = 'rubyw_helper'
9
+ PROJ.authors = 'James Tucker'
10
+ PROJ.email = 'raggi@rubyforge.org'
11
+ PROJ.url = 'http://github.com/raggi/rubyw_helper'
12
+ PROJ.rubyforge.name = 'libraggi'
13
+ PROJ.version = RubywHelper.version
14
+
15
+ PROJ.exclude = %w(tmp$ bak$ ~$ CVS \.git \.hg \.svn ^pkg ^doc \.DS_Store \.cvs
16
+ \.svn \.hgignore \.gitignore \.dotest \.swp$ ~$ \.bin$ \.h$ \.rc$ \.res$)
@@ -0,0 +1,106 @@
1
+ require 'fileutils'
2
+ require 'exception_string'
3
+
4
+ class RubywHelper
5
+
6
+ Version = VERSION = '0.1.1'
7
+ def self.version; Version; end
8
+
9
+ app_name = File.basename($0)
10
+ Defaults = {
11
+ :out => File.join(Dir.pwd, 'logs', "#{app_name}.stdout.log"),
12
+ :err => File.join(Dir.pwd, 'logs', "#{app_name}.stderr.log"),
13
+ :in => case RUBY_PLATFORM
14
+ when /mingw|mswin/
15
+ 'NUL:'
16
+ else
17
+ '/dev/null'
18
+ end
19
+ }
20
+
21
+ attr_reader :old_out, :old_err, :old_in
22
+
23
+ # out replaces $stdout, err replaces $stderr, inn replaces $stdin, simple.
24
+ # provide nils / false to use the Defaults
25
+ def initialize(out = nil, err = nil, inn = nil)
26
+ @stdout, @stderr = out || Defaults[:out], err || Defaults[:err]
27
+ @stdin = inn || Defaults[:in]
28
+ @old_out, @old_err, @old_in = $stdout, $stderr, $stdin
29
+ end
30
+
31
+ def stdio_danger?
32
+ $stdout.closed? && $stderr.closed? && $stdin.closed?
33
+ end
34
+
35
+ # Takes a block, because under these conditions, it really helps developers
36
+ # if best effort is made to try and log error conditions to the files before
37
+ # leaving the process.
38
+ def with_redirection
39
+ ensure_files!
40
+ redirect_stdio!
41
+ yield
42
+ restore_stdio!
43
+ rescue Exception => exception
44
+ fatal! exception.to_s_mri
45
+ end
46
+
47
+ # Sets up the global IO objects to point to where we want.
48
+ def redirect_stdio!
49
+ inn, out, err = open(@stdin), open(@stdout, 'a+'), open(@stderr, 'a+')
50
+ no_warn do
51
+ $stdin = Object.const_set(:STDIN, inn)
52
+ $stdout = Object.const_set(:STDOUT, out)
53
+ $stderr = Object.const_set(:STDERR, err)
54
+ end
55
+ end
56
+
57
+ def restore_stdio!
58
+ no_warn do
59
+ $stdin = Object.const_set(:STDIN, @old_in)
60
+ $stdout = Object.const_set(:STDOUT, @old_out)
61
+ $stderr = Object.const_set(:STDERR, @old_err)
62
+ end
63
+ end
64
+
65
+ private
66
+ # Tries to create any containing directories, and errors out if we can't
67
+ # write to the outputs or read from the input.
68
+ def ensure_files!
69
+ fatal! "Cannot read from #{@stdin}" unless File.readable? @stdin
70
+ [@stdout, @stderr].each do |f|
71
+ dir = File.dirname(f)
72
+ safely { FileUtils.mkdir_p(dir) unless File.directory?(dir) }
73
+ next if File.writable? f
74
+ fatal! "Cannot write to #{f}"
75
+ end
76
+ end
77
+
78
+ # For each output io, safely wrap the given block, and yield the io.
79
+ def safe_each
80
+ [$stderr, $stdout].each { |io| safely { yield io } }
81
+ end
82
+
83
+ # Tries real hard to log the message, then exits with failure status.
84
+ def fatal!(message)
85
+ # Not using safe_each in case that caused an error.
86
+ safely { $stdout.reopen(@stdout, 'a+'); $stdout.puts message }
87
+ safely { $stderr.reopen(@stderr, 'a+'); $stderr.puts message }
88
+ exit 1
89
+ end
90
+
91
+ # Ignores errors, which we might not be able to avoid.
92
+ def safely
93
+ yield
94
+ rescue Exception
95
+ nil
96
+ end
97
+
98
+ # Suppress warnings, most useful for constant redefinition.
99
+ def no_warn
100
+ verbose = $VERBOSE
101
+ $VERBOSE = nil
102
+ yield
103
+ ensure
104
+ $VERBOSE = verbose
105
+ end
106
+ end
data/spec/.bacon ADDED
File without changes
data/spec/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ # Disable test/unit and rspec from running, in case loaded by broken tools.
2
+ Test::Unit.run = false if defined?(Test) && defined?(Test::Unit)
3
+ Spec::run = false if defined?(Spec) && Spec::respond_to?(:run=)
4
+
5
+ # Setup a nice testing environment
6
+ $DEBUG, $TESTING = true, true
7
+ $:.push File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $:.uniq!
9
+
10
+ %w[rubygems bacon].each { |r| require r }
11
+
12
+ # Bacon doesn't do any automagic, so lets tell it to!
13
+ Bacon.summary_on_exit
14
+
15
+ require File.expand_path(
16
+ File.join(File.dirname(__FILE__), %w[.. lib rubyw_helper]))
data/spec/runner ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ __DIR__ = File.dirname(__FILE__)
3
+ __APP__ = File.expand_path(__DIR__ + '/../')
4
+
5
+ puts
6
+ Dir.chdir(__APP__) do
7
+ files = ARGV.empty? ? Dir.glob('{test,spec}/**/{test,spec}_*.rb') : ARGV
8
+ files.each { |f| require f }
9
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+ require 'stringio'
3
+ require 'tempfile'
4
+
5
+ describe "RubywHelper" do
6
+
7
+ def temp_io
8
+ stdin = case RUBY_PLATFORM
9
+ when /mingw|mswin/
10
+ 'NUL:'
11
+ else
12
+ '/dev/null'
13
+ end
14
+ tmp_io = %W(
15
+ /tmp/rubyw_helper_test_stdout.log
16
+ /tmp/rubyw_helper_test_stderr.log
17
+ )
18
+ tmp_io.each { |f| open(f, 'w') {} }
19
+ yield tmp_io + [stdin]
20
+ ensure
21
+ tmp_io.each { |f| File.delete(f) }
22
+ end
23
+
24
+ should "have stdio_danger? when stdout, stderr, and stdin are closed" do
25
+ $stdout, $stderr, $stdin = Array.new(3) { s = StringIO.new(''); s.close; s }
26
+ RubywHelper.new.stdio_danger?.should.eql true
27
+ $stdout, $stderr, $stdin = STDOUT, STDERR, STDIN
28
+ end
29
+
30
+ should "restore the old stdios" do
31
+ oout, oerr, oin = $stdout, $stderr, $stdin
32
+ h = RubywHelper.new
33
+ $stdout, $stderr, $stdin = Array.new(3) do
34
+ s = StringIO.new('')
35
+ s.close
36
+ s
37
+ end
38
+ h.restore_stdio!
39
+ $stdout.should.eql oout
40
+ $stderr.should.eql oerr
41
+ $stdin.should.eql oin
42
+ end
43
+
44
+ should "redirect to the appropriate files and restore stdio afterward" do
45
+ oout, oerr, oin = $stdout, $stderr, $stdin
46
+ temp_io do |out, err, inn|
47
+ h = RubywHelper.new(out, err, inn)
48
+ h.with_redirection do
49
+ $stdout.path.should.eql out
50
+ $stderr.path.should.eql err
51
+ $stdin.path.should.eql inn
52
+ STDOUT.path.should.eql out
53
+ STDERR.path.should.eql err
54
+ STDIN.path.should.eql inn
55
+ $stdout.puts "1234567890"
56
+ $stderr.puts "1234567890"
57
+ [$stdin, $stderr, $stdout].each { |io| io.close unless io.closed? }
58
+ end
59
+ $stdout.should.eql oout
60
+ $stderr.should.eql oerr
61
+ $stdin.should.eql oin
62
+ STDOUT.should.eql oout
63
+ STDERR.should.eql oerr
64
+ STDIN.should.eql oin
65
+ File.read(out).should.eql("1234567890\n")
66
+ File.read(err).should.eql("1234567890\n")
67
+ end
68
+ end
69
+
70
+ end
data/tasks/ann.rake ADDED
@@ -0,0 +1,81 @@
1
+ # $Id$
2
+
3
+ begin
4
+ require 'bones/smtp_tls'
5
+ rescue LoadError
6
+ require 'net/smtp'
7
+ end
8
+ require 'time'
9
+
10
+ namespace :ann do
11
+
12
+ # A prerequisites task that all other tasks depend upon
13
+ task :prereqs
14
+
15
+ file PROJ.ann.file do
16
+ ann = PROJ.ann
17
+ puts "Generating #{ann.file}"
18
+ File.open(ann.file,'w') do |fd|
19
+ fd.puts("#{PROJ.name} version #{PROJ.version}")
20
+ fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
21
+ fd.puts(" #{PROJ.url}") if PROJ.url.valid?
22
+ fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
23
+ fd.puts
24
+ fd.puts("== DESCRIPTION")
25
+ fd.puts
26
+ fd.puts(PROJ.description)
27
+ fd.puts
28
+ fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
29
+ fd.puts
30
+ ann.paragraphs.each do |p|
31
+ fd.puts "== #{p.upcase}"
32
+ fd.puts
33
+ fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
34
+ fd.puts
35
+ end
36
+ fd.puts ann.text if ann.text
37
+ end
38
+ end
39
+
40
+ desc "Create an announcement file"
41
+ task :announcement => ['ann:prereqs', PROJ.ann.file]
42
+
43
+ desc "Send an email announcement"
44
+ task :email => ['ann:prereqs', PROJ.ann.file] do
45
+ ann = PROJ.ann
46
+ from = ann.email[:from] || PROJ.email
47
+ to = Array(ann.email[:to])
48
+
49
+ ### build a mail header for RFC 822
50
+ rfc822msg = "From: #{from}\n"
51
+ rfc822msg << "To: #{to.join(',')}\n"
52
+ rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
53
+ rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
54
+ rfc822msg << "\n"
55
+ rfc822msg << "Date: #{Time.new.rfc822}\n"
56
+ rfc822msg << "Message-Id: "
57
+ rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
58
+ rfc822msg << File.read(ann.file)
59
+
60
+ params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
61
+ ann.email[key]
62
+ end
63
+
64
+ params[3] = PROJ.email if params[3].nil?
65
+
66
+ if params[4].nil?
67
+ STDOUT.write "Please enter your e-mail password (#{params[3]}): "
68
+ params[4] = STDIN.gets.chomp
69
+ end
70
+
71
+ ### send email
72
+ Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
73
+ end
74
+ end # namespace :ann
75
+
76
+ desc 'Alias to ann:announcement'
77
+ task :ann => 'ann:announcement'
78
+
79
+ CLOBBER << PROJ.ann.file
80
+
81
+ # EOF
@@ -0,0 +1,33 @@
1
+ # Poor mans autotest, for when you absolutely positively, just need an autotest.
2
+ # N.B. Uses a runner under test/ or spec/, so you can customize the runtime.
3
+ # Thanks to manveru for this!
4
+ desc "Run specs every time a file changes in lib or spec"
5
+ task :autospec do
6
+ rb = Gem.ruby rescue nil
7
+ rb ||= (require 'rbconfig'; File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']))
8
+ command = 'spec/runner' if test ?e, 'spec/runner'
9
+ command ||= 'test/runner' if test ?e, 'test/runner'
10
+ files = Dir.glob('{lib,spec,test}/**/*.rb')
11
+ mtimes = {}
12
+ sigtrap = proc { puts "\rDo that again, I dare you!"; trap(:INT){ exit 0 }; sleep 0.8; trap(:INT, &sigtrap) }
13
+ trap(:INT, &sigtrap)
14
+ system "#{rb} -I#{GSpec.require_path} #{command}"
15
+ while file = files.shift
16
+ begin
17
+ mtime = File.mtime(file)
18
+ mtimes[file] ||= mtime
19
+ if mtime > mtimes[file]
20
+ files = Dir.glob('{lib,spec,test}/**/*.rb') - [file] # refresh the file list.
21
+ puts
22
+ system "#{rb} -I#{GSpec.require_path} #{command} #{file}"
23
+ puts
24
+ end
25
+ mtimes[file] = mtime
26
+ files << file
27
+ rescue Exception
28
+ retry
29
+ end
30
+ # print "\rChecking: #{file.ljust((ENV['COLUMNS']||80)-11)}";$stdout.flush
31
+ sleep 0.2
32
+ end
33
+ end
data/tasks/bacon.rake ADDED
@@ -0,0 +1,5 @@
1
+ task :spec do
2
+ ruby 'spec/runner'
3
+ end
4
+
5
+ task :test => :spec
data/tasks/bones.rake ADDED
@@ -0,0 +1,21 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ namespace :bones do
6
+
7
+ desc 'Show the PROJ open struct'
8
+ task :debug do |t|
9
+ atr = if t.application.top_level_tasks.length == 2
10
+ t.application.top_level_tasks.pop
11
+ end
12
+
13
+ if atr then Bones::Debug.show_attr(PROJ, atr)
14
+ else Bones::Debug.show PROJ end
15
+ end
16
+
17
+ end # namespace :bones
18
+
19
+ end # HAVE_BONES
20
+
21
+ # EOF
data/tasks/gem.rake ADDED
@@ -0,0 +1,126 @@
1
+ # $Id$
2
+
3
+ require 'rake/gempackagetask'
4
+
5
+ namespace :gem do
6
+
7
+ PROJ.gem._spec = Gem::Specification.new do |s|
8
+ s.name = PROJ.name
9
+ s.version = PROJ.version
10
+ s.summary = PROJ.summary
11
+ s.authors = Array(PROJ.authors)
12
+ s.email = PROJ.email
13
+ s.homepage = Array(PROJ.url).first
14
+ s.rubyforge_project = PROJ.rubyforge.name
15
+
16
+ s.description = PROJ.description
17
+
18
+ PROJ.gem.dependencies.each do |dep|
19
+ s.add_dependency(*dep)
20
+ end
21
+
22
+ s.files = PROJ.gem.files
23
+ s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
24
+ s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
25
+
26
+ s.bindir = 'bin'
27
+ dirs = Dir["{#{PROJ.libs.join(',')}}"]
28
+ s.require_paths = dirs unless dirs.empty?
29
+
30
+ incl = Regexp.new(PROJ.rdoc.include.join('|'))
31
+ excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
32
+ excl = Regexp.new(excl.join('|'))
33
+ rdoc_files = PROJ.gem.files.find_all do |fn|
34
+ case fn
35
+ when excl; false
36
+ when incl; true
37
+ else false end
38
+ end
39
+ s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
40
+ s.extra_rdoc_files = rdoc_files
41
+ s.has_rdoc = true
42
+
43
+ if test ?f, PROJ.test.file
44
+ s.test_file = PROJ.test.file
45
+ else
46
+ s.test_files = PROJ.test.files.to_a
47
+ end
48
+
49
+ # Do any extra stuff the user wants
50
+ PROJ.gem.extras.each do |msg, val|
51
+ case val
52
+ when Proc
53
+ val.call(s.send(msg))
54
+ else
55
+ s.send "#{msg}=", val
56
+ end
57
+ end
58
+ end # Gem::Specification.new
59
+
60
+ # A prerequisites task that all other tasks depend upon
61
+ task :prereqs
62
+
63
+ desc 'Show information about the gem'
64
+ task :debug => 'gem:prereqs' do
65
+ puts PROJ.gem._spec.to_ruby
66
+ end
67
+
68
+ pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
69
+ pkg.need_tar = PROJ.gem.need_tar
70
+ pkg.need_zip = PROJ.gem.need_zip
71
+ pkg.package_files += PROJ.gem._spec.files
72
+ end
73
+ Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
74
+
75
+ gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
76
+ "#{pkg.package_name}.gem"
77
+ else
78
+ "#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
79
+ end
80
+
81
+ desc "Build the gem file #{gem_file}"
82
+ task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
83
+
84
+ file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
85
+ when_writing("Creating GEM") {
86
+ Gem::Builder.new(PROJ.gem._spec).build
87
+ verbose(true) {
88
+ mv gem_file, "#{pkg.package_dir}/#{gem_file}"
89
+ }
90
+ }
91
+ end
92
+
93
+ desc 'Install the gem'
94
+ task :install => [:clobber, 'gem:package'] do
95
+ sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
96
+
97
+ # use this version of the command for rubygems > 1.0.0
98
+ #sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
99
+ end
100
+
101
+ desc 'Uninstall the gem'
102
+ task :uninstall do
103
+ installed_list = Gem.source_index.find_name(PROJ.name)
104
+ if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
105
+ sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
106
+ end
107
+ end
108
+
109
+ desc 'Reinstall the gem'
110
+ task :reinstall => [:uninstall, :install]
111
+
112
+ desc 'Cleanup the gem'
113
+ task :cleanup do
114
+ sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
115
+ end
116
+
117
+ end # namespace :gem
118
+
119
+ desc 'Alias to gem:package'
120
+ task :gem => 'gem:package'
121
+
122
+ task :clobber => 'gem:clobber_package'
123
+
124
+ remove_desc_for_task %w(gem:clobber_package)
125
+
126
+ # EOF
data/tasks/git.rake ADDED
@@ -0,0 +1,41 @@
1
+ # $Id$
2
+
3
+ if HAVE_GIT
4
+
5
+ namespace :git do
6
+
7
+ # A prerequisites task that all other tasks depend upon
8
+ task :prereqs
9
+
10
+ desc 'Show tags from the Git repository'
11
+ task :show_tags => 'git:prereqs' do |t|
12
+ puts %x/git tag/
13
+ end
14
+
15
+ desc 'Create a new tag in the Git repository'
16
+ task :create_tag => 'git:prereqs' do |t|
17
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
18
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
19
+
20
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
21
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
22
+
23
+ puts "Creating Git tag '#{tag}'"
24
+ unless system "git tag -a -m '#{msg}' #{tag}"
25
+ abort "Tag creation failed"
26
+ end
27
+
28
+ if %x/git remote/ =~ %r/^origin\s*$/
29
+ unless system "git push origin #{tag}"
30
+ abort "Could not push tag to remote Git repository"
31
+ end
32
+ end
33
+ end
34
+
35
+ end # namespace :git
36
+
37
+ # task 'gem:release' => 'git:create_tag'
38
+
39
+ end # if HAVE_GIT
40
+
41
+ # EOF
@@ -0,0 +1,49 @@
1
+ # $Id$
2
+
3
+ require 'find'
4
+
5
+ namespace :manifest do
6
+
7
+ desc 'Verify the manifest'
8
+ task :check do
9
+ fn = PROJ.manifest_file + '.tmp'
10
+ files = manifest_files
11
+
12
+ File.open(fn, 'w') {|fp| fp.puts files}
13
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
14
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
15
+ lines.map! do |line|
16
+ case line
17
+ when %r/^(-{3}|\+{3})/; nil
18
+ when %r/^@/; Console::ANSICode.blue line
19
+ when %r/^\+/; Console::ANSICode.green line
20
+ when %r/^\-/; Console::ANSICode.red line
21
+ else line end
22
+ end
23
+ end
24
+ puts lines.compact
25
+ rm fn rescue nil
26
+ end
27
+
28
+ desc 'Create a new manifest'
29
+ task :create do
30
+ files = manifest_files
31
+ unless test(?f, PROJ.manifest_file)
32
+ files << PROJ.manifest_file
33
+ files.sort!
34
+ end
35
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
36
+ end
37
+
38
+ task :assert do
39
+ files = manifest_files
40
+ manifest = File.read(PROJ.manifest_file).split($/)
41
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
42
+ end
43
+
44
+ end # namespace :manifest
45
+
46
+ desc 'Alias to manifest:check'
47
+ task :manifest => 'manifest:check'
48
+
49
+ # EOF
data/tasks/notes.rake ADDED
@@ -0,0 +1,28 @@
1
+ # $Id$
2
+
3
+ if HAVE_BONES
4
+
5
+ desc "Enumerate all annotations"
6
+ task :notes do |t|
7
+ id = if t.application.top_level_tasks.length > 1
8
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
9
+ end
10
+ Bones::AnnotationExtractor.enumerate(
11
+ PROJ, PROJ.notes.tags.join('|'), id, :tag => true)
12
+ end
13
+
14
+ namespace :notes do
15
+ PROJ.notes.tags.each do |tag|
16
+ desc "Enumerate all #{tag} annotations"
17
+ task tag.downcase.to_sym do |t|
18
+ id = if t.application.top_level_tasks.length > 1
19
+ t.application.top_level_tasks.slice!(1..-1).join(' ')
20
+ end
21
+ Bones::AnnotationExtractor.enumerate(PROJ, tag, id)
22
+ end
23
+ end
24
+ end
25
+
26
+ end # if HAVE_BONES
27
+
28
+ # EOF
@@ -0,0 +1,39 @@
1
+ # $Id$
2
+
3
+ # This file does not define any rake tasks. It is used to load some project
4
+ # settings if they are not defined by the user.
5
+
6
+ PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
7
+ PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
8
+ "^#{Regexp.escape(PROJ.rdoc.dir)}/",
9
+ "^#{Regexp.escape(PROJ.rcov.dir)}/"]
10
+
11
+ flatten_arrays = lambda do |this,os|
12
+ os.instance_variable_get(:@table).each do |key,val|
13
+ next if key == :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,55 @@
1
+ # $Id$
2
+
3
+ begin
4
+ require 'hanna/rdoctask'
5
+ rescue LoadError
6
+ require 'rake/rdoctask'
7
+ end
8
+
9
+ namespace :doc do
10
+
11
+ desc 'Generate RDoc documentation'
12
+ Rake::RDocTask.new do |rd|
13
+ rdoc = PROJ.rdoc
14
+ rd.main = rdoc.main
15
+ rd.rdoc_dir = rdoc.dir
16
+
17
+ incl = Regexp.new(rdoc.include.join('|'))
18
+ excl = Regexp.new(rdoc.exclude.join('|'))
19
+ files = PROJ.gem.files.find_all do |fn|
20
+ case fn
21
+ when excl; false
22
+ when incl; true
23
+ else false end
24
+ end
25
+ rd.rdoc_files.push(*files)
26
+
27
+ title = "#{PROJ.name}-#{PROJ.version} Documentation"
28
+
29
+ rf_name = PROJ.rubyforge.name
30
+ title = "#{rf_name}'s " + title if rf_name.valid? and rf_name != title
31
+
32
+ rd.options << "-t #{title}"
33
+ rd.options.concat(rdoc.opts)
34
+ end
35
+
36
+ desc 'Generate ri locally for testing'
37
+ task :ri => :clobber_ri do
38
+ sh "#{RDOC} --ri -o ri ."
39
+ end
40
+
41
+ task :clobber_ri do
42
+ rm_r 'ri' rescue nil
43
+ end
44
+
45
+ end # namespace :doc
46
+
47
+ desc 'Alias to doc:rdoc'
48
+ task :doc => 'doc:rdoc'
49
+
50
+ desc 'Remove all build products'
51
+ task :clobber => %w(doc:clobber_rdoc doc:clobber_ri)
52
+
53
+ remove_desc_for_task %w(doc:clobber_rdoc)
54
+
55
+ # EOF
@@ -0,0 +1,57 @@
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:package'] 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 = [(PROJ.gem.need_tar ? "#{pkg}.tgz" : nil),
30
+ (PROJ.gem.need_zip ? "#{pkg}.zip" : nil),
31
+ "#{pkg}.gem"].compact
32
+
33
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
+ rf.add_release PROJ.rubyforge.name, PROJ.name, PROJ.version, *files
35
+ end
36
+ end # namespace :gem
37
+
38
+
39
+ namespace :doc do
40
+ desc "Publish RDoc to RubyForge"
41
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
+ config = YAML.load(
43
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
+ )
45
+
46
+ host = "#{config['username']}@rubyforge.org"
47
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge.name}/"
48
+ remote_dir << PROJ.rdoc.remote_dir if PROJ.rdoc.remote_dir
49
+ local_dir = PROJ.rdoc.dir
50
+
51
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
+ end
53
+ end # namespace :doc
54
+
55
+ end # if HAVE_RUBYFORGE
56
+
57
+ # EOF
data/tasks/setup.rb ADDED
@@ -0,0 +1,268 @@
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ class OpenStruct; undef :gem; end
10
+
11
+ PROJ = OpenStruct.new(
12
+ # Project Defaults
13
+ :name => nil,
14
+ :summary => nil,
15
+ :description => nil,
16
+ :changes => nil,
17
+ :authors => nil,
18
+ :email => nil,
19
+ :url => "\000",
20
+ :version => ENV['VERSION'] || '0.0.0',
21
+ :exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
22
+ :release_name => ENV['RELEASE'],
23
+
24
+ # System Defaults
25
+ :ruby_opts => %w(-w),
26
+ :libs => [],
27
+ :history_file => 'History.txt',
28
+ :manifest_file => 'Manifest.txt',
29
+ :readme_file => 'README.txt',
30
+
31
+ # Announce
32
+ :ann => OpenStruct.new(
33
+ :file => 'announcement.txt',
34
+ :text => nil,
35
+ :paragraphs => [],
36
+ :email => {
37
+ :from => nil,
38
+ :to => %w(ruby-talk@ruby-lang.org),
39
+ :server => 'localhost',
40
+ :port => 25,
41
+ :domain => ENV['HOSTNAME'],
42
+ :acct => nil,
43
+ :passwd => nil,
44
+ :authtype => :plain
45
+ }
46
+ ),
47
+
48
+ # Gem Packaging
49
+ :gem => OpenStruct.new(
50
+ :dependencies => [],
51
+ :executables => nil,
52
+ :extensions => FileList['ext/**/extconf.rb'],
53
+ :files => nil,
54
+ :need_tar => true,
55
+ :need_zip => false,
56
+ :extras => {}
57
+ ),
58
+
59
+ # File Annotations
60
+ :notes => OpenStruct.new(
61
+ :exclude => %w(^tasks/setup\.rb$),
62
+ :extensions => %w(.txt .rb .erb) << '',
63
+ :tags => %w(FIXME OPTIMIZE TODO)
64
+ ),
65
+
66
+ # Rcov
67
+ :rcov => OpenStruct.new(
68
+ :dir => 'coverage',
69
+ :opts => %w[--sort coverage -T],
70
+ :threshold => 90.0,
71
+ :threshold_exact => false
72
+ ),
73
+
74
+ # Rdoc
75
+ :rdoc => OpenStruct.new(
76
+ :opts => [],
77
+ :include => %w(^lib/ ^bin/ ^ext/ \.txt$),
78
+ :exclude => %w(extconf\.rb$),
79
+ :main => nil,
80
+ :dir => 'doc',
81
+ :remote_dir => nil
82
+ ),
83
+
84
+ # Rubyforge
85
+ :rubyforge => OpenStruct.new(
86
+ :name => "\000"
87
+ ),
88
+
89
+ # Rspec
90
+ :spec => OpenStruct.new(
91
+ :files => FileList['spec/**/*_spec.rb'],
92
+ :opts => []
93
+ ),
94
+
95
+ # Subversion Repository
96
+ :svn => OpenStruct.new(
97
+ :root => nil,
98
+ :path => '',
99
+ :trunk => 'trunk',
100
+ :tags => 'tags',
101
+ :branches => 'branches'
102
+ ),
103
+
104
+ # Test::Unit
105
+ :test => OpenStruct.new(
106
+ :files => FileList['test/**/test_*.rb'],
107
+ :file => 'test/all.rb',
108
+ :opts => []
109
+ )
110
+ )
111
+
112
+ # Load the other rake files in the tasks folder
113
+ rakefiles = Dir.glob('tasks/*.rake').sort
114
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
115
+ import(*rakefiles)
116
+
117
+ # Setup the project libraries
118
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
119
+
120
+ # Setup some constants
121
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
122
+
123
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
124
+
125
+ def quiet( &block )
126
+ io = [STDOUT.dup, STDERR.dup]
127
+ STDOUT.reopen DEV_NULL
128
+ STDERR.reopen DEV_NULL
129
+ block.call
130
+ ensure
131
+ STDOUT.reopen io.first
132
+ STDERR.reopen io.last
133
+ $stdout, $stderr = STDOUT, STDERR
134
+ end
135
+
136
+ DIFF = if WIN32 then 'diff.exe'
137
+ else
138
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
139
+ else 'diff' end
140
+ end unless defined? DIFF
141
+
142
+ SUDO = if WIN32 then ''
143
+ else
144
+ if quiet {system 'which sudo'} then 'sudo'
145
+ else '' end
146
+ end
147
+
148
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
149
+ RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
150
+ GEM = WIN32 ? 'gem.bat' : 'gem'
151
+
152
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
153
+ begin
154
+ require lib
155
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
156
+ rescue LoadError
157
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
158
+ end
159
+ end
160
+ HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
161
+ system("svn --version 2>&1 > #{DEV_NULL}"))
162
+ HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
163
+ system("git --version 2>&1 > #{DEV_NULL}"))
164
+
165
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
166
+ # specified.
167
+ #
168
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
169
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
170
+ #
171
+ def paragraphs_of( path, *paragraphs )
172
+ title = String === paragraphs.first ? paragraphs.shift : nil
173
+ ary = File.read(path).delete("\r").split(/\n\n+/)
174
+
175
+ result = if title
176
+ tmp, matching = [], false
177
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
178
+ paragraphs << (0..-1) if paragraphs.empty?
179
+
180
+ ary.each do |val|
181
+ if val =~ rgxp
182
+ break if matching
183
+ matching = true
184
+ rgxp = %r/^=+/i
185
+ elsif matching
186
+ tmp << val
187
+ end
188
+ end
189
+ tmp
190
+ else ary end
191
+
192
+ result.values_at(*paragraphs)
193
+ end
194
+
195
+ # Adds the given gem _name_ to the current project's dependency list. An
196
+ # optional gem _version_ can be given. If omitted, the newest gem version
197
+ # will be used.
198
+ #
199
+ def depend_on( name, version = nil )
200
+ spec = Gem.source_index.find_name(name).last
201
+ version = spec.version.to_s if version.nil? and !spec.nil?
202
+
203
+ PROJ.gem.dependencies << case version
204
+ when nil; [name]
205
+ when %r/^\d/; [name, ">= #{version}"]
206
+ else [name, version] end
207
+ end
208
+
209
+ # Adds the given arguments to the include path if they are not already there
210
+ #
211
+ def ensure_in_path( *args )
212
+ args.each do |path|
213
+ path = File.expand_path(path)
214
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
215
+ end
216
+ end
217
+
218
+ # Find a rake task using the task name and remove any description text. This
219
+ # will prevent the task from being displayed in the list of available tasks.
220
+ #
221
+ def remove_desc_for_task( names )
222
+ Array(names).each do |task_name|
223
+ task = Rake.application.tasks.find {|t| t.name == task_name}
224
+ next if task.nil?
225
+ task.instance_variable_set :@comment, nil
226
+ end
227
+ end
228
+
229
+ # Change working directories to _dir_, call the _block_ of code, and then
230
+ # change back to the original working directory (the current directory when
231
+ # this method was called).
232
+ #
233
+ def in_directory( dir, &block )
234
+ curdir = pwd
235
+ begin
236
+ cd dir
237
+ return block.call
238
+ ensure
239
+ cd curdir
240
+ end
241
+ end
242
+
243
+ # Scans the current working directory and creates a list of files that are
244
+ # candidates to be in the manifest.
245
+ #
246
+ def manifest_files
247
+ files = []
248
+ exclude = Regexp.new(PROJ.exclude.join('|'))
249
+ Find.find '.' do |path|
250
+ path.sub! %r/^(\.\/|\/)/o, ''
251
+ next unless test ?f, path
252
+ next if path =~ exclude
253
+ files << path
254
+ end
255
+ files.sort!
256
+ end
257
+
258
+ # We need a "valid" method thtat determines if a string is suitable for use
259
+ # in the gem specification.
260
+ #
261
+ class Object
262
+ def valid?
263
+ return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
264
+ return false
265
+ end
266
+ end
267
+
268
+ # EOF
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyw_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - James Tucker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-16 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A simple redirector for use when you just want to safely redirect stdio. Simply encapsulates a few different safety mechanisms when redirecting stdio, with the primary goal of making it easier to write apps that run under rubyw.exe, where ruby loads with stdio closed. Whilst the primary intention for use is under win32, and was actually developed as an external helper for specifically win32-service usage, this gem may be useful to some other folks on other platforms. It is not win32 specific.
17
+ email: raggi@rubyforge.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - README.txt
25
+ files:
26
+ - History.txt
27
+ - Manifest.txt
28
+ - README.txt
29
+ - Rakefile
30
+ - lib/rubyw_helper.rb
31
+ - spec/.bacon
32
+ - spec/helper.rb
33
+ - spec/runner
34
+ - spec/spec_rubyw_helper.rb
35
+ - tasks/ann.rake
36
+ - tasks/autospec.rake
37
+ - tasks/bacon.rake
38
+ - tasks/bones.rake
39
+ - tasks/gem.rake
40
+ - tasks/git.rake
41
+ - tasks/manifest.rake
42
+ - tasks/notes.rake
43
+ - tasks/post_load.rake
44
+ - tasks/rdoc.rake
45
+ - tasks/rubyforge.rake
46
+ - tasks/setup.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/raggi/rubyw_helper
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --main
52
+ - README.txt
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: libraggi
70
+ rubygems_version: 1.3.1
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: A simple redirector for use when you just want to safely redirect stdio
74
+ test_files: []
75
+