Froze rails gems
[depot.git] / vendor / rails / railties / lib / tasks / framework.rake
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 require 'rubygems/gem_runner'
8
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
12
13 version ||= rails.version
14
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
19
20 puts "Freezing to the gems for Rails #{rails.version}"
21 rm_rf "vendor/rails"
22 mkdir_p "vendor/rails"
23
24 begin
25 chdir("vendor/rails") do
26 rails.dependencies.select { |g| deps.include? g.name }.each do |g|
27 Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s])
28 mv(Dir.glob("#{g.name}*").first, g.name)
29 end
30
31 Gem::GemRunner.new.run(["unpack", "rails", "--version", "=#{version}"])
32 FileUtils.mv(Dir.glob("rails*").first, "railties")
33 end
34 rescue Exception
35 rm_rf "vendor/rails"
36 raise
37 end
38 end
39
40 desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0'
41 task :edge do
42 require 'open-uri'
43 version = ENV["RELEASE"] || "edge"
44 target = "rails_#{version}.zip"
45 commits = "http://github.com/api/v1/yaml/rails/rails/commits/master"
46 url = "http://dev.rubyonrails.org/archives/#{target}"
47
48 chdir 'vendor' do
49 latest_revision = YAML.load(open(commits))["commits"].first["id"]
50
51 puts "Downloading Rails from #{url}"
52 File.open('rails.zip', 'wb') do |dst|
53 open url do |src|
54 while chunk = src.read(4096)
55 dst << chunk
56 end
57 end
58 end
59
60 puts 'Unpacking Rails'
61 rm_rf 'rails'
62 `unzip rails.zip`
63 %w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
64 rm_f goner
65 end
66
67 touch "rails/REVISION_#{latest_revision}"
68 end
69
70 puts 'Updating current scripts, javascripts, and configuration settings'
71 Rake::Task['rails:update'].invoke
72 end
73 end
74
75 desc "Unlock this application from freeze of gems or edge and return to a fluid use of system gems"
76 task :unfreeze do
77 rm_rf "vendor/rails"
78 end
79
80 desc "Update both configs, scripts and public/javascripts from Rails"
81 task :update => [ "update:scripts", "update:javascripts", "update:configs" ]
82
83 namespace :update do
84 desc "Add new scripts to the application script/ directory"
85 task :scripts do
86 local_base = "script"
87 edge_base = "#{File.dirname(__FILE__)}/../../bin"
88
89 local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
90 edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
91
92 edge.each do |script|
93 base_name = script[(edge_base.length+1)..-1]
94 next if base_name == "rails"
95 next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
96 if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
97 mkdir_p "#{local_base}/#{File.dirname(base_name)}"
98 end
99 install script, "#{local_base}/#{base_name}", :mode => 0755
100 end
101 end
102
103 desc "Update your javascripts from your current rails install"
104 task :javascripts do
105 require 'railties_path'
106 project_dir = RAILS_ROOT + '/public/javascripts/'
107 scripts = Dir[RAILTIES_PATH + '/html/javascripts/*.js']
108 scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exist?(project_dir + 'application.js')
109 FileUtils.cp(scripts, project_dir)
110 end
111
112 desc "Update config/boot.rb from your current rails install"
113 task :configs do
114 require 'railties_path'
115 FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb')
116 end
117 end
118 end