pvalena / rpms / ruby

Forked from rpms/ruby 2 years ago
Clone
637f46
#!/usr/bin/ruby
637f46
637f46
require 'rubygems/package'
637f46
637f46
module RubyGemsReq
637f46
  module Helpers
637f46
    # Keep only '!=' requirements.
637f46
    def self.conflicts(requirements)
637f46
      conflicts = requirements.select {|r| r.first == '!='}
637f46
    end
637f46
637f46
    # Converts Gem::Requirement into array of requirements strings compatible
637f46
    # with RPM .spec file.
637f46
    def self.requirement_versions_to_rpm(requirement)
637f46
      self.conflicts(requirement.requirements).map do |op, version|
637f46
        version == Gem::Version.new(0) ? "" : "= #{version}"
637f46
      end
637f46
    end
637f46
  end
637f46
637f46
  # Report conflicting gem dependencies including their version.
637f46
  def self.gem_depenencies(specification)
637f46
    specification.runtime_dependencies.each do |dependency|
637f46
      conflict_strings = Helpers::requirement_versions_to_rpm(dependency.requirement).map do |requirement|
637f46
        requirement_string = "rubygem(#{dependency.name}) #{requirement}"
637f46
      end
637f46
      if conflict_strings.length > 0
637f46
        conflict_string = conflict_strings.join(' with ')
637f46
        conflict_string.prepend('(').concat(')') if conflict_strings.length > 1
637f46
        puts conflict_string
637f46
      end
637f46
    end
637f46
  end
637f46
637f46
  # Reports all conflicts specified by all provided .gemspec files.
637f46
  def self.conflicts
637f46
    while filename = gets
637f46
      filename.strip!
637f46
      begin
637f46
        specification = Gem::Specification.load filename
637f46
637f46
        gem_depenencies(specification)
637f46
      rescue => e
637f46
        # Ignore all errors.
637f46
      end
637f46
    end
637f46
  end
637f46
end
637f46
637f46
if __FILE__ == $0
637f46
  RubyGemsReq::conflicts
637f46
end