# -*- ruby -*- require 'rubygems' require 'rake' require 'rake/contrib/sshpublisher' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'rbconfig' ## # hoe - a tool to help rake # # Hoe is a simple rake/rubygems helper for project Rakefiles. It # generates all the usual tasks for projects including rdoc generation, # testing, packaging, and deployment. # # == Using Hoe # # === Basics # # Use this as a minimal starting point: # # require 'hoe' # # Hoe.new("project_name", '1.0.0') do |p| # p.rubyforge_name = "rf_project" # # add other details here # end # # # add other tasks here # # === Tasks Provided: # # * audit - Run ZenTest against the package # * clean - Clean up all the extras # * debug_gem - Show information about the gem # * default - Run the default tasks # * docs - Build the docs HTML Files # * install - Install the package. Uses PREFIX and RUBYLIB # * multi - Run the test suite using multiruby # * package - Build all the packages # * publish_docs - Publish RDoc to RubyForge # * release - Package and upload the release to RubyForge # * test - Run the test suite. Use FILTER to add to the command line. # * uninstall - Uninstall the package. # * upload - Upload RDoc to RubyForge # # === Attributes # # The attributes that you can provide inside the new block above are: # # ==== Mandatory # # * name - The name of the release. # * version - The version. Don't hardcode! use a constant in the project. # # ==== Damn Good to Set # # * author - The author of the package. (can be array of authors) # * changes - A description of the release's latest changes. # * description - A description of the project. # * email - The author's email address. (can be array of urls) # * summary - A short summary of the project. # * url - The url of the project. # # ==== Optional # # * clean_globs - An array of file patterns to delete on clean. # * extra_deps - An array of rubygem dependencies. # * rubyforge_name - The name of the rubyforge project. [default: name.downcase] # * spec_extras - A hash of extra values to set in the gemspec. # # === Environment Variables # # * PREFIX - Used to specify a custom install location (for rake install). # * RUBY_FLAGS - Used to specify flags to ruby [has smart default]. # * RUBY_DEBUG - Used to add extra flags to RUBY_FLAGS. # * FILTER - Used to add flags to test_unit (e.g., -n test_borked) class Hoe VERSION = '1.0.5' rubyprefix = Config::CONFIG['prefix'] sitelibdir = Config::CONFIG['sitelibdir'] PREFIX = ENV['PREFIX'] || rubyprefix RUBYLIB = if PREFIX == rubyprefix then sitelibdir else File.join(PREFIX, sitelibdir[rubyprefix.size..-1]) end RUBY_DEBUG = ENV['RUBY_DEBUG'] RUBY_FLAGS = ENV['RUBY_FLAGS'] || "-w -I#{%w(lib bin test).join(File::PATH_SEPARATOR)}" + (RUBY_DEBUG ? " #{RUBY_DEBUG}" : '') FILTER = ENV['FILTER'] # for tests (eg FILTER="-n test_blah") attr_accessor :author, :bin_files, :changes, :clean_globs, :description, :email, :extra_deps, :lib_files, :name, :rubyforge_name, :spec, :spec_extras, :summary, :test_files, :url, :version def initialize(name, version) self.name = name self.version = version # Defaults self.rubyforge_name = name.downcase self.url = "http://www.zenspider.com/ZSS/Products/#{name}/" self.author = "Ryan Davis" self.email = "ryand-ruby@zenspider.com" self.clean_globs = %w(diff diff.txt demo.rb email.txt ri *.gem **/*~) self.changes = "#{author} is too lazy to write a changeset" self.description = "#{author} is too lazy to write a description" self.summary = "#{author} is too lazy to write a summary" self.extra_deps = [] self.spec_extras = {} if name == 'hoe' then extra_deps << ['rake'] extra_deps << ['rubyforge', '>= 0.3.0'] else extra_deps << ['hoe', ">= #{VERSION}"] end yield self if block_given? define_tasks end def define_tasks desc 'Run the default tasks' task :default => :test desc 'Run the test suite. Use FILTER to add to the command line.' task :test do run_tests end desc 'Run the test suite using multiruby' task :multi do run_tests :multi end ############################################################ # Packaging and Installing self.spec = Gem::Specification.new do |s| s.name = name s.version = version s.summary = summary case author when Array s.authors = author else s.author = author end s.email = email s.homepage = Array(url).first s.rubyforge_project = rubyforge_name s.description = description extra_deps.each do |dep| s.add_dependency(*dep) end spec_extras.each do |msg, val| s.send "#{msg}=", val end s.files = File.read("Manifest.txt").split s.executables = s.files.grep(/bin/) { |f| File.basename(f) } s.bindir = "bin" s.require_paths = Dir['{lib,test}'] s.has_rdoc = true s.test_suite_file = "test/test_all.rb" if test ?f, "test/test_all.rb" end desc 'Show information about the gem.' task :debug_gem do puts spec.to_ruby end self.lib_files = spec.files.grep(/^lib/) self.bin_files = spec.files.grep(/^bin/) self.test_files = %w(test/test_sexp_processor.rb) # for ruby_to_c's tests. Rake::GemPackageTask.new spec do |pkg| pkg.need_tar = true end desc 'Install the package. Uses PREFIX and RUBYLIB' task :install do [ [lib_files + test_files, RUBYLIB, 0444], [bin_files, file.join(PREFIX, 'bin'), 0555] ].each do |files, dest, mode| FileUtils.mkdir_p dest unless test ?d, dest files.each do |file| install file, dest, :mode => mode end end end desc 'Uninstall the package.' task :uninstall do Dir.chdir RUBYLIB do rm_f((lib_files + test_files).map { |f| File.basename f }) end Dir.chdir File.join(PREFIX, 'bin') do rm_f bin_files.map { |f| File.basename f } end end desc 'Package and upload the release to rubyforge.' task :release => [:clean, :package] do |t| v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z" abort "Versions don't match #{v} vs #{version}" if v != version require 'rubyforge' pkg = "pkg/#{name}-#{version}" if $DEBUG then puts "release_id = rf.add_release #{rubyforge_name.inspect}, #{name.inspect}, #{version.inspect}, \"#{pkg}.tgz\"" puts "rf.add_file #{rubyforge_name.inspect}, #{name.inspect}, release_id, \"#{pkg}.gem\"" end rf = RubyForge.new puts "Logging in" rf.login c = rf.config c["release_notes"] = description if description c["release_changes"] = changes if changes c["preformatted"] = true puts "Releasing #{name} v. #{version} tarball" release_id = rf.add_release rubyforge_name, name, version, "#{pkg}.tgz" if release_id then puts " release_id = #{release_id.inspect}" puts "Releasing #{name} v. #{version} gem" rf.add_file rubyforge_name, name, release_id, "#{pkg}.gem" else abort "Couldn't get release_id" end end ############################################################ # Doco Rake::RDocTask.new(:docs) do |rd| rd.main = "README.txt" rd.options << '-d' if RUBY_PLATFORM !~ /win32/ and `which dot` =~ /\/dot/ rd.rdoc_dir = 'doc' files = spec.files.grep(/^(lib|bin)|txt$/) files -= ['Manifest.txt'] rd.rdoc_files.push(*files) title = "#{name}-#{version} Documentation" title = "#{rubyforge_name}'s " + title if rubyforge_name != title rd.options << "-t #{title}" end desc "Generate ri locally for testing" task :ridocs => :clean do sh %q{ rdoc --ri -o ri . } end desc 'Publish RDoc to RubyForge' task :publish_docs => [:clean, :docs] do config = YAML.load(File.read(File.expand_path("~/.rubyforge/config.yml"))) user = "#{config["username"]}@rubyforge.org" project = "/var/www/gforge-projects/#{rubyforge_name}" project += "/#{name}" if rubyforge_name != name local_dir = 'doc' pub = Rake::SshDirPublisher.new user, project, local_dir if rubyforge_name != name then def pub.upload begin super rescue # project directory probably doesn't exist, transfer as a whole sh %{scp -qr #{local_dir} #{host}:#{remote_dir}} end end end pub.upload end ############################################################ # Misc/Maintenance: desc 'Run ZenTest against the package' task :audit do libs = %w(lib test).join(File::PATH_SEPARATOR) sh "zentest -I=#{libs} #{spec.files.grep(/^(lib|test)/).join(' ')}" end desc 'Clean up all the extras' task :clean => [ :clobber_docs, :clobber_package ] do clean_globs.each do |pattern| files = Dir[pattern] rm_rf files unless files.empty? end end desc 'Generate email announcement file.' task :email do require 'rubyforge' subject, body = announcement File.open("email.txt", "w") do |mail| mail.puts subject mail.puts mail.puts body end puts "Created email.txt" end desc 'Post announcement to rubyforge.' task :post_news do require 'rubyforge' subject, body = announcement rf = RubyForge.new rf.login rf.post_news(rubyforge_name, subject, body) puts "Posted to rubyforge" end desc 'Generate email announcement file and post to rubyforge.' task :announce => [:email, :post_news] end # end define def announcement urls = " " + Array(url).map {|s| s.strip}.join("\n ") subject = "Subject: #{name} #{version} Released" body = "#{name} version #{version} has been released!\n\n#{urls}\n\n#{description}\n\nChanges:\n\n#{changes}\n\n#{urls}\n" return subject, body end def run_tests(multi=false) # :nodoc: msg = multi ? :sh : :ruby cmd = if test ?f, 'test/test_all.rb' then "#{RUBY_FLAGS} test/test_all.rb #{FILTER}" else tests = ((Dir.glob("test/**/test_*.rb") + ['test/unit']).map { |f| "require \"#{f}\"" }) "#{RUBY_FLAGS} -e '#{tests.join("; ")}' #{FILTER}" end cmd = "multiruby #{cmd}" if multi send msg, cmd end ## # Reads a file at +path+ and spits out an array of the +paragraphs+ specified # # changes = p.paragraphs_of('History.txt', 0..1).join("\n\n") # summary, *description = p.paragraphs_of('Readme.txt', 3, 3..8) def paragraphs_of(path, *paragraphs) file = File.read(path) file.split(/\n\n+/).values_at(*paragraphs) end end class ::Rake::SshDirPublisher # :nodoc: attr_reader :host, :remote_dir, :local_dir end