3 require 'rake/testtask'
4 require 'rake/rdoctask'
5 require 'rake/packagetask'
6 require 'rake/gempackagetask'
7 require 'rake/contrib/rubyforgepublisher'
8 require File.join(File.dirname(__FILE__), 'lib', 'active_record', 'version')
10 PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
11 PKG_NAME = 'activerecord'
12 PKG_VERSION = ActiveRecord::VERSION::STRING + PKG_BUILD
13 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15 RELEASE_NAME = "REL #{PKG_VERSION}"
17 RUBY_FORGE_PROJECT = "activerecord"
18 RUBY_FORGE_USER = "webster132"
21 "lib/**/*", "test/**/*", "examples/**/*", "doc/**/*", "[A-Z]*", "install.rb", "Rakefile"
22 ].exclude(/\bCVS\b|~$/)
25 desc 'Run mysql, sqlite, and postgresql tests by default'
26 task :default => :test
28 desc 'Run mysql, sqlite, and postgresql tests'
29 task :test => %w(test_mysql test_sqlite test_sqlite3 test_postgresql)
31 for adapter in %w( mysql postgresql sqlite sqlite3 firebird db2 oracle sybase openbase frontbase )
32 Rake::TestTask.new("test_#{adapter}") { |t|
33 t.libs << "test" << "test/connections/native_#{adapter}"
34 adapter_short = adapter == 'db2' ? adapter : adapter[/^[a-z]+/]
35 t.pattern = "test/**/*_test{,_#{adapter_short}}.rb"
40 task :test => "test_#{adapter}"
44 SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))
47 desc 'Build the MySQL test databases'
48 task :build_databases do
49 %x( mysqladmin create activerecord_unittest )
50 %x( mysqladmin create activerecord_unittest2 )
51 %x( mysql -e "grant all on activerecord_unittest.* to rails@localhost" )
52 %x( mysql -e "grant all on activerecord_unittest2.* to rails@localhost" )
55 desc 'Drop the MySQL test databases'
56 task :drop_databases do
57 %x( mysqladmin -f drop activerecord_unittest )
58 %x( mysqladmin -f drop activerecord_unittest2 )
61 desc 'Rebuild the MySQL test databases'
62 task :rebuild_databases => [:drop_databases, :build_databases]
65 task :build_mysql_databases => 'mysql:build_databases'
66 task :drop_mysql_databases => 'mysql:drop_databases'
67 task :rebuild_mysql_databases => 'mysql:rebuild_databases'
70 namespace :postgresql do
71 desc 'Build the PostgreSQL test databases'
72 task :build_databases do
73 %x( createdb -U postgres activerecord_unittest )
74 %x( createdb -U postgres activerecord_unittest2 )
75 %x( psql activerecord_unittest -f #{File.join(SCHEMA_PATH, 'postgresql.sql')} postgres )
76 %x( psql activerecord_unittest2 -f #{File.join(SCHEMA_PATH, 'postgresql2.sql')} postgres )
79 desc 'Drop the PostgreSQL test databases'
80 task :drop_databases do
81 %x( dropdb -U postgres activerecord_unittest )
82 %x( dropdb -U postgres activerecord_unittest2 )
85 desc 'Rebuild the PostgreSQL test databases'
86 task :rebuild_databases => [:drop_databases, :build_databases]
89 task :build_postgresql_databases => 'postgresql:build_databases'
90 task :drop_postgresql_databases => 'postgresql:drop_databases'
91 task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
94 namespace :frontbase do
95 desc 'Build the FrontBase test databases'
96 task :build_databases => :rebuild_frontbase_databases
98 desc 'Rebuild the FrontBase test databases'
99 task :rebuild_databases do
100 build_frontbase_database = Proc.new do |db_name, sql_definition_file|
102 STOP DATABASE #{db_name};
103 DELETE DATABASE #{db_name};
104 CREATE DATABASE #{db_name};
106 CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM;
110 CREATE SCHEMA RAILS AUTHORIZATION RAILS;
113 SET SESSION AUTHORIZATION RAILS;
114 SCRIPT '#{sql_definition_file}';
121 create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_PATH, 'frontbase.sql')]
122 create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_PATH, 'frontbase2.sql')]
123 execute_frontbase_sql = Proc.new do |sql|
125 /Library/FrontBase/bin/sql92 <<-SQL
130 execute_frontbase_sql[create_activerecord_unittest]
131 execute_frontbase_sql[create_activerecord_unittest2]
135 task :build_frontbase_databases => 'frontbase:build_databases'
136 task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
139 # Generate the RDoc documentation
141 Rake::RDocTask.new { |rdoc|
142 rdoc.rdoc_dir = 'doc'
143 rdoc.title = "Active Record -- Object-relation mapping put on rails"
144 rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
145 rdoc.options << '--charset' << 'utf-8'
146 rdoc.template = "#{ENV['template']}.rb" if ENV['template']
147 rdoc.rdoc_files.include('README', 'RUNNING_UNIT_TESTS', 'CHANGELOG')
148 rdoc.rdoc_files.include('lib/**/*.rb')
149 rdoc.rdoc_files.exclude('lib/active_record/vendor/*')
150 rdoc.rdoc_files.include('dev-utils/*.rb')
153 # Enhance rdoc task to copy referenced images also
155 FileUtils.mkdir_p "doc/files/examples/"
156 FileUtils.copy "examples/associations.png", "doc/files/examples/associations.png"
160 # Create compressed packages
162 dist_dirs = [ "lib", "test", "examples" ]
164 spec = Gem::Specification.new do |s|
166 s.version = PKG_VERSION
167 s.summary = "Implements the ActiveRecord pattern for ORM."
168 s.description = %q{Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties database tables and classes together for business objects, like Customer or Subscription, that can find, save, and destroy themselves without resorting to manual SQL.}
170 s.files = [ "Rakefile", "install.rb", "README", "RUNNING_UNIT_TESTS", "CHANGELOG" ]
171 dist_dirs.each do |dir|
172 s.files = s.files + Dir.glob( "#{dir}/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
175 s.add_dependency('activesupport', '= 1.99.0' + PKG_BUILD)
177 s.files.delete "test/fixtures/fixture_database.sqlite"
178 s.files.delete "test/fixtures/fixture_database_2.sqlite"
179 s.files.delete "test/fixtures/fixture_database.sqlite3"
180 s.files.delete "test/fixtures/fixture_database_2.sqlite3"
181 s.require_path = 'lib'
182 s.autorequire = 'active_record'
185 s.extra_rdoc_files = %w( README )
186 s.rdoc_options.concat ['--main', 'README']
188 s.author = "David Heinemeier Hansson"
189 s.email = "david@loudthinking.com"
190 s.homepage = "http://www.rubyonrails.org"
191 s.rubyforge_project = "activerecord"
194 Rake::GemPackageTask.new(spec) do |p|
201 lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
203 for file_name in FileList["lib/active_record/**/*.rb"]
204 next if file_name =~ /vendor/
205 f = File.open(file_name)
209 next if line =~ /^\s*$/
210 next if line =~ /^\s*#/
213 puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
216 total_codelines += codelines
218 lines, codelines = 0, 0
221 puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
225 # Publishing ------------------------------------------------------
227 desc "Publish the beta gem"
228 task :pgem => [:package] do
229 Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
230 `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
233 desc "Publish the API documentation"
234 task :pdoc => [:rdoc] do
235 Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.org", "public_html/ar", "doc").upload
238 desc "Publish the release files to RubyForge."
239 task :release => [ :package ] do
242 packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
244 rubyforge = RubyForge.new
246 rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)