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