lib/hoe.rb in hoe-2.2.0 vs lib/hoe.rb in hoe-2.3.0

- old
+ new

@@ -1,24 +1,15 @@ # -*- ruby -*- require 'rubygems' require 'rake' require 'rake/gempackagetask' -begin - require 'rdoc/task' -rescue LoadError - require 'rake/rdoctask' -end require 'rake/testtask' -require 'rbconfig' require 'rubyforge' require 'yaml' -begin - gem 'rdoc' -rescue Gem::LoadError -end +require 'hoe/rake' ## # Hoe is a simple rake/rubygems helper for project Rakefiles. It helps # generate rubygems and includes a dynamic plug-in system allowing for # easy extensibility. Hoe ships with plug-ins for all your usual @@ -67,12 +58,15 @@ # end # end class Hoe # duh - VERSION = '2.2.0' + VERSION = '2.3.0' + @@plugins = [:clean, :debug, :deps, :flay, :flog, :package, :publish, + :rcov, :signing, :test] + ## # Used to add extra flags to RUBY_FLAGS. RUBY_DEBUG = ENV['RUBY_DEBUG'] @@ -214,23 +208,26 @@ # Find and load all plugin files. # # It is called at the end of hoe.rb def self.load_plugins - loaded = {} + loaded, found = {}, {} - Gem.find_files("hoe/*.rb").each do |plugin| - warn plugin if $DEBUG - name = File.basename plugin + Gem.find_files("hoe/*.rb").reverse.each do |path| + found[File.basename(path, ".rb").intern] = path + end + + :keep_doing_this while found.map { |name, plugin| + next unless Hoe.plugins.include? name next if loaded[name] begin - load plugin - loaded[name] = true + warn "loading #{plugin}" if $DEBUG + loaded[name] = load plugin rescue LoadError => e warn "error loading #{plugin.inspect}: #{e.message}. skipping..." end - end + }.any? end ## # Normalize a project name into the project, file, and klass cases (?!?). # @@ -253,17 +250,19 @@ ## # Return the list of activated plugins. def self.plugins - @@plugins ||= [] + @@plugins end ## # Create a new hoe-specification executing the supplied block def self.spec name, &block + Hoe.load_plugins + spec = self.new name spec.activate_plugins spec.instance_eval(&block) spec.post_initialize spec # TODO: remove? @@ -271,16 +270,23 @@ ## # Activate plugin modules and add them to the current instance. def activate_plugins - self.class.constants.reject { |n| n =~ /^[A-Z_]+$/ }.each do |name| + names = self.class.constants.map { |s| s.to_s } + names.reject! { |n| n =~ /^[A-Z_]+$/ } + + names.each do |name| + next unless Hoe.plugins.include? name.downcase.intern + warn "extend #{name}" if $DEBUG self.extend Hoe.const_get(name) end - self.class.plugins.each do |plugin| - send "initialize_#{plugin}" rescue nil + Hoe.plugins.each do |plugin| + msg = "initialize_#{plugin}" + warn msg if $DEBUG + send msg if self.respond_to? msg end end ## # Add standard and user defined dependencies to the spec. @@ -343,19 +349,10 @@ s.extra_rdoc_files += s.files.grep(/txt$/) s.extra_rdoc_files.reject! { |f| f =~ %r%^(test|spec|vendor|template|data|tmp)/% } s.extra_rdoc_files += @extra_rdoc_files - # Do any extra stuff the user wants - spec_extras.each do |msg, val| - case val - when Proc - val.call(s.send(msg)) - else - s.send "#{msg}=", val - end - end end unless self.version then version = nil @@ -370,10 +367,20 @@ unless self.version then spec.version = self.version = "0.borked" warn "Add 'VERSION = \"x.y.z\"' to your code or fix your hoe spec" end end + + # Do any extra stuff the user wants + spec_extras.each do |msg, val| + case val + when Proc + val.call spec.send(msg) + else + spec.send "#{msg}=", val + end + end end ## # Convenience method to set add to both the author and email fields. @@ -410,26 +417,28 @@ self.test_globs = ['test/**/test_*.rb'] self.url = nil if block_given? then warn "Hoe.new {...} deprecated. Switch to Hoe.spec." + Hoe.load_plugins self.activate_plugins yield self post_initialize end end ## # Intuit values from the readme and history files. def intuit_values - readme = File.read_utf(readme_file).split(/^(=+ .*)$/)[1..-1] rescue '' + header_re = /^((?:=+|#+) .*)$/ + readme = File.read_utf(readme_file).split(header_re)[1..-1] rescue '' + unless readme.empty? then - sections = readme.map { |s| - s =~ /^=/ ? s.strip.downcase.chomp(':').split.last : s.strip - } - sections = Hash[*sections] + sections = Hash[*readme.map { |s| + s =~ /^[=#]/ ? s.strip.downcase.chomp(':').split.last : s.strip + }] desc = sections.values_at(*description_sections).join("\n\n") summ = desc.split(/\.\s+/).first(summary_sentences).join(". ") self.description ||= desc self.summary ||= summ @@ -438,11 +447,11 @@ missing readme_file end self.changes ||= begin h = File.read_utf(history_file) - h.split(/^(===.*)/)[1..2].join.strip + h.split(/^(={2,}|\#{2,})/)[1..2].join.strip rescue missing history_file '' end end @@ -467,11 +476,11 @@ bad << plugin next end (Rake::Task.tasks - old_tasks).each do |task| - task.plugin = plugin # "%-#{max}s" % plugin + task.plugin = plugin end end @@plugins -= bad end @@ -548,25 +557,13 @@ rc = File.expand_path("~/.hoerc") exists = File.exist? rc config = exists ? YAML.load_file(rc) : {} yield(config, rc) end - - Hoe.load_plugins end class File # Like File::read, but strips out a BOM marker if it exists. def self.read_utf path File.read(path).sub(/\A\xEF\xBB\xBF/, '') - end -end - -module Rake - class Task - attr_accessor :plugin - alias :old_comment :comment - def comment - "%-#{$plugin_max}s # %s" % [plugin, old_comment] if old_comment - end end end