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
|
|
|
|
attr_accessor :config, :licenses, :site, :spdx
|
|
|
|
attr_accessor :osi_approved_licenses, :fsf_approved_licenses, :od_approved_licenses
|
|
|
|
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
|
2016-02-08 21:37:19 +01:00
|
|
|
SpecHelper.licenses ||= begin
|
|
|
|
site.collections['licenses'].docs.map do |license|
|
2016-06-01 17:36:56 +02:00
|
|
|
spdx_lcase = File.basename(license.basename, '.txt')
|
|
|
|
license.to_liquid.merge('spdx-lcase' => spdx_lcase)
|
2016-01-20 16:37:44 +01:00
|
|
|
end
|
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|
|
2018-01-03 20:17:19 +01:00
|
|
|
next unless (meta.include? 'identifiers') && (meta['identifiers'].include? 'spdx') && (meta.include? 'tags') && (meta['tags'].include? 'libre')
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|