Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updating to latest fixme

  • Loading branch information...
commit 911465544dffd2d16d706987543b9aa0e9227331 1 parent b06d682
Jeremy Hinegardner authored
2  CONTRIBUTING.md
View
@@ -18,7 +18,7 @@ easiest way to contribute.
* **Bug reports** please be as detailed as possible. Include:
* full ruby engine and version: `ruby -e 'puts RUBY_DESCRIPTION'`
* operating system and version
- * version of hitimes `ruby -e 'ruby -rubygems -e "require 'hitimes'; puts Hitimes::VERSION'`
+ * version of hitimes `ruby -rubygems -e "require 'hitimes'; puts Hitimes::VERSION"`
* as much detail about the bug as possible so I can replicated it. Feel free
to link in a [gist][]
* **New Feature**
10 Manifest.txt
View
@@ -29,6 +29,7 @@ lib/hitimes/timed_metric.rb
lib/hitimes/timed_value_metric.rb
lib/hitimes/value_metric.rb
lib/hitimes/version.rb
+spec/hitimes_spec.rb
spec/interval_spec.rb
spec/metric_spec.rb
spec/mutex_stats_spec.rb
@@ -39,11 +40,6 @@ spec/timed_metric_spec.rb
spec/timed_value_metric_spec.rb
spec/value_metric_spec.rb
spec/version_spec.rb
-tasks/announce.rake
-tasks/config.rb
-tasks/distribution.rake
-tasks/documentation.rake
+tasks/default.rake
tasks/extension.rake
-tasks/rspec.rake
-tasks/rubyforge.rake
-tasks/utils.rb
+tasks/this.rb
354 Rakefile
View
@@ -1,364 +1,24 @@
# vim: syntax=ruby
+load 'tasks/this.rb'
This.name = "hitimes"
This.author = "Jeremy Hinegardner"
This.email = "jeremy@copiousfreetime.org"
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
-This.version = Util.version
-#------------------------------------------------------------------------------
-# If you want to Develop on this project just run 'rake develop' and you'll
-# have all you need to get going. If you want to use bundler for development,
-# then run 'rake develop:using_bundler'
-#------------------------------------------------------------------------------
-namespace :develop do
-
- # Install all the development and runtime dependencies of this gem using the
- # gemspec.
- task :default do
- require 'rubygems/dependency_installer'
- installer = Gem::DependencyInstaller.new
-
- Util.set_coverage_gem
-
- puts "Installing gem depedencies needed for development"
- Util.platform_gemspec.dependencies.each do |dep|
- if dep.matching_specs.empty? then
- puts "Installing : #{dep}"
- installer.install dep
- else
- puts "Skipping : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
- end
- end
- puts "\n\nNow run 'rake test'"
- end
-
- # Create a Gemfile that just references the gemspec
- file 'Gemfile' => :gemspec do
- File.open( "Gemfile", "w+" ) do |f|
- f.puts 'source :rubygems'
- f.puts 'gemspec'
- end
- end
-
- desc "Create a bundler Gemfile"
- task :using_bundler => 'Gemfile' do
- puts "Now you can 'bundle'"
- end
-
- # Gemfiles are build artifacts
- CLOBBER << FileList['Gemfile*']
-end
-desc "Bootstrap development"
-task :develop => "develop:default"
-
-#------------------------------------------------------------------------------
-# RSpec tests
-#------------------------------------------------------------------------------
-begin
- require 'rspec/core/rake_task'
- RSpec::Core::RakeTask.new( :test ) do |t|
- t.ruby_opts = %w[ -w -rubygems ]
- t.rspec_opts = %w[ --format doc --color ]
- end
- task :default => :test
-rescue LoadError
- Util.task_warning( 'test' )
-end
-
-#------------------------------------------------------------------------------
-# RDoc - standard rdoc rake task, although we must make sure to use a more
-# recent version of rdoc since it is the one that has 'tomdoc' markup
-#------------------------------------------------------------------------------
-begin
- gem 'rdoc' # otherwise we get the wrong task from stdlib
- require 'rdoc/task'
- RDoc::Task.new do |t|
- t.markup = 'tomdoc'
- t.rdoc_dir = 'doc'
- t.main = 'README.rdoc'
- t.title = "#{This.name} #{This.version}"
- t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
- end
-rescue LoadError => le
- Util.task_warning( 'rdoc' )
-end
-
-#------------------------------------------------------------------------------
-# Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
-# for the moment only rcov is listed.
-#------------------------------------------------------------------------------
-if RUBY_VERSION < "1.9.2"
- begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new( 'coverage' ) do |t|
- t.libs << 'spec'
- t.pattern = 'spec/**/*_spec.rb'
- t.verbose = true
- t.rcov_opts << "-x ^/" # remove all the global files
- t.rcov_opts << "--sort coverage" # so we see the worst files at the top
- end
- rescue LoadError
- Util.task_warning( 'rcov' )
- end
-else
- begin
- require 'simplecov'
- desc 'Run tests with code coverage'
- task :coverage do
- ENV['COVERAGE'] = 'true'
- Rake::Task[:test].execute
- end
- CLOBBER << FileList["coverage"]
- rescue LoadError
- Util.task_warning( 'simplecov' )
- end
-end
-
-#------------------------------------------------------------------------------
-# Manifest - We want an explicit list of thos files that are to be packaged in
-# the gem. Most of this is from Hoe.
-#------------------------------------------------------------------------------
-namespace 'manifest' do
- desc "Check the manifest"
- task :check => :clean do
- files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
- files = files.select{ |f| File.file?( f ) }
-
- tmp = "Manifest.tmp"
- File.open( tmp, 'w' ) do |f|
- f.puts files.join("\n")
- end
-
- begin
- sh "diff -du Manifest.txt #{tmp}"
- ensure
- rm tmp
- end
- puts "Manifest looks good"
- end
-
- desc "Generate the manifest"
- task :generate => :clean do
- files = %x[ git ls-files ].split("\n").sort
- files.reject! { |f| f =~ This.exclude_from_manifest }
- File.open( "Manifest.txt", "w" ) do |f|
- f.puts files.join("\n")
- end
- end
-end
-
-#------------------------------------------------------------------------------
-# hitimes - look for fixmes and report them
-#------------------------------------------------------------------------------
-task :fixme => 'manifest:check' do
- Util.read_manifest.each do |file|
- next if file == File.basename( __FILE__ )
-
- puts "FIXME: Rename #{file}" if file =~ /fixme/i
-
- IO.readlines( file ).each_with_index do |line, idx|
- prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
- puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
- end
- end
-end
-
-#------------------------------------------------------------------------------
-# Gem Specification
-#------------------------------------------------------------------------------
-This.gemspec = Hash.new
-This.gemspec['ruby'] = Gem::Specification.new do |spec|
- spec.name = This.name
- spec.version = This.version
- spec.author = This.author
- spec.email = This.email
- spec.homepage = This.homepage
-
- spec.summary = This.summary
- spec.description = This.description
-
- spec.files = This.manifest
- spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
- spec.test_files = spec.files.grep(/^spec/)
-
- spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc)$/)
- spec.rdoc_options = [ "--main" , 'README.rdoc', ]
-
- # The Runtime Dependencies
- # spec.add_dependency( 'map', '~> 6.2.0')
-
- # The Development Dependencies
+This.ruby_gemspec do |spec|
spec.add_development_dependency( 'rake' , '~> 10.0.3')
spec.add_development_dependency( 'rspec' , '~> 2.12.0' )
spec.add_development_dependency( 'rdoc' , '~> 3.12' )
spec.add_development_dependency( 'json' , '~> 1.7.6' )
spec.add_development_dependency( 'rake-compiler', '~> 0.8.1' )
- spec.extensions.concat Util.extension_conf_files
+ spec.extensions.concat This.extension_conf_files
end
-#--------------------------------------------------
-# JRuby spec has some alterations
-#--------------------------------------------------
-jruby_gemspec = This.gemspec['ruby'].dup
-jruby_gemspec.extensions.clear
-jruby_gemspec.platform = 'java'
-This.gemspec['java'] = jruby_gemspec
-
-# The name of the gemspec file on disk
-This.gemspec_file = "#{This.name}.gemspec"
-
-# Really this is only here to support those who use bundler
-desc "Build the #{This.name}.gemspec file"
-task :gemspec do
- Util.set_coverage_gem
- File.open( This.gemspec_file, "wb+" ) do |f|
- f.write Util.platform_gemspec.to_ruby
- end
-end
-
-# the gemspec is also a dev artifact and should not be kept around.
-CLOBBER << This.gemspec_file
-
-# The standard gem packaging task, everyone has it.
-require 'rubygems/package_task'
-Gem::PackageTask.new( Util.platform_gemspec ) do
- # nothing
-end
-
-#------------------------------------------------------------------------------
-# Release - the steps we go through to do a final release, this is pulled from
-# a compbination of mojombo's rakegem, hoe and hoe-git
-#
-# 1) make sure we are on the master branch
-# 2) make sure there are no uncommitted items
-# 3) check the manifest and make sure all looks good
-# 4) build the gem
-# 5) do an empty commit to have the commit message of the version
-# 6) tag that commit as the version
-# 7) push master
-# 8) push the tag
-# 7) pus the gem
-#------------------------------------------------------------------------------
-task :release_check do
- unless `git branch` =~ /^\* master$/
- abort "You must be on the master branch to release!"
- end
- unless `git status` =~ /^nothing to commit/m
- abort "Nope, sorry, you have unfinished business"
- end
+This.java_gemspec do |spec|
+ spec.extensions.clear
end
-desc "Create tag v#{This.version}, build and push #{Util.platform_gemspec.full_name} to rubygems.org"
-task :release => [ :release_check, 'manifest:check', :gem ] do
- sh "git commit --allow-empty -a -m 'Release #{This.version}'"
- sh "git tag -a -m 'v#{This.version}' v#{This.version}"
- sh "git push origin master"
- sh "git push origin v#{This.version}"
- sh "gem push pkg/#{Util.platform_gemspec.full_name}.gem"
-end
-
-#------------------------------------------------------------------------------
-# Load the extra rake tasks
-#------------------------------------------------------------------------------
-$: << "." unless $:.include?(".")
-begin
- load 'tasks/extension.rake'
-rescue LoadError => e
- Util.task_warning( 'extension' )
-end
-
-#------------------------------------------------------------------------------
-# Rakefile Support - This is all the guts and utility methods that are
-# necessary to support the above tasks.
-#
-# Lots of Credit for this Rakefile goes to:
-#
-# Ara T. Howard - see the Rakefile in all of his projects -
-# https://github.com/ahoward/
-# Tom Preston Werner - his Rakegem project https://github.com/mojombo/rakegem
-# Seattle.rb - Hoe - cuz it has relly good stuff in there
-#------------------------------------------------------------------------------
-BEGIN {
-
- require 'ostruct'
- require 'rake/clean'
- require 'rubygems' unless defined? Gem
-
- module Util
- def self.version
- [ "lib/#{ This.name }.rb", "lib/#{ This.name }/version.rb" ].each do |v|
- line = File.read( v )[/^\s*VERSION\s*=\s*.*/]
- if line then
- return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
- end
- end
- end
-
- # Partition an rdoc file into sections and return the text of the section
- # as an array of paragraphs
- def self.section_of( file, section_name )
- re = /^=+ (.*)$/
- parts = File.read( file ).split( re )[1..-1]
- parts.map! { |p| p.strip }
-
- sections = Hash.new
- Hash[*parts].each do |k,v|
- sections[k] = v.split("\n\n")
- end
- return sections[section_name]
- end
-
- def self.task_warning( task )
- warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
- end
-
- def self.read_manifest
- abort "You need a Manifest.txt" unless File.readable?( "Manifest.txt" )
- File.readlines( "Manifest.txt" ).map { |l| l.strip }
- end
-
- def self.extension_conf_files
- read_manifest.grep( /extconf.rb\Z/ )
- end
-
- def self.platform_gemspec
- This.gemspec[This.platform]
- end
-
- def self.proj_root_path
- Pathname.new( File.expand_path( "..", __FILE__ ) )
- end
-
- def self.set_coverage_gem
- # list these here instead of gem dependencies since there is not a way to
- # specify ruby version specific dependencies
- g, v = 'simplecov', '~> 0.7.1'
- if RUBY_VERSION < "1.9.2"
- g, v = 'rcov', '~> 1.0.0'
- end
-
- if Util.platform_gemspec.dependencies.none? { |s| s.name == g } then
- Util.platform_gemspec.add_development_dependency( g, v )
- end
- end
-
- def self.proj_path( *args )
- proj_root_path.join( *args )
- end
- end
-
- # Hold all the metadata about this project
- This = OpenStruct.new
- This.platform = (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
-
- desc = Util.section_of( 'README.rdoc', 'DESCRIPTION')
- This.summary = desc.first
- This.description = desc.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
-
-
- This.exclude_from_manifest = %r/tmp$|\.(git|DS_Store)|^(doc|coverage|pkg)|Gemfile*|\.gemspec$|\.swp$|\.jar|\.rvmrc$|~$/
- This.manifest = Util.read_manifest
-
-}
+load 'tasks/default.rake'
+load 'tasks/extension.rake'
264 tasks/default.rake
View
@@ -0,0 +1,264 @@
+# vim: syntax=ruby
+require 'rake/clean'
+#------------------------------------------------------------------------------
+# If you want to Develop on this project just run 'rake develop' and you'll
+# have all you need to get going. If you want to use bundler for development,
+# then run 'rake develop:using_bundler'
+#------------------------------------------------------------------------------
+namespace :develop do
+
+ # Install all the development and runtime dependencies of this gem using the
+ # gemspec.
+ task :default do
+ require 'rubygems/dependency_installer'
+ installer = Gem::DependencyInstaller.new
+
+ This.set_coverage_gem
+
+ puts "Installing gem depedencies needed for development"
+ This.platform_gemspec.dependencies.each do |dep|
+ if dep.matching_specs.empty? then
+ puts "Installing : #{dep}"
+ installer.install dep
+ else
+ puts "Skipping : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
+ end
+ end
+ puts "\n\nNow run 'rake test'"
+ end
+
+ # Create a Gemfile that just references the gemspec
+ file 'Gemfile' => :gemspec do
+ File.open( "Gemfile", "w+" ) do |f|
+ f.puts 'source :rubygems'
+ f.puts 'gemspec'
+ end
+ end
+
+ desc "Create a bundler Gemfile"
+ task :using_bundler => 'Gemfile' do
+ puts "Now you can 'bundle'"
+ end
+
+ # Gemfiles are build artifacts
+ CLOBBER << FileList['Gemfile*']
+end
+desc "Boostrap development"
+task :develop => "develop:default"
+
+#------------------------------------------------------------------------------
+# Minitest - standard TestTask
+#------------------------------------------------------------------------------
+begin
+ require 'rake/testtask'
+ Rake::TestTask.new( :test ) do |t|
+ t.ruby_opts = %w[ -w -rubygems ]
+ t.libs = %w[ lib spec ]
+ t.pattern = "spec/**/*_spec.rb"
+ end
+ task :default => :test
+rescue LoadError
+ This.task_warning( 'test' )
+end
+
+#------------------------------------------------------------------------------
+# RDoc - standard rdoc rake task, although we must make sure to use a more
+# recent version of rdoc since it is the one that has 'tomdoc' markup
+#------------------------------------------------------------------------------
+begin
+ gem 'rdoc' # otherwise we get the wrong task from stdlib
+ require 'rdoc/task'
+ RDoc::Task.new do |t|
+ t.markup = 'tomdoc'
+ t.rdoc_dir = 'doc'
+ t.main = 'README.rdoc'
+ t.title = "#{This.name} #{This.version}"
+ t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
+ end
+rescue LoadError => le
+ This.task_warning( 'rdoc' )
+end
+
+#------------------------------------------------------------------------------
+# Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
+# for the moment only rcov is listed.
+#------------------------------------------------------------------------------
+if RUBY_VERSION < "1.9.0"
+ begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new( 'coverage' ) do |t|
+ t.libs << 'spec'
+ t.pattern = 'spec/**/*_spec.rb'
+ t.verbose = true
+ t.rcov_opts << "-x ^/" # remove all the global files
+ t.rcov_opts << "--sort coverage" # so we see the worst files at the top
+ end
+ rescue LoadError
+ This.task_warning( 'rcov' )
+ end
+else
+ begin
+ require 'simplecov'
+ desc 'Run tests with code coverage'
+ task :coverage do
+ ENV['COVERAGE'] = 'true'
+ Rake::Task[:test].execute
+ end
+ CLOBBER << FileList["coverage"]
+ rescue LoadError
+ This.task_warning( 'simplecov' )
+ end
+end
+
+#------------------------------------------------------------------------------
+# Manifest - We want an explicit list of thos files that are to be packaged in
+# the gem. Most of this is from Hoe.
+#------------------------------------------------------------------------------
+namespace 'manifest' do
+ desc "Check the manifest"
+ task :check => :clean do
+ files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
+ files = files.select{ |f| File.file?( f ) }
+
+ tmp = "Manifest.tmp"
+ File.open( tmp, 'w' ) do |f|
+ f.puts files.join("\n")
+ end
+
+ begin
+ sh "diff -du Manifest.txt #{tmp}"
+ ensure
+ rm tmp
+ end
+ puts "Manifest looks good"
+ end
+
+ desc "Generate the manifest"
+ task :generate => :clean do
+ files = %x[ git ls-files ].split("\n").sort
+ files.reject! { |f| f =~ This.exclude_from_manifest }
+ File.open( "Manifest.txt", "w" ) do |f|
+ f.puts files.join("\n")
+ end
+ end
+end
+
+#------------------------------------------------------------------------------
+# Fixme - look for fixmes and report them
+#------------------------------------------------------------------------------
+namespace :fixme do
+ task :default => 'manifest:check' do
+ This.manifest.each do |file|
+ next if file == __FILE__
+ next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
+ puts "FIXME: Rename #{file}" if file =~ /fixme/i
+ IO.readlines( file ).each_with_index do |line, idx|
+ prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
+ puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
+ end
+ end
+ end
+
+ def fixme_project_root
+ This.project_path( '../fixme' )
+ end
+
+ def fixme_project_path( subtree )
+ fixme_project_root.join( subtree )
+ end
+
+ def local_fixme_files
+ This.manifest.select { |p| p =~ %r|^tasks/| }
+ end
+
+ def outdated_fixme_files
+ local_fixme_files.reject do |local|
+ upstream = fixme_project_path( local )
+ Digest::SHA256.file( local ) == Digest::SHA256.file( upstream )
+ end
+ end
+
+ def fixme_up_to_date?
+ outdated_fixme_files.empty?
+ end
+
+ desc "See if the fixme tools are outdated"
+ task :outdated => :release_check do
+ if fixme_up_to_date? then
+ puts "Fixme files are up to date."
+ else
+ outdated_fixme_files.each do |f|
+ puts "#{f} is outdated"
+ end
+ end
+ end
+
+ desc "Update outdated fixme files"
+ task :update => :release_check do
+ if fixme_up_to_date? then
+ puts "Fixme files are already up to date."
+ else
+ puts "Updating fixme files:"
+ outdated_fixme_files.each do |local|
+ upstream = fixme_project_path( local )
+ puts " * #{local}"
+ FileUtils.cp( upstream, local )
+ end
+ puts "Use your git commands as appropriate."
+ end
+ end
+end
+desc "Look for fixmes and report them"
+task :fixme => "fixme:default"
+
+#------------------------------------------------------------------------------
+# Gem Specification
+#------------------------------------------------------------------------------
+# Really this is only here to support those who use bundler
+desc "Build the #{This.name}.gemspec file"
+task :gemspec do
+ File.open( This.gemspec_file, "wb+" ) do |f|
+ f.write This.platform_gemspec.to_ruby
+ end
+end
+
+# the gemspec is also a dev artifact and should not be kept around.
+CLOBBER << This.gemspec_file
+
+# The standard gem packaging task, everyone has it.
+require 'rubygems/package_task'
+Gem::PackageTask.new( This.platform_gemspec ) do
+ # nothing
+end
+
+#------------------------------------------------------------------------------
+# Release - the steps we go through to do a final release, this is pulled from
+# a compbination of mojombo's rakegem, hoe and hoe-git
+#
+# 1) make sure we are on the master branch
+# 2) make sure there are no uncommitted items
+# 3) check the manifest and make sure all looks good
+# 4) build the gem
+# 5) do an empty commit to have the commit message of the version
+# 6) tag that commit as the version
+# 7) push master
+# 8) push the tag
+# 7) pus the gem
+#------------------------------------------------------------------------------
+task :release_check do
+ unless `git branch` =~ /^\* master$/
+ abort "You must be on the master branch to release!"
+ end
+ unless `git status` =~ /^nothing to commit/m
+ abort "Nope, sorry, you have unfinished business"
+ end
+end
+
+desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
+task :release => [ :release_check, 'manifest:check', :gem ] do
+ sh "git commit --allow-empty -a -m 'Release #{This.version}'"
+ sh "git tag -a -m 'v#{This.version}' v#{This.version}"
+ sh "git push origin master"
+ sh "git push origin v#{This.version}"
+ sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
+end
12 tasks/extension.rake
View
@@ -38,24 +38,22 @@ namespace :ext do
def ext_dest_dir
version_sub = RUBY_VERSION.sub(/\.\d$/,'')
- dest_dir = Util.proj_path( 'lib', 'hitimes', version_sub )
+ This.project_path( 'lib', 'hitimes', version_sub )
end
def with_each_extension
- Util.platform_gemspec.extensions.each do |ext|
+ This.platform_gemspec.extensions.each do |ext|
yield ext
end
end
def build_win( version = "1.8.7" )
- ext_config = Util.platform_gemspec.extensions.frist
+ ext_config = This.platform_gemspec.extensions.frist
return nil unless ext_config.cross_rbconfig
rbconfig = ext_config.cross_rbconfig["rbconfig-#{version}"]
raise ArgumentError, "No cross compiler for version #{version}, we have #{ext_config.cross_rbconfig.keys.join(",")}" unless rbconfig
with_each_extension do |extension|
path = Pathname.new(extension)
- parts = path.split
- conf = parts.last
rvm = File.expand_path( "~/.rvm/bin/rvm" )
Dir.chdir(path.dirname) do |d|
if File.exist?( "Makefile" ) then
@@ -85,8 +83,6 @@ namespace :ext do
task :clean do
with_each_extension do |extension|
path = Pathname.new(extension)
- parts = path.split
- conf = parts.last
Dir.chdir(path.dirname) do |d|
if File.exist?( "Makefile" ) then
sh "make clean"
@@ -99,8 +95,6 @@ namespace :ext do
task :clobber do
with_each_extension do |extension|
path = Pathname.new(extension)
- parts = path.split
- conf = parts.last
Dir.chdir(path.dirname) do |d|
if File.exist?( "Makefile" ) then
sh "make distclean"
209 tasks/this.rb
View
@@ -0,0 +1,209 @@
+require 'pathname'
+
+# Public: A Class containing all the metadata and utilities needed to manage a
+# ruby project.
+class ThisProject
+ # The name of this project
+ attr_accessor :name
+
+ # The author's name
+ attr_accessor :author
+
+ # The email address of the author(s)
+ attr_accessor :email
+
+ # The homepage of this project
+ attr_accessor :homepage
+
+ # The regex of files to exclude from the manifest
+ attr_accessor :exclude_from_manifest
+
+ # The hash of Gem::Specifications keyed' by platform
+ attr_accessor :gemspecs
+
+ # Public: Initialize ThisProject
+ #
+ # Yields self
+ def initialize(&block)
+ @exclude_from_manifest = %r/tmp$|\.(git|DS_Store)|^(doc|coverage|pkg)|Gemfile*|\.gemspec$|\.swp$|\.jar|\.rvmrc$|~$/
+ @gemspecs = Hash.new
+ yield self if block_given?
+ end
+
+ # Public: return the version of ThisProject
+ #
+ # Search the ruby files in the project looking for the one that has the
+ # version string in it. This does not eval any code in the project, it parses
+ # the source code looking for the string.
+ #
+ # Returns a String version
+ def version
+ [ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
+ path = project_path( v )
+ line = path.read[/^\s*VERSION\s*=\s*.*/]
+ if line then
+ return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+ end
+ end
+ end
+
+ # Internal: Return a section of an RDoc file with the given section name
+ #
+ # path - the relative path in the project of the file to parse
+ # section_name - the section out of the file from which to parse data
+ #
+ # Retuns the text of the section as an array of paragrphs.
+ def section_of( file, section_name )
+ re = /^=+ (.*)$/
+ sectional = project_path( file )
+ parts = sectional.read.split( re )[1..-1]
+ parts.map! { |p| p.strip }
+
+ sections = Hash.new
+ Hash[*parts].each do |k,v|
+ sections[k] = v.split("\n\n")
+ end
+ return sections[section_name]
+ end
+
+ # Internal: print out a warning about the give task
+ def task_warning( task )
+ warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
+ end
+
+ # Internal: Return the full path to the file that is relative to the project
+ # root.
+ #
+ # path - the relative path of the file from the project root
+ #
+ # Returns the Pathname of the file
+ def project_path( *relative_path )
+ project_root.join( *relative_path )
+ end
+
+ # Internal: The absolute path of this file
+ #
+ # Returns the Pathname of this file.
+ def this_file_path
+ Pathname.new( __FILE__ ).expand_path
+ end
+
+ # Internal: The root directory of this project
+ #
+ # This is defined as being the directory that is in the path of this project
+ # that has the first Rakefile
+ #
+ # Returns the Pathname of the directory
+ def project_root
+ this_file_path.ascend do |p|
+ rakefile = p.join( 'Rakefile' )
+ return p if rakefile.exist?
+ end
+ end
+
+ # Internal: Returns the contents of the Manifest.txt file as an array
+ #
+ # Returns an Array of strings
+ def manifest
+ manifest_file = project_path( "Manifest.txt" )
+ abort "You need a Manifest.txt" unless manifest_file.readable?
+ manifest_file.readlines.map { |l| l.strip }
+ end
+
+ # Internal: Return the files that define the extensions
+ #
+ # Returns an Array
+ def extension_conf_files
+ manifest.grep( /extconf.rb\Z/ )
+ end
+
+ # Internal: Returns the gemspace associated with the current ruby platform
+ def platform_gemspec
+ gemspecs[platform]
+ end
+
+ def core_gemspec
+ Gem::Specification.new do |spec|
+ spec.name = name
+ spec.version = version
+ spec.author = author
+ spec.email = email
+ spec.homepage = homepage
+
+ spec.summary = summary
+ spec.description = description
+
+ spec.files = manifest
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(/^spec/)
+
+ spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc)$/)
+ spec.rdoc_options = [ "--main" , 'README.rdoc',
+ "--markup", "tomdoc" ]
+ end
+ end
+
+ # Internal: Return the gemspec for the ruby platform
+ def ruby_gemspec( core = core_gemspec, &block )
+ yielding_gemspec( 'ruby', core, &block )
+ end
+
+ # Internal: Return the gemspec for the jruby platform
+ def java_gemspec( core = core_gemspec, &block )
+ yielding_gemspec( 'java', core, &block )
+ end
+
+ # Internal: give an initial spec and a key, create a new gemspec based off of
+ # it.
+ #
+ # This will force the new gemspecs 'platform' to be that of the key, since the
+ # only reason you would have multiple gemspecs at this point is to deal with
+ # different platforms.
+ def yielding_gemspec( key, core )
+ spec = gemspecs[key] ||= core.dup
+ spec.platform = key
+ yield spec if block_given?
+ return spec
+ end
+
+ # Internal: Set the recovery gem development dependency
+ #
+ # These are dynamically set since they cannot be hard coded as there is
+ # no way to ship them correctly in the gemspec
+ #
+ # Returns nothing.
+ def set_coverage_gem
+ if RUBY_VERSION < "1.9.0"
+ platform_gemspec.add_development_dependency( 'rcov', '~> 1.0.0' )
+ else
+ platform_gemspec.add_development_dependency( 'simplecov', '~> 0.7.1' )
+ end
+ end
+
+ # Internal: Return the platform of ThisProject at the current moment in time.
+ def platform
+ (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
+ end
+
+ # Internal: Return the DESCRIPTION section of the README.rdoc file
+ def description_section
+ section_of( 'README.rdoc', 'DESCRIPTION')
+ end
+
+ # Internal: Return the summary text from the README
+ def summary
+ description_section.first
+ end
+
+ # Internal: Return the full description text from the READEM
+ def description
+ description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
+ end
+
+ # Internal: The path to the gemspec file
+ def gemspec_file
+ project_path( "#{ name }.gemspec" )
+ end
+end
+
+This = ThisProject.new
Please sign in to comment.
Something went wrong with that request. Please try again.