Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 325 lines (275 sloc) 8.171 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
# -*- mode: ruby; -*-
if RUBY_VERSION < '1.9.0'
  require 'rubygems'
  require 'rubygems/specification'
end

require 'fileutils'
require 'rake'
require 'rake/testtask'
require 'rake/extensiontask'
require 'rake/javaextensiontask'

begin
  require 'git'
  require 'devkit'
  require 'ci/reporter/rake/test_unit'
  rescue LoadError
end

ENV['TEST_MODE'] = 'TRUE'

Rake::ExtensionTask.new('cbson') do |ext|
  ext.lib_dir = "lib/bson_ext"
end

#Rake::JavaExtensionTask.new('jbson') do |ext| # not yet functional
# ext.ext_dir = 'ext/src/org/jbson'
#end

desc "Compiles and tests MongoDB Ruby driver w/ C extensions."
task :c do
  Rake::Task['compile:cbson'].invoke
  Rake::Task['test:c'].invoke
end

task :java do
  Rake::Task['build:java'].invoke
  Rake::Task['test:ruby'].invoke
end

namespace :build do
  desc "Build the java extensions."
  task :java do
    puts "Building Java extensions..."
    java_dir = File.join(File.dirname(__FILE__), 'ext', 'java')
    jar_dir = File.join(java_dir, 'jar')

    jruby_jar = File.join(jar_dir, 'jruby.jar')
    mongo_jar = File.join(jar_dir, 'mongo-2.6.5.jar')

    src_base = File.join(java_dir, 'src')

    system("javac -Xlint:deprecation -Xlint:unchecked -classpath #{jruby_jar}:#{mongo_jar} #{File.join(src_base, 'org', 'jbson', '*.java')}")
    system("cd #{src_base} && jar cf #{File.join(jar_dir, 'jbson.jar')} #{File.join('.', 'org', 'jbson', '*.class')}")
  end
end

desc "Test the MongoDB Ruby driver."
task :test do
  puts "\nTo test the driver with the C-extensions:\nrake test:c\n\n"
  puts "To test the pure ruby driver: \nrake test:ruby\n\n"
end

task :path do
    $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
end

