2017-01-18 13:31:19 -08:00
|
|
|
# frozen_string_literal: true
|
2017-03-26 17:19:44 -07:00
|
|
|
|
2015-03-07 12:47:24 -05:00
|
|
|
require 'jekyll'
|
2015-03-07 13:38:52 -05:00
|
|
|
require 'json'
|
2017-12-30 15:38:31 -08:00
|
|
|
require 'licensee'
|
2016-01-15 17:40:32 -05:00
|
|
|
require 'open-uri'
|
2015-03-07 12:47:24 -05:00
|
|
|
|
2016-02-08 15:37:19 -05:00
|
|
|
module SpecHelper
|
|
|
|
class << self
|
2020-07-30 11:53:51 -07:00
|
|
|
attr_accessor :config, :licenses, :site, :spdx,
|
|
|
|
:osi_approved_licenses, :fsf_approved_licenses, :od_approved_licenses
|
2016-02-08 15:37:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-07 12:47:24 -05:00
|
|
|
def config_file
|
2016-02-08 15:37:19 -05:00
|
|
|
File.expand_path './_config.yml', source
|
2015-03-07 12:47:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
2016-02-08 15:37:19 -05:00
|
|
|
File.expand_path('../', File.dirname(__FILE__))
|
2015-03-07 12:47:24 -05:00
|
|
|
end
|
|
|
|
|
2016-01-29 12:44:28 -05:00
|
|
|
def licenses_path
|
2016-02-08 15:37:19 -05:00
|
|
|
File.expand_path '_licenses', source
|
2016-01-29 12:44:28 -05:00
|
|
|
end
|
|
|
|
|
2015-03-07 12:47:24 -05:00
|
|
|
def config
|
2016-02-08 15:37:19 -05:00
|
|
|
SpecHelper.config ||= begin
|
|
|
|
config = Jekyll::Configuration.new.read_config_file config_file
|
|
|
|
config = Jekyll::Utils.deep_merge_hashes(config, source: source)
|
|
|
|
Jekyll::Utils.deep_merge_hashes(Jekyll::Configuration::DEFAULTS, config)
|
|
|
|
end
|
2015-03-07 12:47:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def licenses
|
2021-03-29 09:30:10 -07:00
|
|
|
SpecHelper.licenses ||= site.collections['licenses'].docs.map do |license|
|
2021-03-29 09:32:31 -07:00
|
|
|
spdx_lcase = File.basename(license.basename, '.txt')
|
|
|
|
license.to_liquid.merge('spdx-lcase' => spdx_lcase)
|
2016-01-18 17:05:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-14 10:35:44 -07:00
|
|
|
def shown_licenses
|
2017-03-26 17:19:44 -07:00
|
|
|
licenses.reject { |l| l['hidden'] }
|
2016-06-14 10:35:44 -07:00
|
|
|
end
|
|
|
|
|
2015-03-07 12:47:24 -05:00
|
|
|
def site
|
2016-02-08 15:37:19 -05:00
|
|
|
SpecHelper.site ||= begin
|
2015-03-07 12:47:24 -05:00
|
|
|
site = Jekyll::Site.new(config)
|
|
|
|
site.reset
|
|
|
|
site.read
|
|
|
|
site
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rules
|
2016-02-08 15:37:19 -05:00
|
|
|
site.data['rules']
|
2015-03-07 12:47:24 -05:00
|
|
|
end
|
|
|
|
|
2015-08-22 15:25:16 -04:00
|
|
|
def fields
|
2016-02-08 15:37:19 -05:00
|
|
|
site.data['fields']
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def meta
|
2016-02-08 15:37:19 -05:00
|
|
|
site.data['meta']
|
2015-08-22 15:25:16 -04:00
|
|
|
end
|
|
|
|
|
2015-03-07 12:47:24 -05:00
|
|
|
def rule?(tag, group)
|
2016-02-08 15:37:19 -05:00
|
|
|
rules[group].any? { |r| r['tag'] == tag }
|
2015-03-07 12:47:24 -05:00
|
|
|
end
|
2015-03-07 13:38:52 -05:00
|
|
|
|
|
|
|
def spdx_list
|
2017-12-29 14:30:08 -08:00
|
|
|
SpecHelper.spdx ||= begin
|
|
|
|
url = 'https://spdx.org/licenses/licenses.json'
|
2018-03-14 18:45:10 -07:00
|
|
|
list = JSON.parse(OpenURI.open_uri(url).read)['licenses']
|
2017-12-29 14:30:08 -08:00
|
|
|
list.each_with_object({}) do |values, memo|
|
|
|
|
memo[values['licenseId']] = values
|
|
|
|
end
|
|
|
|
end
|
2015-03-07 13:38:52 -05:00
|
|
|
end
|
|
|
|
|
2016-01-15 17:40:32 -05:00
|
|
|
def spdx_ids
|
2016-05-25 08:53:23 -05:00
|
|
|
spdx_list.map { |name, _properties| name }
|
2016-01-15 17:40:32 -05:00
|
|
|
end
|
|
|
|
|
2015-03-07 13:38:52 -05:00
|
|
|
def find_spdx(license)
|
2018-01-03 11:08:38 -08:00
|
|
|
spdx_list.find { |name, _properties| name.casecmp(license).zero? }
|
2015-03-07 13:38:52 -05:00
|
|
|
end
|
2016-01-15 17:40:32 -05:00
|
|
|
|
2016-01-15 18:01:07 -05:00
|
|
|
def osi_approved_licenses
|
2016-02-08 15:37:19 -05:00
|
|
|
SpecHelper.osi_approved_licenses ||= begin
|
2016-01-15 18:01:07 -05:00
|
|
|
licenses = {}
|
2017-12-29 14:30:08 -08:00
|
|
|
list = spdx_list.select { |_id, meta| meta['isOsiApproved'] }
|
2016-01-15 18:01:07 -05:00
|
|
|
list.each do |id, meta|
|
2016-02-08 15:37:19 -05:00
|
|
|
licenses[id.downcase] = meta['name']
|
2016-01-15 18:01:07 -05:00
|
|
|
end
|
|
|
|
licenses
|
|
|
|
end
|
2016-01-15 17:40:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def fsf_approved_licenses
|
2016-02-08 15:37:19 -05:00
|
|
|
SpecHelper.fsf_approved_licenses ||= begin
|
2018-01-03 11:17:19 -08:00
|
|
|
url = 'https://wking.github.io/fsf-api/licenses-full.json'
|
2018-03-14 18:45:10 -07:00
|
|
|
object = JSON.parse(OpenURI.open_uri(url).read)
|
2016-01-15 17:40:32 -05:00
|
|
|
licenses = {}
|
2018-01-05 16:18:59 -08:00
|
|
|
object['licenses'].each_value do |meta|
|
2020-07-23 12:28:53 -07:00
|
|
|
next unless meta.dig('identifiers', 'spdx') && (meta.include? 'tags') && (meta['tags'].include? 'libre')
|
2018-09-24 15:39:55 -07:00
|
|
|
|
2018-01-03 11:17:19 -08:00
|
|
|
meta['identifiers']['spdx'].each do |identifier|
|
|
|
|
licenses[identifier.downcase] = meta['name']
|
|
|
|
end
|
2016-01-18 15:32:17 -05:00
|
|
|
end
|
2016-01-15 17:40:32 -05:00
|
|
|
licenses
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def od_approved_licenses
|
2016-02-08 15:37:19 -05:00
|
|
|
SpecHelper.od_approved_licenses ||= begin
|
2018-05-22 13:39:44 -07:00
|
|
|
url = 'https://licenses.opendefinition.org/licenses/groups/od.json'
|
2018-03-14 18:45:10 -07:00
|
|
|
data = OpenURI.open_uri(url).read
|
2016-01-15 17:40:32 -05:00
|
|
|
data = JSON.parse(data)
|
|
|
|
licenses = {}
|
|
|
|
data.each do |id, meta|
|
2016-02-08 15:37:19 -05:00
|
|
|
licenses[id.downcase] = meta['title']
|
2016-01-15 17:40:32 -05:00
|
|
|
end
|
|
|
|
licenses
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-15 18:01:07 -05:00
|
|
|
def approved_licenses
|
|
|
|
(osi_approved_licenses.keys + fsf_approved_licenses.keys + od_approved_licenses.keys).flatten.uniq.sort
|
2016-01-15 17:40:32 -05:00
|
|
|
end
|
2017-12-30 15:38:31 -08:00
|
|
|
|
|
|
|
module Licensee
|
|
|
|
class License
|
|
|
|
class << self
|
|
|
|
def license_dir
|
|
|
|
dir = ::File.dirname(__FILE__)
|
|
|
|
::File.expand_path '../_licenses', dir
|
|
|
|
end
|
2021-03-29 09:30:10 -07:00
|
|
|
|
2021-02-26 13:47:53 -08:00
|
|
|
def spdx_dir
|
|
|
|
::File.expand_path '../license-list-XML/src', __dir__
|
|
|
|
end
|
2017-12-30 15:38:31 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|