~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/railties/lib/tasks/framework.rake

  • Committer: Michael Forrest
  • Date: 2010-10-15 16:28:50 UTC
  • Revision ID: michael.forrest@canonical.com-20101015162850-tj2vchanv0kr0dun
refrozeĀ gems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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", "update:application_controller" ]
 
82
 
 
83
  desc "Applies the template supplied by LOCATION=/path/to/template"
 
84
  task :template do
 
85
    require 'rails_generator/generators/applications/app/template_runner'
 
86
    Rails::TemplateRunner.new(ENV["LOCATION"])
 
87
  end
 
88
 
 
89
  namespace :update do
 
90
    desc "Add new scripts to the application script/ directory"
 
91
    task :scripts do
 
92
      local_base = "script"
 
93
      edge_base  = "#{File.dirname(__FILE__)}/../../bin"
 
94
 
 
95
      local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
 
96
      edge  = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
 
97
  
 
98
      edge.each do |script|
 
99
        base_name = script[(edge_base.length+1)..-1]
 
100
        next if base_name == "rails"
 
101
        next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
 
102
        if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
 
103
          mkdir_p "#{local_base}/#{File.dirname(base_name)}"
 
104
        end
 
105
        install script, "#{local_base}/#{base_name}", :mode => 0755
 
106
      end
 
107
    end
 
108
 
 
109
    desc "Update your javascripts from your current rails install"
 
110
    task :javascripts do
 
111
      require 'railties_path'  
 
112
      project_dir = RAILS_ROOT + '/public/javascripts/'
 
113
      scripts = Dir[RAILTIES_PATH + '/html/javascripts/*.js']
 
114
      scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exist?(project_dir + 'application.js')
 
115
      FileUtils.cp(scripts, project_dir)
 
116
    end
 
117
 
 
118
    desc "Update config/boot.rb from your current rails install"
 
119
    task :configs do
 
120
      require 'railties_path'  
 
121
      FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb')
 
122
    end
 
123
    
 
124
    desc "Rename application.rb to application_controller.rb"
 
125
    task :application_controller do
 
126
      old_style = RAILS_ROOT + '/app/controllers/application.rb'
 
127
      new_style = RAILS_ROOT + '/app/controllers/application_controller.rb'
 
128
      if File.exists?(old_style) && !File.exists?(new_style)
 
129
        FileUtils.mv(old_style, new_style)
 
130
        puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
 
131
      end
 
132
    end
 
133
    
 
134
    desc "Generate dispatcher files in RAILS_ROOT/public"
 
135
    task :generate_dispatchers do
 
136
      require 'railties_path'
 
137
      FileUtils.cp(RAILTIES_PATH + '/dispatches/config.ru', RAILS_ROOT + '/config.ru')
 
138
      FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.fcgi', RAILS_ROOT + '/public/dispatch.fcgi')
 
139
      FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.rb')
 
140
      FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.cgi')
 
141
    end
 
142
  end
 
143
end