Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/abstract_adapter.rb @ 1464:261b3d9a4903 redmine-2.4
Update to Redmine 2.4 branch rev 12663
author | Chris Cannam |
---|---|
date | Tue, 14 Jan 2014 14:37:42 +0000 |
parents | 433d4f72a19b |
children | 51364c0cd58f e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1296:038ba2d95de8 | 1464:261b3d9a4903 |
---|---|
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. |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
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 require 'redmine/scm/adapters' | |
20 | |
21 if RUBY_VERSION < '1.9' | |
22 require 'iconv' | |
23 end | |
19 | 24 |
20 module Redmine | 25 module Redmine |
21 module Scm | 26 module Scm |
22 module Adapters | 27 module Adapters |
23 class CommandFailed < StandardError #:nodoc: | |
24 end | |
25 | |
26 class AbstractAdapter #:nodoc: | 28 class AbstractAdapter #:nodoc: |
27 | 29 |
28 # raised if scm command exited with error, e.g. unknown revision. | 30 # raised if scm command exited with error, e.g. unknown revision. |
29 class ScmCommandAborted < CommandFailed; end | 31 class ScmCommandAborted < CommandFailed; end |
30 | 32 |
212 | 214 |
213 def self.logger | 215 def self.logger |
214 Rails.logger | 216 Rails.logger |
215 end | 217 end |
216 | 218 |
219 # Path to the file where scm stderr output is logged | |
220 # Returns nil if the log file is not writable | |
221 def self.stderr_log_file | |
222 if @stderr_log_file.nil? | |
223 writable = false | |
224 path = Redmine::Configuration['scm_stderr_log_file'].presence | |
225 path ||= Rails.root.join("log/#{Rails.env}.scm.stderr.log").to_s | |
226 if File.exists?(path) | |
227 if File.file?(path) && File.writable?(path) | |
228 writable = true | |
229 else | |
230 logger.warn("SCM log file (#{path}) is not writable") | |
231 end | |
232 else | |
233 begin | |
234 File.open(path, "w") {} | |
235 writable = true | |
236 rescue => e | |
237 logger.warn("SCM log file (#{path}) cannot be created: #{e.message}") | |
238 end | |
239 end | |
240 @stderr_log_file = writable ? path : false | |
241 end | |
242 @stderr_log_file || nil | |
243 end | |
244 | |
217 def self.shellout(cmd, options = {}, &block) | 245 def self.shellout(cmd, options = {}, &block) |
218 if logger && logger.debug? | 246 if logger && logger.debug? |
219 logger.debug "Shelling out: #{strip_credential(cmd)}" | 247 logger.debug "Shelling out: #{strip_credential(cmd)}" |
220 end | 248 # Capture stderr in a log file |
221 if Rails.env == 'development' | 249 if stderr_log_file |
222 # Capture stderr when running in dev environment | 250 cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}" |
223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}" | 251 end |
224 end | 252 end |
225 begin | 253 begin |
226 mode = "r+" | 254 mode = "r+" |
227 IO.popen(cmd, mode) do |io| | 255 IO.popen(cmd, mode) do |io| |
228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) | 256 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) |