diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2019-10-19 13:33:10 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2019-10-19 13:33:10 +0000 |
commit | 773807871733c7917f297a11ab89ce1deebc8453 (patch) | |
tree | ce2b4d29e78e6fa4a779a4f189f95ca88564719a /lib/redmine | |
parent | cb2d4068e8294d9ca31578b2f07b130751b98471 (diff) | |
download | redmine-773807871733c7917f297a11ab89ce1deebc8453.tar.gz redmine-773807871733c7917f297a11ab89ce1deebc8453.zip |
code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in lib/redmine/scm/adapters/abstract_adapter.rb
git-svn-id: http://svn.redmine.org/redmine/trunk@18777 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/scm/adapters/abstract_adapter.rb | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index c4496142a..67a1f17a3 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -203,10 +203,6 @@ module Redmine self.class.shellout(cmd, options, &block) end - def self.logger - Rails.logger - end - # Path to the file where scm stderr output is logged # Returns nil if the log file is not writable def self.stderr_log_file @@ -234,32 +230,39 @@ module Redmine end private_class_method :stderr_log_file - def self.shellout(cmd, options = {}, &block) - if logger && logger.debug? - logger.debug "Shelling out: #{strip_credential(cmd)}" - # Capture stderr in a log file - if stderr_log_file - cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}" - end + # Singleton class method is public + class << self + def logger + Rails.logger end - begin - mode = "r+" - IO.popen(cmd, mode) do |io| - io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) - io.close_write unless options[:write_stdin] - block.call(io) if block_given? + + def shellout(cmd, options = {}, &block) + if logger && logger.debug? + logger.debug "Shelling out: #{strip_credential(cmd)}" + # Capture stderr in a log file + if stderr_log_file + cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}" + end + end + begin + mode = "r+" + IO.popen(cmd, mode) do |io| + io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding) + io.close_write unless options[:write_stdin] + block.call(io) if block_given? + end + rescue => e + msg = strip_credential(e.message) + # The command failed, log it and re-raise + logmsg = "SCM command failed, " + logmsg += "make sure that your SCM command (e.g. svn) is " + logmsg += "in PATH (#{ENV['PATH']})\n" + logmsg += "You can configure your scm commands in config/configuration.yml.\n" + logmsg += "#{strip_credential(cmd)}\n" + logmsg += "with: #{msg}" + logger.error(logmsg) + raise CommandFailed.new(msg) end - rescue => e - msg = strip_credential(e.message) - # The command failed, log it and re-raise - logmsg = "SCM command failed, " - logmsg += "make sure that your SCM command (e.g. svn) is " - logmsg += "in PATH (#{ENV['PATH']})\n" - logmsg += "You can configure your scm commands in config/configuration.yml.\n" - logmsg += "#{strip_credential(cmd)}\n" - logmsg += "with: #{msg}" - logger.error(logmsg) - raise CommandFailed.new(msg) end end |