licensee 8.9.2 → 9.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/bin/licensee +42 -28
- data/lib/licensee.rb +14 -28
- data/lib/licensee/content_helper.rb +38 -12
- data/lib/licensee/license.rb +22 -9
- data/lib/licensee/matchers.rb +14 -0
- data/lib/licensee/matchers/cabal.rb +16 -0
- data/lib/licensee/matchers/{copyright_matcher.rb → copyright.rb} +1 -5
- data/lib/licensee/matchers/{cran_matcher.rb → cran.rb} +1 -1
- data/lib/licensee/matchers/{dice_matcher.rb → dice.rb} +1 -7
- data/lib/licensee/matchers/{dist_zilla_matcher.rb → dist_zilla.rb} +1 -1
- data/lib/licensee/matchers/{exact_matcher.rb → exact.rb} +2 -1
- data/lib/licensee/matchers/gemspec.rb +24 -0
- data/lib/licensee/matchers/{package_matcher.rb → matcher.rb} +5 -3
- data/lib/licensee/matchers/{npm_bower_matcher.rb → npm_bower.rb} +2 -2
- data/lib/licensee/matchers/package.rb +22 -0
- data/lib/licensee/project_files.rb +8 -0
- data/lib/licensee/project_files/license_file.rb +22 -4
- data/lib/licensee/project_files/package_manager_file.rb +37 -0
- data/lib/licensee/project_files/project_file.rb +65 -0
- data/lib/licensee/project_files/{readme.rb → readme_file.rb} +2 -2
- data/lib/licensee/projects.rb +7 -0
- data/lib/licensee/projects/fs_project.rb +64 -27
- data/lib/licensee/projects/git_project.rb +49 -43
- data/lib/licensee/projects/project.rb +149 -0
- data/lib/licensee/version.rb +1 -1
- data/spec/bin_spec.rb +9 -2
- data/spec/fixtures/crlf-license/LICENSE +674 -0
- data/spec/fixtures/fcpl-modified-mpl/LICENSE +193 -193
- data/spec/fixtures/ipsum.txt +19 -0
- data/spec/fixtures/license-in-parent-folder/LICENSE.txt +21 -0
- data/spec/fixtures/license-in-parent-folder/license-folder/LICENSE.txt +21 -0
- data/spec/fixtures/multiple-license-files/LICENSE +362 -0
- data/spec/fixtures/multiple-license-files/LICENSE.txt +21 -0
- data/spec/integration_spec.rb +57 -22
- data/spec/licensee/content_helper_spec.rb +33 -9
- data/spec/licensee/license_spec.rb +8 -1
- data/spec/licensee/matchers/cabal_matcher_spec.rb +45 -0
- data/spec/licensee/matchers/copyright_matcher_spec.rb +1 -1
- data/spec/licensee/matchers/cran_matcher_spec.rb +11 -2
- data/spec/licensee/matchers/dice_matcher_spec.rb +1 -2
- data/spec/licensee/matchers/dist_zilla_matcher_spec.rb +11 -2
- data/spec/licensee/matchers/exact_matcher_spec.rb +1 -1
- data/spec/licensee/matchers/gemspec_matcher_spec.rb +19 -1
- data/spec/licensee/matchers/npm_bower_matcher_spec.rb +23 -6
- data/spec/licensee/matchers/package_matcher_spec.rb +31 -2
- data/spec/licensee/project_files/license_file_spec.rb +62 -6
- data/spec/licensee/project_files/package_info_spec.rb +10 -1
- data/spec/{project_file_spec.rb → licensee/project_files/project_file_spec.rb} +14 -1
- data/spec/licensee/project_files/readme_spec.rb +1 -1
- data/spec/licensee/project_spec.rb +134 -9
- data/spec/licensee_spec.rb +4 -3
- data/spec/spec_helper.rb +12 -23
- data/spec/vendored_license_spec.rb +16 -13
- metadata +29 -17
- data/lib/licensee/matchers/gemspec_matcher.rb +0 -19
- data/lib/licensee/project.rb +0 -87
- data/lib/licensee/project_file.rb +0 -39
- data/lib/licensee/project_files/package_info.rb +0 -31
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module Licensee
|
|
2
|
-
module Matchers
|
|
3
|
-
class Gemspec < Package
|
|
4
|
-
# We definitely don't want to be evaling arbitrary Gemspec files
|
|
5
|
-
# While not 100% accurate, use some lenient regex to try to grep the
|
|
6
|
-
# license declaration from the Gemspec as a string, if any
|
|
7
|
-
LICENSE_REGEX = /
|
|
8
|
-
^\s*[a-z0-9_]+\.license\s*\=\s*[\'\"]([a-z\-0-9\.]+)[\'\"]\s*$
|
|
9
|
-
/ix
|
|
10
|
-
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
def license_property
|
|
14
|
-
match = @file.content.match LICENSE_REGEX
|
|
15
|
-
match[1].downcase if match && match[1]
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
data/lib/licensee/project.rb
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
require 'rugged'
|
|
2
|
-
|
|
3
|
-
module Licensee
|
|
4
|
-
class Project
|
|
5
|
-
attr_reader :detect_readme, :detect_packages
|
|
6
|
-
alias detect_readme? detect_readme
|
|
7
|
-
alias detect_packages? detect_packages
|
|
8
|
-
|
|
9
|
-
def initialize(detect_packages: false, detect_readme: false)
|
|
10
|
-
@detect_packages = detect_packages
|
|
11
|
-
@detect_readme = detect_readme
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Returns the matching License instance if a license can be detected
|
|
15
|
-
def license
|
|
16
|
-
@license ||= matched_file && matched_file.license
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def matched_file
|
|
20
|
-
@matched_file ||= begin
|
|
21
|
-
[license_file, readme, package_file].compact.find(&:license)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def license_file
|
|
26
|
-
return @license_file if defined? @license_file
|
|
27
|
-
@license_file = begin
|
|
28
|
-
license_file = license_from_file { |n| LicenseFile.name_score(n) }
|
|
29
|
-
return license_file unless license_file && license_file.license
|
|
30
|
-
|
|
31
|
-
# Special case LGPL, which actually lives in LICENSE.lesser, per the
|
|
32
|
-
# license instructions. See https://git.io/viwyK
|
|
33
|
-
lesser = if license_file.license.gpl?
|
|
34
|
-
license_from_file { |file| LicenseFile.lesser_gpl_score(file) }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
lesser || license_file
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def readme_file
|
|
42
|
-
return unless detect_readme?
|
|
43
|
-
return @readme if defined? @readme
|
|
44
|
-
@readme = begin
|
|
45
|
-
content, name = find_file { |n| Readme.name_score(n) }
|
|
46
|
-
content = Readme.license_content(content)
|
|
47
|
-
Readme.new(content, name) if content && name
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
alias readme readme_file
|
|
51
|
-
|
|
52
|
-
def package_file
|
|
53
|
-
return unless detect_packages?
|
|
54
|
-
return @package_file if defined? @package_file
|
|
55
|
-
@package_file = begin
|
|
56
|
-
content, name = find_file { |n| PackageInfo.name_score(n) }
|
|
57
|
-
PackageInfo.new(content, name) if content && name
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
# Given a block, passes each filename to that block, and expects a numeric
|
|
64
|
-
# score in response. Returns an array of all files with a score > 0,
|
|
65
|
-
# sorted by file score descending
|
|
66
|
-
def find_files
|
|
67
|
-
return [] if files.empty? || files.nil?
|
|
68
|
-
found = files.each { |file| file[:score] = yield(file[:name]) }
|
|
69
|
-
found.select! { |file| file[:score] > 0 }
|
|
70
|
-
found.sort { |a, b| b[:score] <=> a[:score] }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Given a block, passes each filename to that block, and expects a numeric
|
|
74
|
-
# score in response. Returns a hash representing the top scoring file
|
|
75
|
-
# or nil, if no file scored > 0
|
|
76
|
-
def find_file(&block)
|
|
77
|
-
return if files.empty? || files.nil?
|
|
78
|
-
file = find_files(&block).first
|
|
79
|
-
[load_file(file), file[:name]] if file
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def license_from_file(&block)
|
|
83
|
-
content, name = find_file(&block)
|
|
84
|
-
LicenseFile.new(content, name) if content && name
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
module Licensee
|
|
2
|
-
class Project
|
|
3
|
-
class File
|
|
4
|
-
attr_reader :content, :filename
|
|
5
|
-
|
|
6
|
-
ENCODING = Encoding::UTF_8
|
|
7
|
-
ENCODING_OPTIONS = {
|
|
8
|
-
invalid: :replace,
|
|
9
|
-
undef: :replace,
|
|
10
|
-
replace: ''
|
|
11
|
-
}.freeze
|
|
12
|
-
|
|
13
|
-
def initialize(content, filename = nil)
|
|
14
|
-
@content = content
|
|
15
|
-
@content.force_encoding(ENCODING)
|
|
16
|
-
unless @content.valid_encoding?
|
|
17
|
-
@content.encode!(ENCODING, ENCODING_OPTIONS)
|
|
18
|
-
end
|
|
19
|
-
@filename = filename
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def matcher
|
|
23
|
-
@matcher ||= possible_matchers.map { |m| m.new(self) }.find(&:match)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Returns the percent confident with the match
|
|
27
|
-
def confidence
|
|
28
|
-
matcher && matcher.confidence
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def license
|
|
32
|
-
matcher && matcher.match
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
alias match license
|
|
36
|
-
alias path filename
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module Licensee
|
|
2
|
-
class Project
|
|
3
|
-
class PackageInfo < Licensee::Project::File
|
|
4
|
-
def possible_matchers
|
|
5
|
-
case ::File.extname(filename)
|
|
6
|
-
when '.gemspec'
|
|
7
|
-
[Matchers::Gemspec]
|
|
8
|
-
when '.json'
|
|
9
|
-
[Matchers::NpmBower]
|
|
10
|
-
else
|
|
11
|
-
if filename == 'DESCRIPTION' && content.match(/^Package:/)
|
|
12
|
-
[Matchers::Cran]
|
|
13
|
-
elsif filename == 'dist.ini'
|
|
14
|
-
[Matchers::DistZilla]
|
|
15
|
-
else
|
|
16
|
-
[]
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.name_score(filename)
|
|
22
|
-
return 1.0 if ::File.extname(filename) == '.gemspec'
|
|
23
|
-
return 1.0 if filename == 'package.json'
|
|
24
|
-
return 0.8 if filename == 'dist.ini'
|
|
25
|
-
return 0.9 if filename == 'DESCRIPTION'
|
|
26
|
-
return 0.75 if filename == 'bower.json'
|
|
27
|
-
0.0
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|