namespace :test do

  desc "Test the driver with the C extension enabled."
  task :c => :path do
    ENV['C_EXT'] = 'TRUE'
    if ENV['TEST']
      Rake::Task['test:functional'].invoke
    else
      Rake::Task['test:unit'].invoke
      Rake::Task['test:functional'].invoke
      Rake::Task['test:bson'].invoke
      Rake::Task['test:pooled_threading'].invoke
      Rake::Task['test:drop_databases'].invoke
    end
    ENV['C_EXT'] = nil
  end

  desc "Test the driver using pure ruby (no C extension)"
  task :ruby => :path do
    ENV['C_EXT'] = nil
    if ENV['TEST']
      Rake::Task['test:functional'].invoke
    else
      Rake::Task['test:unit'].invoke
      Rake::Task['test:functional'].invoke
      Rake::Task['test:bson'].invoke
      Rake::Task['test:pooled_threading'].invoke
      Rake::Task['test:drop_databases'].invoke
    end
  end

  desc "Run the replica set test suite"
  Rake::TestTask.new(:rs) do |t|
    t.test_files = FileList['test/replica_sets/*_test.rb']
    t.ruby_opts << '-w'
  end

  desc "Run the replica set test suite"
  Rake::TestTask.new(:rs_no_threads) do |t|
    t.test_files = FileList['test/replica_sets/*_test.rb'] - ["test/replica_sets/refresh_with_threads_test.rb"]
    t.ruby_opts << '-w'
  end

  desc "Run the sharded cluster test suite"
  Rake::TestTask.new(:sc) do |t|
    t.test_files = FileList['test/sharded_cluster/*_test.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:unit) do |t|
    t.test_files = FileList['test/unit/*_test.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:functional) do |t|
    t.test_files = FileList['test/*_test.rb'] - ["test/db_api_test.rb"]
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:pooled_threading) do |t|
    t.test_files = FileList['test/threading/*_test.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:auto_reconnect) do |t|
    t.test_files = FileList['test/auxillary/autoreconnect_test.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:authentication) do |t|
    t.test_files = FileList['test/auxillary/authentication_test.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:new_features) do |t|
    t.test_files = FileList['test/auxillary/1.4_features.rb']
    t.ruby_opts << '-w'
  end

  Rake::TestTask.new(:bson) do |t|
    t.test_files = FileList['test/bson/*_test.rb']
    t.ruby_opts << '-w'
  end

  task :drop_databases => :path do |t|
    puts "Dropping test databases..."
    require 'mongo'
    con = Mongo::Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
      ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT)
    con.database_names.each do |name|
      con.drop_database(name) if name =~ /^ruby-test/
    end
  end
end

desc "Generate RDOC documentation"
task :rdoc do
  version = eval(File.read("mongo.gemspec")).version
  out = File.join('html', version.to_s)
  FileUtils.rm_rf('html')
  system "rdoc --main README.md --op #{out} --inline-source --quiet README.md `find lib -name '*.rb'`"
end

desc "Generate YARD documentation"
task :ydoc do
  require './lib/mongo/version.rb'
  out = File.join('ydoc', Mongo::VERSION)
  FileUtils.rm_rf('ydoc')
  system "yardoc -o #{out} --title MongoRuby-#{Mongo::VERSION}"
end

namespace :jenkins do
  task :ci_reporter do
    begin
      require 'ci/reporter/rake/test_unit'
    rescue LoadError
      warn "Warning: Unable to load ci_reporter gem."
    end
  end

  namespace :test do
    task :ruby do
      Rake::Task['test:ruby'].invoke
    end

    task :c do
      Rake::Task['gem:install_extensions'].invoke
      Rake::Task['test:c'].invoke
    end
  end
end

namespace :gem do
  desc "Install the gem locally"
  task :install do
    `gem build bson.gemspec`
    `gem install --no-rdoc --no-ri bson-*.gem`

    `gem build mongo.gemspec`
    `gem install --no-rdoc --no-ri mongo-*.gem`

    `rm mongo-*.gem`
    `rm bson-*.gem`
  end
  
  desc "Uninstall the optional c extensions"
  task :uninstall_extensions do
    `gem uninstall bson_ext`
  end

  desc "Install the optional c extensions"
  task :install_extensions do
    `gem build bson_ext.gemspec`
    `gem install --no-rdoc --no-ri bson_ext-*.gem`
    `rm bson_ext-*.gem`
  end
end

namespace :ci do
  namespace :test do
    task :c => :path do
      Rake::Task['gem:install'].invoke
      Rake::Task['gem:install_extensions'].invoke
      Rake::Task['test:c'].invoke
    end
  end
end

# Deployment
VERSION_FILES = %w(lib/bson/version.rb lib/mongo/version.rb ext/cbson/version.h)
GEMSPECS = %w(bson.gemspec bson.java.gemspec bson_ext.gemspec mongo.gemspec)

def gem_list(version)
  files = []
  files << "bson-#{version}.gem"
  files << "bson-#{version}-java.gem"
  files << "bson_ext-#{version}.gem"
  files << "mongo-#{version}.gem"
  return files
end

def check_version(version)
  if !(version =~ /(\d).(\d).(\d)(.rc(\d))?/)
    raise "Must specify a valid version (e.g., x.y.z)"
  end
end

def current_version
  f = File.open("lib/mongo/version.rb")
  str = f.read
  str =~ /VERSION\s+=\s+"([.\drc]+)"$/
  return $1
end

def change_version(new_version)
  version = current_version
  puts "Changing version from #{version} to #{new_version}"
  VERSION_FILES.each do |filename|
    f = File.open(filename)
    str = f.read
    f.close
    str.gsub!("\"#{version}\"", "\"#{new_version}\"")
    File.open(filename, 'w') do |f|
      f.write(str)
    end
  end
end

namespace :deploy do
  desc "Change version to new release"
  task :change_version, [:version] do |t, args|
    check_version(args[:version])
    change_version(args[:version])
  end

  desc "Add version files, commit, tag release"
  task :git_prepare do |t, args|
    g = Git.open(Dir.getwd())
    version = current_version
    to_commit = VERSION_FILES << 'docs/HISTORY.md'
    g.add(to_commit)
    g.commit "RELEASE #{version}"
    g.add_tag("#{version}")
  end

  desc "Push release to github"
  task :git_push do
    g = Git.open(Dir.getwd())
    g.push
    g.push(g.tag(current_version))
  end

  desc "Build all gems"
  task :gem_build do
    `rm *.gem`
    `gem build mongo.gemspec`
    `gem build bson.gemspec`
    `gem build bson.java.gemspec`
    `gem build bson_ext.gemspec`
    puts `ls *.gem`
  end

  desc "Push all gems to RubyGems"
  task :gem_push do
    gem_list(current_version).each do |gem_name|
      puts "Push #{gem_name} to RubyGems? (y/N)"
      if STDIN.gets.chomp == 'y'
        system "gem push #{gem_name}"
      end
    end
  end
end

task :default => :list

task :list do
  system 'rake -T'
end
Something went wrong with that request. Please try again.