From 97b0618b6a8953343a97036862df3ed977167d72 Mon Sep 17 00:00:00 2001 From: mo khan Date: Mon, 19 Aug 2019 14:55:16 -0600 Subject: Apply changes from https://gitlab.com/gitlab-org/security-products/license-management/merge_requests/50 --- lib/license/management.rb | 3 ++ lib/license/management/json_report.rb | 41 ++++++++++-------- lib/license/management/repository.rb | 7 ++- licenses.yml | 82 ----------------------------------- normalized-licenses.yml | 82 +++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 103 deletions(-) delete mode 100644 licenses.yml create mode 100644 normalized-licenses.yml diff --git a/lib/license/management.rb b/lib/license/management.rb index 3b41843..2fdb6b5 100644 --- a/lib/license/management.rb +++ b/lib/license/management.rb @@ -11,6 +11,9 @@ require 'license/management/versions/v1' require 'license/management/json_report' require 'license/management/version' +# This applies a monkey patch to the JsonReport found in the `license_finder` gem. +LicenseFinder::JsonReport.prepend(License::Management::JsonReport) + module License module Management def self.root diff --git a/lib/license/management/json_report.rb b/lib/license/management/json_report.rb index 19a44c4..fde30ef 100644 --- a/lib/license/management/json_report.rb +++ b/lib/license/management/json_report.rb @@ -1,28 +1,31 @@ # frozen_string_literal: true -# This is a monkey patch of the JsonReport found in `license_finder` -module LicenseFinder - class JsonReport < CsvReport - DEFAULT_VERSION = '1' - VERSIONS = { - nil => ::License::Management::Versions::V1, - '' => ::License::Management::Versions::V1, - '1' => ::License::Management::Versions::V1, - '1.0' => ::License::Management::Versions::V1 - }.freeze +module License + module Management + module JsonReport + DEFAULT_VERSION = '1' + VERSIONS = { + nil => ::License::Management::Versions::V1, + '' => ::License::Management::Versions::V1, + '1' => ::License::Management::Versions::V1, + '1.0' => ::License::Management::Versions::V1 + }.freeze - def to_s - JSON.pretty_generate(version_for(report_version).to_h) + "\n" - end + # This method overrides the method defined in `License::Management::JsonReport` to + # allow us to generate a custom json report. + def to_s + JSON.pretty_generate(version_for(report_version).to_h) + "\n" + end - private + private - def report_version - ENV.fetch('LM_REPORT_VERSION', DEFAULT_VERSION) - end + def report_version + ENV.fetch('LM_REPORT_VERSION', DEFAULT_VERSION) + end - def version_for(version) - VERSIONS.fetch(version.to_s).new(dependencies) + def version_for(version) + VERSIONS.fetch(version.to_s).new(dependencies) + end end end end diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb index 707d9f0..2eee1b6 100644 --- a/lib/license/management/repository.rb +++ b/lib/license/management/repository.rb @@ -7,14 +7,14 @@ module License include Verifiable def initialize( - compatibility_path: License::Management.root.join('licenses.yml') + compatibility_path: License::Management.root.join('normalized-licenses.yml') ) @compatibility_data = YAML.safe_load(IO.read(compatibility_path)) end def item_for(license) id = id_for(license) - item = id ? compatibility_data['items'][id] : nil + item = id ? compatibility_data['licenses'][id] : nil item ? { 'id' => id }.merge(item) : generate_item_for(license) end @@ -27,6 +27,9 @@ module License ids[license.send(:short_name)] || ids[license.url] end + # When `license_finder` is unable to determine the license it will use the full + # content of the file as the name of the license. This method shrinks that name + # down to just take the first line of the file. def take_first_line_from(content) return '' if blank?(content) diff --git a/licenses.yml b/licenses.yml deleted file mode 100644 index 8ed24b2..0000000 --- a/licenses.yml +++ /dev/null @@ -1,82 +0,0 @@ ---- -ids: - ASL, version 2: Apache-2.0 - Apache1_1: Apache-1.1 - Apache2: Apache-2.0 - Apache 2.0: Apache-2.0 - BSD: BSD-4-Clause - CC01: CC0-1.0 - EPL1: EPL-1.0 - GPLv2: GPL-2.0 - GPLv3: GPL-3.0 - ISC: ISC - LGPL 2.1: LGPL-2.1 - LGPL, version 2.1: LGPL-2.1 - LGPL2_1: LGPL-2.1 - LGPL: LGPL-3.0-only - MIT: MIT - MPL 1.1: MPL-1.1 - MPL1_1: MPL-1.1 - MPL2: MPL-2.0 - New BSD License: BSD-3-Clause - NewBSD: BSD-3-Clause - Python: Python-2.0 - Ruby: Ruby - SimplifiedBSD: BSD-2-Clause - http://www.apache.org/licenses/LICENSE-2.0: Apache-2.0 - unknown: unknown -items: - GPL-3.0: - name: GPL 3.0 - url: https://www.gnu.org/licenses/gpl-3.0.txt - BSD-2-Clause: - name: Simplified BSD - url: https://opensource.org/licenses/bsd-license - ISC: - name: ISC - url: https://en.wikipedia.org/wiki/ISC_license - Apache-1.1: - name: Apache 1.1 - url: https://www.apache.org/licenses/LICENSE-1.1.txt - MPL-2.0: - name: Mozilla Public License 2.0 - url: https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt - LGPL-3.0-only: - name: LGPL - url: https://www.gnu.org/licenses/lgpl.txt - CC0-1.0: - name: CC0 1.0 - url: https://creativecommons.org/publicdomain/zero/1.0/ - unknown: - name: unknown - url: '' - GPL-2.0: - name: GPL 2.0 - url: https://www.gnu.org/licenses/gpl-2.0.txt - EPL-1.0: - name: EPL 1.0 - url: https://www.eclipse.org/legal/epl-v10.html - Python-2.0: - name: Python Software Foundation License - url: https://hg.python.org/cpython/raw-file/89ce323357db/LICENSE - BSD-3-Clause: - name: New BSD License - url: https://opensource.org/licenses/BSD-3-Clause - MIT: - name: MIT - url: https://opensource.org/licenses/mit-license - LGPL-2.1: - name: LGPL 2.1 - url: https://opensource.org/licenses/LGPL-2.1 - Ruby: - name: Ruby - url: https://www.ruby-lang.org/en/about/license.txt - Apache-2.0: - name: Apache 2.0 - url: https://www.apache.org/licenses/LICENSE-2.0.txt - MPL-1.1: - name: MPL 1.1 - url: https://www.mozilla.org/en-US/MPL/1.1/ - BSD-4-Clause: - name: BSD - url: https://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29 diff --git a/normalized-licenses.yml b/normalized-licenses.yml new file mode 100644 index 0000000..e26df4f --- /dev/null +++ b/normalized-licenses.yml @@ -0,0 +1,82 @@ +--- +ids: + ASL, version 2: Apache-2.0 + Apache1_1: Apache-1.1 + Apache2: Apache-2.0 + Apache 2.0: Apache-2.0 + BSD: BSD-4-Clause + CC01: CC0-1.0 + EPL1: EPL-1.0 + GPLv2: GPL-2.0 + GPLv3: GPL-3.0 + ISC: ISC + LGPL 2.1: LGPL-2.1 + LGPL, version 2.1: LGPL-2.1 + LGPL2_1: LGPL-2.1 + LGPL: LGPL-3.0-only + MIT: MIT + MPL 1.1: MPL-1.1 + MPL1_1: MPL-1.1 + MPL2: MPL-2.0 + New BSD License: BSD-3-Clause + NewBSD: BSD-3-Clause + Python: Python-2.0 + Ruby: Ruby + SimplifiedBSD: BSD-2-Clause + http://www.apache.org/licenses/LICENSE-2.0: Apache-2.0 + unknown: unknown +licenses: + GPL-3.0: + name: GPL 3.0 + url: https://www.gnu.org/licenses/gpl-3.0.txt + BSD-2-Clause: + name: Simplified BSD + url: https://opensource.org/licenses/bsd-license + ISC: + name: ISC + url: https://en.wikipedia.org/wiki/ISC_license + Apache-1.1: + name: Apache 1.1 + url: https://www.apache.org/licenses/LICENSE-1.1.txt + MPL-2.0: + name: Mozilla Public License 2.0 + url: https://www.mozilla.org/media/MPL/2.0/index.815ca599c9df.txt + LGPL-3.0-only: + name: LGPL + url: https://www.gnu.org/licenses/lgpl.txt + CC0-1.0: + name: CC0 1.0 + url: https://creativecommons.org/publicdomain/zero/1.0/ + unknown: + name: unknown + url: '' + GPL-2.0: + name: GPL 2.0 + url: https://www.gnu.org/licenses/gpl-2.0.txt + EPL-1.0: + name: EPL 1.0 + url: https://www.eclipse.org/legal/epl-v10.html + Python-2.0: + name: Python Software Foundation License + url: https://hg.python.org/cpython/raw-file/89ce323357db/LICENSE + BSD-3-Clause: + name: New BSD License + url: https://opensource.org/licenses/BSD-3-Clause + MIT: + name: MIT + url: https://opensource.org/licenses/mit-license + LGPL-2.1: + name: LGPL 2.1 + url: https://opensource.org/licenses/LGPL-2.1 + Ruby: + name: Ruby + url: https://www.ruby-lang.org/en/about/license.txt + Apache-2.0: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.txt + MPL-1.1: + name: MPL 1.1 + url: https://www.mozilla.org/en-US/MPL/1.1/ + BSD-4-Clause: + name: BSD + url: https://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29 -- cgit v1.2.3