Upgraded Rails and RSpec
[monkeycharger.git] / vendor / rails / railties / lib / tasks / framework.rake
blob99b61c7d5865a239e351a0130d05f910e4bf7236
1 namespace :rails do
2   namespace :freeze do
3     desc "Lock this application to the current gems (by unpacking them into vendor/rails)"
4     task :gems do
5       deps = %w(actionpack activerecord actionmailer activesupport activeresource)
6       require 'rubygems'
7       Gem.manage_gems
9       rails = (version = ENV['VERSION']) ?
10         Gem.cache.find_name('rails', "= #{version}").first :
11         Gem.cache.find_name('rails').sort_by { |g| g.version }.last
13       version ||= rails.version
15       unless rails
16         puts "No rails gem #{version} is installed.  Do 'gem list rails' to see what you have available."
17         exit
18       end
20       puts "Freezing to the gems for Rails #{rails.version}"
21       rm_rf   "vendor/rails"
22       mkdir_p "vendor/rails"
24       chdir("vendor/rails") do
25         rails.dependencies.select { |g| deps.include? g.name }.each do |g|
26           Gem::GemRunner.new.run(["unpack", "-v", "#{g.version_requirements}", "#{g.name}"])
27           mv(Dir.glob("#{g.name}*").first, g.name)
28         end
30         Gem::GemRunner.new.run(["unpack", "-v", "=#{version}", "rails"])
31         FileUtils.mv(Dir.glob("rails*").first, "railties")
32       end
33     end
35     desc "Lock to latest Edge Rails or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)"
36     task :edge do
37       $verbose = false
38       `svn --version` rescue nil
39       unless !$?.nil? && $?.success?
40         $stderr.puts "ERROR: Must have subversion (svn) available in the PATH to lock this application to Edge Rails"
41         exit 1
42       end
43             
44       rm_rf   "vendor/rails"
45       mkdir_p "vendor/rails"
46       
47       svn_root = "http://dev.rubyonrails.org/svn/rails/"
49       if ENV['TAG']
50         rails_svn = "#{svn_root}/tags/#{ENV['TAG']}"
51         touch "vendor/rails/TAG_#{ENV['TAG']}"
52       else
53         rails_svn = "#{svn_root}/trunk"
55         if ENV['REVISION'].nil?
56           ENV['REVISION'] = /^r(\d+)/.match(%x{svn -qr HEAD log #{svn_root}})[1]
57           puts "REVISION not set. Using HEAD, which is revision #{ENV['REVISION']}."
58         end
60         touch "vendor/rails/REVISION_#{ENV['REVISION']}"
61       end
63       for framework in %w(railties actionpack activerecord actionmailer activesupport activeresource)
64         system "svn export #{rails_svn}/#{framework} vendor/rails/#{framework}" + (ENV['REVISION'] ? " -r #{ENV['REVISION']}" : "")
65       end
66     end
67   end
69   desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems"
70   task :unfreeze do
71     rm_rf "vendor/rails"
72   end
74   desc "Update both configs, scripts and public/javascripts from Rails"
75   task :update => [ "update:scripts", "update:javascripts", "update:configs" ]
77   namespace :update do
78     desc "Add new scripts to the application script/ directory"
79     task :scripts do
80       local_base = "script"
81       edge_base  = "#{File.dirname(__FILE__)}/../../bin"
83       local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
84       edge  = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
85   
86       edge.each do |script|
87         base_name = script[(edge_base.length+1)..-1]
88         next if base_name == "rails"
89         next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
90         if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
91           mkdir_p "#{local_base}/#{File.dirname(base_name)}"
92         end
93         install script, "#{local_base}/#{base_name}", :mode => 0755
94       end
95     end
97     desc "Update your javascripts from your current rails install"
98     task :javascripts do
99       require 'railties_path'  
100       project_dir = RAILS_ROOT + '/public/javascripts/'
101       scripts = Dir[RAILTIES_PATH + '/html/javascripts/*.js']
102       scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exists?(project_dir + 'application.js')
103       FileUtils.cp(scripts, project_dir)
104     end
106     desc "Update config/boot.rb from your current rails install"
107     task :configs do
108       require 'railties_path'  
109       FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb')
110     end
111   end