summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/license/management/repository.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb
index fdff30d..ed2519f 100644
--- a/lib/license/management/repository.rb
+++ b/lib/license/management/repository.rb
@@ -5,6 +5,11 @@ module License
class Repository
include Loggable
include Verifiable
+ KNOWN_SOURCES = [
+ 'licenses.nuget.org',
+ 'opensource.org',
+ 'www.opensource.org',
+ ].freeze
def initialize(
compatibility_path: License::Management.root.join('normalized-licenses.yml'),
@@ -34,15 +39,15 @@ module License
'name' => data['name'],
'url' => data['seeAlso'][-1]
}
- else
- log_info("Could not find license `#{id}` in SPDX")
- nil
end
end
def id_for(license)
ids = compatibility_data['ids']
- ids[license.send(:short_name)] || ids[license.url] || known_sources(license.url)
+ ids[license.send(:short_name)] ||
+ ids[license.url] ||
+ known_sources(license.send(:short_name)) ||
+ known_sources(license.url)
end
# When `license_finder` is unable to determine the license it will use the full
@@ -55,7 +60,7 @@ module License
end
def generate_item_for(license)
- log_info("detected unknown license named `#{license.send(:short_name)}`")
+ log_info("detected unknown license named `#{license.send(:short_name)}`:`#{license.url}`")
name = take_first_line_from(license.name)
{
'id' => name.downcase,
@@ -76,13 +81,14 @@ module License
end
def known_sources(url)
+ return if blank?(url)
return unless url =~ /\A#{::URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/
uri = URI.parse(url)
- return unless ['opensource.org', 'licenses.nuget.org'].include?(uri.host)
-
+ return unless KNOWN_SOURCES.include?(uri.host.downcase)
uri.path.split('/')[-1]
- rescue
+ rescue => error
+ log_info(error)
nil
end
end