require 'rubygems'

require 'rake'
require 'rake/testtask'
require 'rdoc/task'
require 'rake/gempackagetask'
require 'test/unit'

require File.dirname(__FILE__) + '/lib/atmos'

task :default => :test


desc "run tests"
Rake::TestTask.new do |t|
   libdir  = File.expand_path('lib')
   testdir = File.expand_path('test')
   
   t.libs = [libdir, testdir]
   #t.pattern = 'test/lib/test_*.rb'
   t.verbose = true
   #t.warning = true
end


Rake::RDocTask.new do |rdoc|  
   rdoc.rdoc_dir = 'doc'  
   rdoc.title    = "EMC Atmos' REST API gem - ruby-atmos"  
   rdoc.options << '--line-numbers' << '--inline-source' << '--main=README'
   rdoc.rdoc_files.include('README')
   rdoc.rdoc_files.include('lib/*.rb')
   rdoc.rdoc_files.include('lib/atmos/*.rb')  
end


spec = Gem::Specification.new do |s|
   s.platform          = Gem::Platform::RUBY
   s.name              = 'ruby-atmos'
   s.version           = Gem::Version.new(Atmos::VERSION)
   s.summary           = "Client library for EMC's Atmos REST API"
   s.description       = "Ruby OO library to access an EMC Atmos server as a blobstore."
   s.email             = 'fleur.dragan@emc.com'
   s.author            = 'Fleur Dragan'
   s.has_rdoc          = true
   s.extra_rdoc_files  = %w(README COPYING)
   s.homepage          = 'http://www.emc.com/atmos'
    #s.rubyforge_project = 'atmos'
   s.files             = FileList['Rakefile', 'lib/atmos.rb', 'lib/*/*.rb']
   s.test_files        = Dir['test/**/*']
   s.require_path      = 'lib'
   s.add_dependency('log4r',     '>=1.1.9')
   s.add_dependency('ruby-hmac', '>=0.4.0')

   s.rdoc_options  = ['--title', "EMC Atmos' REST API gem - ruby-atmos",
                       '--main',  'README',
                       '--line-numbers', '--inline-source']
end

#
# DRY: set up gemspecs for both versions of gems
#
nokogiri_spec = spec.clone
nokogiri_spec.name = 'ruby-atmos'
nokogiri_spec.add_dependency('nokogiri',  '>=1.4.4')
nokogiri_spec.description = "Ruby OO library to access an EMC Atmos server with nokogiri as XML parser."
nokogiri_spec.rubyforge_project = nokogiri_spec.name

rexml_spec = spec.clone
rexml_spec.name = 'ruby-atmos-pure'
rexml_spec.files += FileList['lib/atmos/*/rexml.rb']
rexml_spec.description = "Ruby OO library to access an EMC Atmos server with rexml as XML parser."
rexml_spec.rubyforge_project = rexml_spec.name


#
# creating the actual package tasks for the two gems
#
Rake::GemPackageTask.new(nokogiri_spec) { |pkg| }
Rake::GemPackageTask.new(rexml_spec) { |pkg| }

desc 'install, require both gems'
task :installtest do
       sh "sudo gem i pkg/#{rexml_spec.name}-#{rexml_spec.version}.gem"
       sh "ruby test/require_test.rb"
       sh "sudo gem uninstall #{rexml_spec.name} -x"
       sh "sudo gem i pkg/#{nokogiri_spec.name}-#{nokogiri_spec.version}.gem"
       sh "ruby test/require_test.rb"
end
  
desc 'install, require both gems'
task :install do
       sh "sudo gem i pkg/#{rexml_spec.name}-#{rexml_spec.version}.gem"
       sh "sudo gem i pkg/#{nokogiri_spec.name}-#{nokogiri_spec.version}.gem"
end
  
desc 'uninstall both gems'
task :uninstall do
    sh "sudo gem uninstall #{nokogiri_spec.name} -x"
    sh "sudo gem uninstall nokogiri -x"
    sh "sudo gem uninstall #{rexml_spec.name} -x"
end
  
desc 'reinstall both gems'
task :reinstall => [:uninstall, :install]

desc 'push to rubygems.org'
task :push => [:installtest] do
   sh "gem push pkg/#{rexml_spec.name}-#{rexml_spec.version}.gem"
   sh "gem push pkg/#{nokogiri_spec.name}-#{nokogiri_spec.version}.gem"
end

