licensee 4.4.2 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/licensee +4 -2
- data/lib/licensee.rb +1 -0
- data/lib/licensee/filesystem_repository.rb +38 -0
- data/lib/licensee/license.rb +1 -1
- data/lib/licensee/project.rb +10 -1
- data/lib/licensee/version.rb +1 -1
- data/test/functions.rb +2 -21
- data/test/test_licensee_project.rb +56 -41
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d6862fe6acd66d17a577ac52357cb55352c355
|
4
|
+
data.tar.gz: 1e52b8216cd0443e86bf2f6b4bdc67d3a12c6b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4afadc876117dca8dae492065fd0145086dafb195f50dd0314e42299f9d4345ab4fc124fce52b89812553fb2cc082037e2ce03807a9cb074c080eb6af5ba8fa6
|
7
|
+
data.tar.gz: f0028b11795d26f8c23664ee7e010fc7c57eeead50b29c77dd2086dd8f5ee63da05a1459c564751d704e6da7b1fd3f79b753b18bff956691e077d2c7a2c5063a
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Licensee automates the process of reading `LICENSE` files and compares their con
|
|
18
18
|
|
19
19
|
2. If the license is an exact match to a known license. Licenses like GPL don't have a copyright notice that needs to be changed in the license itself, so if we strip away whitespace, we might get lucky, and direct string comparison in Ruby is cheap.
|
20
20
|
|
21
|
-
3. If 90% of the lines match a known license. We use Git's internal change calculation method. To
|
21
|
+
3. If 90% of the lines match a known license. We use Git's internal change calculation method. To calculate diffs, Git hashes each line of both files, and compares the hashes to tell the percent changed. This method is fast, but is done on a line-by-line basis, so if the license is wrapped differently, or has extra words inserted, it's not going to match the license.
|
22
22
|
|
23
23
|
4. If we still can't match the license, we use a fancy math thing called the [Levenshtein distance algorithm](https://en.wikipedia.org/wiki/Levenshtein_distance), which while very slow, is really good at calculating the similarity between two strings. By calculating the percent changed from the known license to the license file, you can tell, e.g., that a given license is 90% similar to the MIT license, that 10% likely representing the copyright line being properly adapted to the project.
|
24
24
|
|
data/bin/licensee
CHANGED
data/lib/licensee.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "licensee/license"
|
|
8
8
|
require_relative "licensee/licenses"
|
9
9
|
require_relative "licensee/license_file"
|
10
10
|
require_relative "licensee/project"
|
11
|
+
require_relative "licensee/filesystem_repository"
|
11
12
|
require_relative "licensee/matcher"
|
12
13
|
require_relative "licensee/matchers/exact_matcher"
|
13
14
|
require_relative "licensee/matchers/copyright_matcher"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Licensee
|
2
|
+
class FilesystemRepository
|
3
|
+
def initialize(path)
|
4
|
+
@path = path
|
5
|
+
end
|
6
|
+
|
7
|
+
def last_commit() self end
|
8
|
+
|
9
|
+
def tree
|
10
|
+
return to_enum(__method__) unless block_given?
|
11
|
+
Dir.entries(@path).each do |name|
|
12
|
+
filename = File.join @path, name
|
13
|
+
next if File.directory? filename
|
14
|
+
yield(:name => name, :type => :blob, :oid => filename)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def lookup(filename)
|
19
|
+
Blob.new File.read(filename)
|
20
|
+
end
|
21
|
+
|
22
|
+
Blob = Struct.new(:content) do
|
23
|
+
def size
|
24
|
+
content.size
|
25
|
+
end
|
26
|
+
|
27
|
+
def similarity(other)
|
28
|
+
self.hashsig ? Rugged::Blob::HashSignature.compare(self.hashsig, other) : 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def hashsig(options = 0)
|
32
|
+
@hashsig ||= Rugged::Blob::HashSignature.new(content, options)
|
33
|
+
rescue Rugged::InvalidError
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/licensee/license.rb
CHANGED
data/lib/licensee/project.rb
CHANGED
@@ -10,6 +10,7 @@ class Licensee
|
|
10
10
|
license.md
|
11
11
|
unlicense
|
12
12
|
copying
|
13
|
+
copyright
|
13
14
|
]
|
14
15
|
|
15
16
|
# Initializes a new project
|
@@ -20,7 +21,15 @@ class Licensee
|
|
20
21
|
if path_or_repo.kind_of? Rugged::Repository
|
21
22
|
@repository = path_or_repo
|
22
23
|
else
|
23
|
-
|
24
|
+
begin
|
25
|
+
@repository = Rugged::Repository.new(path_or_repo)
|
26
|
+
rescue Rugged::RepositoryError
|
27
|
+
if revision
|
28
|
+
raise
|
29
|
+
else
|
30
|
+
@repository = FilesystemRepository.new(path_or_repo)
|
31
|
+
end
|
32
|
+
end
|
24
33
|
end
|
25
34
|
|
26
35
|
@revision = revision
|
data/lib/licensee/version.rb
CHANGED
data/test/functions.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Pulled from helper.rb because something in the test suite monkey patches benchmarking
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
|
+
require 'licensee/filesystem_repository'
|
4
5
|
|
5
6
|
def fixtures_base
|
6
7
|
File.expand_path "fixtures", File.dirname( __FILE__ )
|
@@ -18,27 +19,7 @@ def license_from_path(path)
|
|
18
19
|
license
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
attr_reader :content
|
23
|
-
|
24
|
-
def initialize(content)
|
25
|
-
@content = content
|
26
|
-
end
|
27
|
-
|
28
|
-
def size
|
29
|
-
content.size
|
30
|
-
end
|
31
|
-
|
32
|
-
def similarity(other)
|
33
|
-
self.hashsig ? Rugged::Blob::HashSignature.compare(self.hashsig, other) : 0
|
34
|
-
end
|
35
|
-
|
36
|
-
def hashsig(options = 0)
|
37
|
-
@hashsig ||= Rugged::Blob::HashSignature.new(content, options)
|
38
|
-
rescue Rugged::InvalidError
|
39
|
-
nil
|
40
|
-
end
|
41
|
-
end
|
22
|
+
FakeBlob = Licensee::FilesystemRepository::Blob
|
42
23
|
|
43
24
|
def chaos_monkey(string)
|
44
25
|
Random.rand(5).times do
|
@@ -1,57 +1,72 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
class TestLicenseeProject < Minitest::Test
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
6
|
+
[true, false].each do |as_git|
|
7
|
+
describe(as_git ? "git" : "non-git") do
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
9
|
+
def make_project(fixture_name, as_git)
|
10
|
+
fixture = fixture_path fixture_name
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
unless as_git
|
13
|
+
dest = File.join("tmp", "fixtures", fixture_name)
|
14
|
+
FileUtils.mkdir_p File.dirname(dest)
|
15
|
+
system "git", "clone", "-q", fixture, dest
|
16
|
+
FileUtils.rm_r File.join(dest, ".git")
|
17
|
+
fixture = dest
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
assert_equal Rugged::Commit, commit.class
|
20
|
-
assert_equal "b02cbad9d254c41d16d56ed9d6d2cf07c1d837fd", commit.oid
|
21
|
-
end
|
20
|
+
Licensee::Project.new fixture
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
unless as_git
|
24
|
+
def teardown
|
25
|
+
FileUtils.rm_rf "tmp/fixtures"
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
should "detect the license file" do
|
30
|
+
project = make_project "licenses.git", as_git
|
31
|
+
assert_instance_of Licensee::LicenseFile, project.license_file
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
should "detect the license" do
|
35
|
+
project = make_project "licenses.git", as_git
|
36
|
+
assert_equal "mit", project.license.key
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
should "return the license blob" do
|
40
|
+
project = make_project "licenses.git", as_git
|
41
|
+
assert_equal "LICENSE", project.send(:license_blob)[:name]
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
should "detect an atypically cased license file" do
|
45
|
+
project = make_project "case-sensitive.git", as_git
|
46
|
+
assert_instance_of Licensee::LicenseFile, project.license_file
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
should "detect MIT-LICENSE licensed projects" do
|
50
|
+
project = make_project "named-license-file-prefix.git", as_git
|
51
|
+
assert_equal "mit", project.license.key
|
52
|
+
end
|
53
|
+
|
54
|
+
should "detect LICENSE-MIT licensed projects" do
|
55
|
+
project = make_project "named-license-file-suffix.git", as_git
|
56
|
+
assert_equal "mit", project.license.key
|
57
|
+
end
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
|
59
|
+
should "not error out on repos with folders names license" do
|
60
|
+
project = make_project "license-folder.git", as_git
|
61
|
+
assert_equal nil, project.license
|
62
|
+
end
|
63
|
+
|
64
|
+
should "detect licence files" do
|
65
|
+
project = make_project "licence.git", as_git
|
66
|
+
assert_equal "mit", project.license.key
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
56
70
|
end
|
71
|
+
|
57
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rugged
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- Rakefile
|
108
108
|
- bin/licensee
|
109
109
|
- lib/licensee.rb
|
110
|
+
- lib/licensee/filesystem_repository.rb
|
110
111
|
- lib/licensee/license.rb
|
111
112
|
- lib/licensee/license_file.rb
|
112
113
|
- lib/licensee/licenses.rb
|
@@ -207,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
208
|
version: '0'
|
208
209
|
requirements: []
|
209
210
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.2.
|
211
|
+
rubygems_version: 2.2.3
|
211
212
|
signing_key:
|
212
213
|
specification_version: 4
|
213
214
|
summary: A Ruby Gem to detect under what license a project is distributed
|