diff lib/redmine/configuration.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 051f544170fe
children 433d4f72a19b
line wrap: on
line diff
--- a/lib/redmine/configuration.rb	Fri Feb 24 18:36:29 2012 +0000
+++ b/lib/redmine/configuration.rb	Fri Feb 24 19:09:32 2012 +0000
@@ -5,42 +5,42 @@
 # modify it under the terms of the GNU General Public License
 # as published by the Free Software Foundation; either version 2
 # of the License, or (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 module Redmine
   module Configuration
-    
+
     # Configuration default values
     @defaults = {
       'email_delivery' => nil
     }
-    
+
     @config = nil
-    
+
     class << self
       # Loads the Redmine configuration file
       # Valid options:
       # * <tt>:file</tt>: the configuration file to load (default: config/configuration.yml)
-      # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env) 
+      # * <tt>:env</tt>: the environment to load the configuration for (default: Rails.env)
       def load(options={})
         filename = options[:file] || File.join(Rails.root, 'config', 'configuration.yml')
         env = options[:env] || Rails.env
-        
+
         @config = @defaults.dup
-        
+
         load_deprecated_email_configuration(env)
         if File.file?(filename)
           @config.merge!(load_from_yaml(filename, env))
         end
-        
+
         # Compatibility mode for those who copy email.yml over configuration.yml
         %w(delivery_method smtp_settings sendmail_settings).each do |key|
           if value = @config.delete(key)
@@ -48,7 +48,7 @@
             @config['email_delivery'][key] = value
           end
         end
-        
+
         if @config['email_delivery']
           ActionMailer::Base.perform_deliveries = true
           @config['email_delivery'].each do |k, v|
@@ -56,16 +56,16 @@
             ActionMailer::Base.send("#{k}=", v)
           end
         end
-          
+
         @config
       end
-      
+
       # Returns a configuration setting
       def [](name)
         load unless @config
         @config[name]
       end
-      
+
       # Yields a block with the specified hash configuration settings
       def with(settings)
         settings.stringify_keys!
@@ -75,11 +75,17 @@
         yield if block_given?
         @config.merge! was
       end
-      
+
       private
-      
+
       def load_from_yaml(filename, env)
-        yaml = YAML::load_file(filename)
+        yaml = nil
+        begin
+          yaml = YAML::load_file(filename)
+        rescue ArgumentError
+          $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded."
+          exit 1
+        end
         conf = {}
         if yaml.is_a?(Hash)
           if yaml['default']
@@ -89,12 +95,12 @@
             conf.merge!(yaml[env])
           end
         else
-          $stderr.puts "#{filename} is not a valid Redmine configuration file"
+          $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid Redmine configuration file."
           exit 1
         end
         conf
       end
-      
+
       def load_deprecated_email_configuration(env)
         deprecated_email_conf = File.join(Rails.root, 'config', 'email.yml')
         if File.file?(deprecated_email_conf)