2010-11-29 23:46:04 +00:00
|
|
|
require 'yaml'
|
|
|
|
require 'fileutils'
|
2011-01-05 22:44:45 +00:00
|
|
|
require 'apache/hash'
|
2010-11-29 23:46:04 +00:00
|
|
|
|
|
|
|
module Apache
|
|
|
|
module Rake
|
|
|
|
module Support
|
|
|
|
def config
|
2011-01-04 21:58:16 +00:00
|
|
|
if !@config
|
2011-01-05 22:44:45 +00:00
|
|
|
@config = YAML.load_file('config.yml').to_sym_keys
|
2011-01-04 21:58:16 +00:00
|
|
|
config_paths!
|
|
|
|
|
|
|
|
class << @config
|
|
|
|
def [](which)
|
|
|
|
if which == :dest_path
|
|
|
|
print "config[:dest_path] is deprecated.".foreground(:red).bright
|
|
|
|
puts " Use config[:destination_path] instead.".foreground(:red)
|
|
|
|
|
|
|
|
self[:destination_path]
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@config
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_paths!
|
2011-01-06 16:17:46 +00:00
|
|
|
[ :source, :destination ].each do |which|
|
2011-01-04 21:58:16 +00:00
|
|
|
begin
|
|
|
|
@config[:"#{which}_path"] = File.expand_path(@config[which])
|
|
|
|
rescue StandardError
|
|
|
|
puts "#{which.to_s.bright} is not defined in the configuration file.".foreground(:red)
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
2010-11-29 23:46:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_environments
|
|
|
|
Dir[File.join(config[:source_path], '**', '*.rb')].collect { |file|
|
|
|
|
File.readlines(file).find_all { |line| line[%r{(if_environment|build_if)}] }.collect { |line| line.scan(%r{:[a-z_]+}) }
|
|
|
|
}.flatten.uniq.sort.collect { |name| name[1..-1] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_default_environment
|
|
|
|
File.read('.environment').strip rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def need_environment
|
|
|
|
puts "You need to specify an environment. Available environments:"
|
|
|
|
puts
|
|
|
|
puts get_environments.collect { |env| "rake apache:create[#{env}]" } * "\n"
|
|
|
|
puts
|
|
|
|
puts "Additionally, you can set a default environment for this server:"
|
|
|
|
puts
|
|
|
|
puts "rake apache:default[#{get_environments.first}]"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|