summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-08-19 14:55:16 -0600
committermo khan <mo.khan@gmail.com>2019-08-19 14:55:16 -0600
commit97b0618b6a8953343a97036862df3ed977167d72 (patch)
tree673e697351f4c547fae55dd84acac6602fbfe091
parent1e0553590435977e5f27bcd4b715b4fbca7b595c (diff)
Apply changes from https://gitlab.com/gitlab-org/security-products/license-management/merge_requests/50
-rw-r--r--lib/license/management.rb3
-rw-r--r--lib/license/management/json_report.rb41
-rw-r--r--lib/license/management/repository.rb7
-rw-r--r--normalized-licenses.yml (renamed from licenses.yml)2
4 files changed, 31 insertions, 22 deletions
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/normalized-licenses.yml
index 8ed24b2..e26df4f 100644
--- a/licenses.yml
+++ b/normalized-licenses.yml
@@ -25,7 +25,7 @@ ids:
SimplifiedBSD: BSD-2-Clause
http://www.apache.org/licenses/LICENSE-2.0: Apache-2.0
unknown: unknown
-items:
+licenses:
GPL-3.0:
name: GPL 3.0
url: https://www.gnu.org/licenses/gpl-3.0.txt