# Rakefile for flexmock        -*- ruby -*-

require 'rubygems'
require 'rake/gempackagetask'
require 'rake/clean'
require 'rake/rdoctask'
require 'rake/testtask'

CLEAN.include('*.tmp')
CLOBBER.include("html", 'pkg')

PKG_VERSION = '0.4.3'

PKG_FILES = FileList[
  '[A-Z]*',
  'lib/**/*.rb', 
  'test/**/*.rb',
  '*.blurb',
  'install.rb'
]

RDOC_FILES = FileList[
  'README',
  'CHANGELOG',
  'lib/**/*.rb',
  'doc/**/*.rdoc',
]


task :default => [:test_all]
task :test_all => [:test]
task :ta => [:test_all]

# Test Targets -------------------------------------------------------

Rake::TestTask.new do |t|
  t.pattern = 'test/test*.rb'
  t.verbose = true
  t.warning = true
end

# RDoc Target --------------------------------------------------------

rd = Rake::RDocTask.new("rdoc") do |rdoc|
  rdoc.rdoc_dir = 'html'
  rdoc.template = 'doc/jamis.rb'
#  rdoc.template = 'html'
#  rdoc.template = 'kilmer'
#  rdoc.template = 'css2'
  rdoc.title    = "Flex Mock"
  rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
  rdoc.rdoc_files.include(RDOC_FILES)
end

task :rdoc => ["README"]
file "README" => ["Rakefile"] do
  ruby %{-i.bak -pe 'sub!(/^Version *:: *(\\d+\\.)+\\d+ *$/, "Version :: #{PKG_VERSION}")' README} # "
end

# Package Task -------------------------------------------------------

if ! defined?(Gem)
  puts "Package Target requires RubyGEMs"
else
  spec = Gem::Specification.new do |s|
    
    #### Basic information.

    s.name = 'flexmock'
    s.version = PKG_VERSION
    s.summary = "Simple and Flexible Mock Objects for Testing"
    s.description = %{
      FlexMock is a extremely simple mock object class compatible
      with the Test::Unit framework.  Although the FlexMock's 
      interface is simple, it is very flexible.
    }				# '

    #### Dependencies and requirements.
    
    #s.add_dependency('log4r', '> 1.0.4')
    #s.requirements << ""
    
    #### Which files are to be included in this gem?  Everything!  (Except CVS directories.)

    s.files = PKG_FILES.to_a

    #### C code extensions.

    #s.extensions << "ext/rmagic/extconf.rb"

    #### Load-time details: library and application (you will need one or both).

    s.require_path = 'lib'                         # Use these for libraries.

    #### Documentation and testing.

    s.has_rdoc = true
    s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
    s.rdoc_options <<
      '--title' <<  'Flex Mock' <<
      '--main' << 'README' <<
      '--line-numbers'

    #### Author and project details.

    s.author = "Jim Weirich"
    s.email = "jim@weirichhouse.org"
    s.homepage = "http://onestepback.org/software/flexmock"
  end

  Rake::GemPackageTask.new(spec) do |pkg|
    pkg.need_zip = true
    pkg.need_tar = true
  end
end

desc "Display a list of all the rubyfiles in the project."
task :rubyfiles do
  puts FileList['**/*.rb']
end
task :rf => :rubyfiles

require 'rake/contrib/publisher'
require 'rake/contrib/sshpublisher'

task :publish => [:rdoc] do
  html_publisher = Rake::SshFreshDirPublisher.new(
    'umlcoop',
    'htdocs/software/flexmock',
    'html')
  blurb_publisher = Rake::SshFilePublisher.new(
    'umlcoop',
    'htdocs/software/flexmock',
    '.',
    'flexmock.blurb')
  html_publisher.upload
  blurb_publisher.upload
end

SVNHOME = 'svn://localhost/software/flexmock'

task :specs do
  specs = FileList['test/spec_*.rb']
  ENV['RUBYLIB'] = "lib:test:#{ENV['RUBYLIB']}"
  sh %{spec #{specs}}
end

task :tag do
  sh %{svn copy #{SVNHOME}/trunk #{SVNHOME}/tags/rel-#{PKG_VERSION} -m 'Release #{PKG_VERSION}'}
end

RUBY_FILES = FileList['**/*.rb']
RUBY_FILES.exclude(/^pkg/)
task :dbg do
  RUBY_FILES.egrep(/DBG/)
end
