comparison lib/redmine/scm/adapters/abstract_adapter.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents bb32da3bea34 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require 'cgi' 18 require 'cgi'
19 19
20 if RUBY_VERSION < '1.9'
21 require 'iconv'
22 end
23
20 module Redmine 24 module Redmine
21 module Scm 25 module Scm
22 module Adapters 26 module Adapters
23 class CommandFailed < StandardError #:nodoc: 27 class CommandFailed < StandardError #:nodoc:
24 end 28 end
212 216
213 def self.logger 217 def self.logger
214 Rails.logger 218 Rails.logger
215 end 219 end
216 220
221 # Path to the file where scm stderr output is logged
222 # Returns nil if the log file is not writable
223 def self.stderr_log_file
224 if @stderr_log_file.nil?
225 writable = false
226 path = Redmine::Configuration['scm_stderr_log_file'].presence
227 path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s
228 if File.exists?(path)
229 if File.file?(path) && File.writable?(path)
230 writable = true
231 else
232 logger.warn("SCM log file (#{path}) is not writable")
233 end
234 else
235 begin
236 File.open(path, "w") {}
237 writable = true
238 rescue => e
239 logger.warn("SCM log file (#{path}) cannot be created: #{e.message}")
240 end
241 end
242 @stderr_log_file = writable ? path : false
243 end
244 @stderr_log_file || nil
245 end
246
217 def self.shellout(cmd, options = {}, &block) 247 def self.shellout(cmd, options = {}, &block)
218 if logger && logger.debug? 248 if logger && logger.debug?
219 logger.debug "Shelling out: #{strip_credential(cmd)}" 249 logger.debug "Shelling out: #{strip_credential(cmd)}"
220 end 250 # Capture stderr in a log file
221 if Rails.env == 'development' 251 if stderr_log_file
222 # Capture stderr when running in dev environment 252 cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}" 253 end
224 end 254 end
225 begin 255 begin
226 mode = "r+" 256 mode = "r+"
227 IO.popen(cmd, mode) do |io| 257 IO.popen(cmd, mode) do |io|
228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) 258 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)