module Travis::Tools::System

def description(*args)

def description(*args)
  [ full_os, ruby, rubygems, *args.flatten].compact.uniq.join("; ")
end

def full_os

def full_os
  os_name == os_type ? os : "#{os} like #{os_type}"
end

def has?(command)

def has?(command)
  return false unless unix?
  @has ||= {}
  @has.fetch(command) { @has[command] = system "which #{command} 2>/dev/null >/dev/null" }
end

def linux?

def linux?
  RUBY_PLATFORM =~ /linux/i
end

def mac?

def mac?
  RUBY_PLATFORM =~ /darwin/i
end

def os

def os
  os_name ? "#{os_name} #{os_version}".strip : os_type
end

def os_name

def os_name
  @os_name ||= has?(:sw_vers)     && `sw_vers -productName`.chomp
  @os_name ||= has?(:lsb_release) && `lsb_release -i -s`.chomp
end

def os_type

def os_type
  @os_type ||= windows? ? 'Windows' : `uname`.chomp
end

def os_version

def os_version
  @os_version ||= has?(:sw_vers)     && `sw_vers -productVersion`.chomp
  @os_version ||= has?(:lsb_release) && `lsb_release -r -s`.chomp
end

def recent_version?(version, minimum)

def recent_version?(version, minimum)
  version = version.split('.').map { |s| s.to_i }
  minimum = minimum.split('.').map { |s| s.to_i }
  (version <=> minimum) >= 0
end

def ruby

def ruby
  case ruby_engine
  when 'ruby'  then "Ruby #{ruby_version}"
  when 'jruby' then "JRuby #{JRUBY_VERSION} like Ruby #{ruby_version}"
  when 'rbx'   then "Rubinius #{Rubinius.version[/\d\S+/]} like Ruby #{ruby_version}"
  else              "#{ruby_engine} like Ruby #{ruby_version}"
  end
end

def ruby_engine

def ruby_engine
  defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
end

def ruby_version

def ruby_version
  "%s-p%s" % [RUBY_VERSION, RUBY_PATCHLEVEL]
end

def rubygems

def rubygems
  return "no RubyGems" unless defined? Gem
  "RubyGems #{Gem::VERSION}"
end

def running?(app)

def running?(app)
  return false unless unix?
  system "pgrep -u $(whoami) #{app} >/dev/null"
end

def unix?

def unix?
  not windows?
end

def windows?

def windows?
  File::ALT_SEPARATOR == "\\"
end