Module: FileUtils

Extended by:
FFI::Library
Defined in:
lib/buildr/core/util.rb,
lib/buildr/core/util.rb,
lib/buildr/core/util.rb

Overview

Fix for BUILDR-292. JRuby fails to rename a file on different devices this monkey-patch wont be needed when JRUBY-3381 gets resolved.

Instance Method Summary collapse

Instance Method Details

#__mv_nativeObject

:nodoc:



355
# File 'lib/buildr/core/util.rb', line 355

alias_method :__mv_native, :mv

#sh(*cmd, &block) ⇒ Object

code “borrowed” directly from Rake



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/buildr/core/util.rb', line 452

def sh(*cmd, &block)
  options = (Hash === cmd.last) ? cmd.pop : {}
  unless block_given?
    show_command = cmd.join(" ")
    show_command = show_command[0,42] + "..."

    block = lambda { |ok, status|
      ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
    }
  end
  if RakeFileUtils.verbose_flag == :default
    options[:verbose] = false
  else
    options[:verbose] ||= RakeFileUtils.verbose_flag
  end
  options[:noop]    ||= RakeFileUtils.nowrite_flag
  rake_check_options options, :noop, :verbose
  rake_output_message cmd.join(" ") if options[:verbose]
  unless options[:noop]
    if Buildr::Util.win_os?
      # Ruby uses forward slashes regardless of platform,
      # unfortunately cd c:/some/path fails on Windows
      pwd = Dir.pwd.gsub(%r{/}, '\\')
      cd = "cd /d \"#{pwd}\" && "
    else
      cd = "cd '#{Dir.pwd}' && "
    end
    args = if cmd.size > 1 then cmd[1..cmd.size] else [] end

    res = if Buildr::Util.win_os? && cmd.size == 1
      __native_system__("#{cd} call #{cmd.first}")
    else
      arg_str = args.map { |a| "'#{a}'" }
      __native_system__(cd + cmd.first + ' ' + arg_str.join(' '))
    end
    status = Buildr::ProcessStatus.new(0, res == 0, res)    # KLUDGE
    block.call(res == 0, status)
  end
end