summaryrefslogtreecommitdiff
path: root/lib/license
diff options
context:
space:
mode:
Diffstat (limited to 'lib/license')
-rw-r--r--lib/license/management/repository.rb34
-rw-r--r--lib/license/management/version.rb2
2 files changed, 28 insertions, 8 deletions
diff --git a/lib/license/management/repository.rb b/lib/license/management/repository.rb
index 0c428dd..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'),
@@ -25,6 +30,8 @@ module License
attr_reader :spdx_data, :compatibility_data
def spdx_data_for(id)
+ return if blank?(id)
+
data = spdx_data[id]
if data
{
@@ -32,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]
+ 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
@@ -53,10 +60,11 @@ 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' => 'unknown',
- 'name' => take_first_line_from(license.name),
+ 'id' => name.downcase,
+ 'name' => name,
'url' => present?(license.url) ? license.url : ''
}
end
@@ -71,6 +79,18 @@ module License
memo
end
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 KNOWN_SOURCES.include?(uri.host.downcase)
+ uri.path.split('/')[-1]
+ rescue => error
+ log_info(error)
+ nil
+ end
end
end
end
diff --git a/lib/license/management/version.rb b/lib/license/management/version.rb
index b61aa01..8161098 100644
--- a/lib/license/management/version.rb
+++ b/lib/license/management/version.rb
@@ -2,6 +2,6 @@
module License
module Management
- VERSION = '1.7.2'
+ VERSION = '1.7.4'
end
end