Removed Hoe code, dependency.
[merb_radiant.git] / Rakefile
blob3ea6cf42c66babfe7fa9d52c135f9ed99ff847d0
1 require 'rubygems'
2 Gem.clear_paths
3 Gem.path.unshift(File.join(File.dirname(__FILE__), "gems"))
5 require 'rake'
6 require 'rake/rdoctask'
7 require 'rake/testtask'
8 require 'spec/rake/spectask'
9 require 'fileutils'
10 require 'merb-core'
11 require 'rubigen'
12 include FileUtils
14 ##############################################################################
15 # Merb
16 ##############################################################################
18 # Load the basic runtime dependencies; this will include 
19 # any plugins and therefore plugin rake tasks.
20 init_env = ENV['MERB_ENV'] || 'rake'
21 Merb.load_dependencies(:environment => init_env)
22      
23 # Get Merb plugins and dependencies
24 Merb::Plugins.rakefiles.each { |r| require r } 
26 desc "start runner environment"
27 task :merb_env do
28   Merb.start_environment(:environment => init_env, :adapter => 'runner')
29 end
31 ##############################################################################
32 # ADD YOUR CUSTOM TASKS BELOW
33 ##############################################################################
35 unless Rake::Task.task_defined? "radiant:release"
36   Dir["#{MERB_RADIANT_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
37 end
39 class Freezer
40   
41   class << self
43     def components
44       {
45         "core" => "git://github.com/wycats/merb-core.git",
46         "more" => "git://github.com/wycats/merb-more.git",
47         "plugins" => "git://github.com/wycats/merb-plugins.git"
48       }
49     end
51     def framework_dir
52       # Should allow customization of this directory's location?
53       File.join(File.dirname(__FILE__), "framework")
54     end
56     def gitmodules
57       File.join(File.dirname(__FILE__), ".gitmodules")    
58     end
60     def freeze(component, update = false)
61       new(component, update).freeze
62     end
64   end
66   def initialize(component, update)
67     @component = "merb-" + component
68     @update    = update
69   end
70   
71   def freeze
72     # Ensure that required git commands are available
73     %w(git-pull git-submodule).each do |bin|
74       next if in_path?(bin)
75       $stderr.puts "ERROR: #{bin} must be avaible in PATH"
76       exit 1
77     end
79     unless File.directory?(framework_dir)
80       puts "Creating framework directory ..."
81       FileUtils.mkdir_p(framework_dir)
82     end
84     if managed?
85       puts "#{@component} seems to be already managed by git-submodule."
86       if @update
87         puts "Trying to update #{@component} ..."
88         sh "cd #{framework_dir}/#{@component} && git-pull"
89       end
90     else
91       puts "Creating submodule for #{@component} ..."
92       sh "git-submodule --quiet add #{components[@component.gsub("merb-", '')]} #{File.basename(framework_dir)}/#{@component}" 
93       if $?.success?
94         sh("git-submodule init")
95       else
96         # Should this instead be a raise?
97         $stderr.puts("ERROR: unable to create submodule for #{@component}")
98       end
99     end
100   end
102   protected
104   def in_submodule?
105     return false unless File.exists?(gitmodules)
106     File.read(gitmodules) =~ %r![submodule "#{framework_dir}/#{@component}"]!
107   end
109   def managed?
110     File.directory?(File.join(framework_dir, @component)) || in_submodule?
111   end
113   def in_path?(bin)
114     `which #{bin}`
115     !$?.nil? && $?.success?
116   end
120 task :freeze => Freezer.components.keys.map { |component| "freeze:#{component}" }
121 namespace :freeze do
122   Freezer.components.each do |component, git_repository|
123     desc "Freeze #{component} from #{git_repository}"
124     task component do
125       Freezer.freeze(component, ENV["UPDATE"])
126     end
127   end