# Rakefile for RubyGems      -*- ruby -*-

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

PKG_NAME = 'rubygems'
PKG_VERSION = `ruby -Ilib bin/gem environment packageversion`.chomp

CLEAN.include("COMMENTS")
CLOBBER.include(
  "test/data/one/one-*0.0.1.gem",
  "test/temp",
  'test/data/gemhome',
  'scripts/*.wiki'
  )

task :default => [:test]

desc "Run unit tests"
task :test do
  test_name = ENV['TEST'] || 'test/test*.rb'
  ruby %{-Ilib -rscripts/runtest -e 'run_tests("#{test_name}", true)'}
end

desc "Run Functional Tests"
task :functional do
  test_name = ENV['TEST'] || 'test/functional.rb'
  ruby %{-Ilib -rscripts/runtest -e 'run_tests("#{test_name}", true)'}
end

desc "Run All Tests"
task :alltests do
  test_name = ENV['TEST'] || 'test/{test,functional}*.rb'
  ruby %{-Ilib -rscripts/runtest -e 'run_tests("#{test_name}", true)'}
end

# Shortcuts for test targets
task :ft => [:functional]
task :ut => [:test]
task :at => [:alltests]

task :gemtest do
  ruby %{-Ilib -rscripts/runtest -e 'run_tests("test/test_gempaths.rb", true)'}
end

# Wiki Doc Targets

desc "Build the Wiki documentation"
task :wiki => ['scripts/gemdoc.wiki', 'scripts/specdoc.wiki']

file 'scripts/gemdoc.wiki' => ['scripts/gemdoc.rb', 'scripts/gemdoc.data'] do
  chdir('scripts') do
    ruby %{-I../lib gemdoc.rb <gemdoc.data >gemdoc.wiki}
  end
end

file 'scripts/specdoc.wiki' =>
  ['scripts/specdoc.rb', 'scripts/specdoc.data', 'scripts/specdoc.yaml'] do
  chdir('scripts') do
    ruby %{-I../lib specdoc.rb >specdoc.wiki}
  end
end

# Package tasks

PKG_FILES = FileList[
  "Rakefile", "ChangeLog", "Releases", "TODO", "README", 
  "install.rb",
  "bin/*",
  "doc/*.css", "doc/*.rb",
  "examples/**/*",
  "gemspecs/**/*",
  "lib/**/*.rb",
  "packages/**/*",
  "redist/*.gem",
  "scripts/*.rb",
  "test/**/*"
]

Rake::PackageTask.new("package") do |p|
  p.name = PKG_NAME
  p.version = PKG_VERSION
  p.need_tar = true
  p.need_zip = true
  p.package_files = PKG_FILES
end


spec = Gem::Specification.new do |s|
  s.name = PKG_NAME + "-update"  
  s.version = PKG_VERSION
  s.summary = "RubyGems Update GEM"
  s.description = <<-EOF
RubyGems is a package management framework for Ruby.  This Gem
is a update for the base RubyGems software.  You must have a base
installation of RubyGems before this update can be applied.
    EOF
  s.files = PKG_FILES.to_a
  s.require_path = 'lib'
  s.author = "RubyGems Team"
  s.email = "rubygems-developers@rubyforge.org"
  s.homepage = "http://rubygems.rubyforge.org"
  s.rubyforge_project = "rubygems"
  s.bindir = "bin"                               # Use these for applications.
  s.executables = ["update_rubygems"]
end

Rake::GemPackageTask.new(spec) do |p| end

# Install RubyGems

desc "Install RubyGems"
task :install do
  ruby 'install.rb'
end

# Run 'gem' (using local bin and lib directories).
# e.g.
#     rake rungem -- install -r blahblah --test

desc "Run local 'gem'"
task :rungem do
  ARGV.shift
  exec "ruby -Ilib bin/gem #{ARGV.join(' ')}"
end
