module License::Compatibility

Constants

VERSION

Public Class Methods

check_license_list(list) click to toggle source
# File lib/license/compatibility.rb, line 63
def self.check_license_list(list)
  result = true
  self.filter_known_licenses(list).permutation(2).to_a.each { |couple|
    intermediate_result = self.forward_compatibility(couple[0], couple[1])
    puts "#{couple[0]} is not forward-compatible with #{couple[1]}" unless intermediate_result
    result &= intermediate_result
  }
  puts "Licenses are compatible" if result
  result
end
check_package_licence_list(list) click to toggle source
# File lib/license/compatibility.rb, line 74
def self.check_package_licence_list(list)
  result = true
  known_licenses = self.filter_known_licenses(list.map { |x| x[1] })
  list.select { |x| known_licenses.include? x[1] }.permutation(2).to_a.each { |couple|
    intermediate_result = self.forward_compatibility(couple[0][1], couple[1][1])
    puts "#{couple[0][0]} (#{couple[0][1]}) is not forward-compatible with #{couple[1][0]} (#{couple[1][1]})" unless intermediate_result
    result &= intermediate_result
  }
  puts "Licenses are compatible" if result
  result
end
filter_known_licenses(list) click to toggle source
# File lib/license/compatibility.rb, line 48
def self.filter_known_licenses(list)
  known = []
  list.each { |license |
    begin
      self.license_type(license)
      unless known.include? license
        known.push(license)
      end
    rescue => e
      STDERR.puts e
    end
  }
  return known
end
forward_compatibility(source_license, derivative_license) click to toggle source
# File lib/license/compatibility.rb, line 10
def self.forward_compatibility(source_license, derivative_license)
  source_type = license_type(source_license)
  derivative_type = license_type(derivative_license)
  case source_type
  when :public_domain
    return true
  when :permissive, :weak_copyleft
    [:public_domain, :permissive, :weak_copyleft, :copyleft, :strong_copyleft, :network_copyleft].include? derivative_type
  when :strong_copyleft
    [:weak_copyleft, :strong_copyleft, :network_copyleft].include? derivative_type
  when :network_copyleft
    [:network_copyleft].include? derivative_type
  else
    raise "Unknown license compatibility: #{source_license} and #{derivative_license}"
  end
end
license_data() click to toggle source
# File lib/license/compatibility.rb, line 27
def self.license_data
  @@license_data ||= JSON.load(File.read(File.expand_path('../licenses.json', __FILE__)))
end
license_type(license) click to toggle source
# File lib/license/compatibility.rb, line 31
def self.license_type(license)
  license = license.delete('+')
  if license_data['public_domain'].include?(license)
    :public_domain
  elsif license_data['permissive'].include?(license)
    :permissive
  elsif license_data['weak_copyleft'].include?(license)
    :weak_copyleft
  elsif license_data['strong_copyleft'].include?(license)
    :strong_copyleft
  elsif license_data['network_copyleft'].include?(license)
    :network_copyleft
  else
    raise "Unknown license type: #{license}"
  end
end