lib/hoe.rb in hoe-1.11.0 vs lib/hoe.rb in hoe-1.12.0

- old
+ new

@@ -1,11 +1,15 @@ # -*- ruby -*- require 'rubygems' require 'rake' require 'rake/gempackagetask' -require 'rake/rdoctask' +begin + require 'rdoc/task' +rescue LoadError + require 'rake/rdoctask' +end require 'rake/testtask' require 'rbconfig' require 'rubyforge' require 'yaml' @@ -128,11 +132,11 @@ # This will set the +Gem::Specification+ platform to the one indicated in # +FORCE_PLATFORM+ (instead of default Gem::Platform::CURRENT) # class Hoe - VERSION = '1.11.0' + VERSION = '1.12.0' GEMURL = URI.parse 'http://gems.rubyforge.org' # for namespace :deps below ruby_prefix = Config::CONFIG['prefix'] sitelibdir = Config::CONFIG['sitelibdir'] @@ -502,16 +506,16 @@ default_tasks = [] if File.directory? "test" then desc 'Run the test suite. Use FILTER or TESTOPTS to add flags/args.' task :test do - run_tests + ruby make_test_cmd end desc 'Run the test suite using multiruby.' task :multi do - run_tests :multi + ruby make_test_cmd(:multi) end desc 'Show which test files fail when run alone.' task :test_deps do tests = Dir["test/**/test_*.rb"] + Dir["test/**/*_test.rb"] @@ -720,12 +724,11 @@ pkg.need_zip = @need_zip end desc 'Install the package as a gem.' task :install_gem => [:clean, :package, :check_extra_deps] do - gem = Dir['pkg/*.gem'].first - sh "#{'sudo ' unless WINDOZE}gem install --local #{gem}" + install_gem Dir['pkg/*.gem'].first 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" @@ -946,22 +949,20 @@ # extra_deps = [["rubyforge", ">= 1.0.0"], ["rake", ">= 0.8.1"]] extra_deps.each do |dep| begin gem(*dep) rescue Gem::LoadError - dep_gem, dep_version = dep - dep_version = "--version '#{dep_version}'" if dep_version - sh "#{'sudo ' unless WINDOZE}gem install #{dep_gem} #{dep_version}" + install_gem(*dep) end end end desc 'Create a fresh ~/.hoerc file.' task :config_hoe do with_config do |config, path| default_config = { - "exclude" => /tmp$|CVS|\.svn/, + "exclude" => /tmp$|CVS|\.svn|\.log$/, "publish_on_announce" => false, "signing_key_file" => "~/.gem/gem-private_key.pem", "signing_cert_file" => "~/.gem/gem-public_cert.pem", "blogs" => [ { "user" => "user", @@ -1113,11 +1114,19 @@ puts "Keys already exist: #{key_file} and #{cert_file}" end end end # end define - def run_tests(multi=false) # :nodoc: + def install_gem name, version = nil + gem_cmd = Gem.default_exec_format % 'gem' + sudo = 'sudo ' unless WINDOZE + local = '--local' unless version + version = "--version '#{version}'" if version + sh "#{sudo}#{gem_cmd} install #{local} #{name} #{version}" + end + + def make_test_cmd multi = false # :nodoc: framework = SUPPORTED_TEST_FRAMEWORKS[testlib] raise "unsupported test framework #{testlib}" unless framework tests = ["rubygems", framework] + test_globs.map { |g| Dir.glob(g) }.flatten @@ -1128,11 +1137,11 @@ if multi then ENV['EXCLUDED_VERSIONS'] = multiruby_skip.join ":" cmd = "-S multiruby #{cmd}" end - ruby cmd + cmd end def announcement # :nodoc: changes = self.changes.rdoc_to_markdown subject = "#{name} #{version} Released" @@ -1149,9 +1158,49 @@ # 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.read(path).delete("\r").split(/\n\n+/).values_at(*paragraphs) + end +end + +module Rake + module TaskManager + ## + # This gives us access to the tasks already defined in rake. + def all_tasks + @tasks + end + end + + ## + # Hooks into rake and allows us to clear out a task by name or + # regexp. Use this if you want to completely override a task instead + # of extend it. + def self.clear_tasks(*tasks) + tasks.flatten.each do |name| + case name + when Regexp then + Rake.application.all_tasks.delete_if { |k,_| k =~ name } + else + Rake.application.all_tasks.delete(name) + end + end + end + + ## + # Removes the last action added to a task. Use this when two + # libraries define the same task and you only want one of the + # actions. + # + # require 'hoe' + # require 'tasks/rails' + # Rake.undo("test") # rolls out rails' test task + + def self.undo(*names) + names.each do |name| + all_tasks[name].actions.delete_at(-1) + end end end # :enddoc: