Skip to content

Commit

Permalink
rake cleanup, better versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Black committed Nov 11, 2012
1 parent 21d0c98 commit 63a1324
Show file tree
Hide file tree
Showing 44 changed files with 305 additions and 2,502 deletions.
10 changes: 4 additions & 6 deletions .gitignore
@@ -1,7 +1,4 @@
html docs
pkg
doc
ydoc
.yardoc .yardoc
*.gem *.gem
nbproject nbproject
Expand All @@ -11,7 +8,7 @@ nbproject
ext/cbson/Makefile ext/cbson/Makefile
lib/mongo_ext/Makefile lib/mongo_ext/Makefile
lib/bson_ext lib/bson_ext
benchmark tasks/benchmark/exp_series_suite_*.js
*~ *~
*#* *#*
*.class *.class
Expand All @@ -25,4 +22,5 @@ test/tools/data/
Gemfile.lock Gemfile.lock
.idea/* .idea/*
tmp tmp

data
.DS_Store
2 changes: 1 addition & 1 deletion .yardopts
@@ -1 +1 @@
lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e ./yard/yard_ext.rb -p yard/templates lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e ./tasks/yard/yard_ext.rb -p tasks/yard/templates
38 changes: 18 additions & 20 deletions Gemfile
@@ -1,29 +1,27 @@
source :rubygems source :rubygems


# Generic gem 'json'
gem "bundler" gem 'rake', :require => ['rake/testtask']
gem "rake"
gem "json"


# Testing group :deployment do
group :test do gem 'git'
gem "test-unit" gem 'yard'
gem "mocha", ">=0.12.4" #0.12.3 is broken for us gem 'rdoc'
gem "shoulda" gem 'rake-compiler', :require => ['rake/extensiontask', 'rake/javaextensiontask']
gem "rake-compiler" gem 'version_bumper'
gem "sfl" gem 'rvm'
gem 'redcarpet' unless RUBY_PLATFORM =~ /java/
end end


# Deployment group :testing do
group :deploy do gem 'test-unit'
gem "git" gem 'mocha', '>=0.12.4', :require => ['mocha/setup'] #0.12.3 is broken for us
gem "yard" gem 'shoulda'
gem "redcarpet", "2.2.0" unless RUBY_PLATFORM =~ /java/ gem 'sfl'
end end


# Java
platforms :jruby do platforms :jruby do
gem "bouncy-castle-java" gem 'bouncy-castle-java'
gem "jruby-launcher" gem 'jruby-launcher'
gem "jruby-openssl" gem 'jruby-openssl'
end end
File renamed without changes.
289 changes: 8 additions & 281 deletions Rakefile
@@ -1,286 +1,13 @@
# -*- mode: ruby; -*- # -*- mode: ruby; -*-
require 'rake'
require 'fileutils'
require 'rake/testtask'
require 'rake/extensiontask'
require 'rake/javaextensiontask'


begin require 'rubygems'
require 'git'
require 'devkit'
rescue LoadError
end

ENV['TEST_MODE'] = 'TRUE'

Rake::ExtensionTask.new('cbson') do |ext|
ext.lib_dir = "lib/bson_ext"
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_set/*_test.rb'] - ['test/replica_set/count_test.rb']
t.libs << 'test'
end

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

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

Rake::TestTask.new(:functional) do |t|
t.test_files = FileList['test/functional/*_test.rb'] - [
"test/functional/db_api_test.rb",
"test/functional/pool_test.rb",
"test/functional/threading_test.rb",
"test/functional/grid_io_test.rb",
"test/functional/grid_test.rb"
]
t.libs << 'test'
end

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

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

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

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

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


Rake::TestTask.new(:config) do |t| begin
t.test_files = FileList['test/tools/mongo_config_test.rb'] require 'bundler'
t.libs << 'test' Bundler.require(:default, :deployment, :testing)
end # Bundler::GemHelper.install_tasks

rescue LoadError
task :drop_databases => :path do |t| raise '[FAIL] Bundler not found! Install it with `gem install bundler; bundle install`.'
puts "Dropping test databases..."
require 'mongo'
client = Mongo::Client.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Client::DEFAULT_PORT, :safe => true)
client.database_names.each do |name|
client.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 :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

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

def gem_list(version)
files = []
files << "bson-#{version}.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_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 end


task :default => :list Dir.glob(File.join("tasks", "**", "*.rake")).sort.each { |rake| load File.expand_path(rake) }

task :list do
system 'rake -T'
end
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
1.7.0

0 comments on commit 63a1324

Please sign in to comment.