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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 838dc4899938c974a913e9097f7ea675bbbaa3e4
4
- data.tar.gz: ccfd1b06f7d7e012db37caad3013f464c5cbfc1b
3
+ metadata.gz: d6d6862fe6acd66d17a577ac52357cb55352c355
4
+ data.tar.gz: 1e52b8216cd0443e86bf2f6b4bdc67d3a12c6b3c
5
5
  SHA512:
6
- metadata.gz: f990aba892efb0f74986af60d73dec263af25c19a83bb374555f39e2da16e530b079ac31d521ab30f53f971da3f19b1ef9bf225bebb38fbdabad398f27bc2a0e
7
- data.tar.gz: be5014602677a7947136059c65dfe6018be36a23ecfc79d931676915b8f91ca54a34ce1721323653efcb7ce4aa3ace003e6bae89e92d87469e19b8bf2b9d59d8
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 calcualte 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.
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
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require_relative "../lib/licensee"
4
- project = Licensee::Project.new(Dir.pwd)
3
+
4
+ path = ARGV[0] || Dir.pwd
5
+
6
+ project = Licensee::Project.new(path)
5
7
  license = project.license_file
6
8
 
7
9
  if license
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
@@ -70,7 +70,7 @@ class Licensee
70
70
  private
71
71
 
72
72
  def parts
73
- @parts ||= content.match(/^(---\n.*\n---\n+)?(.*)/m).to_a
73
+ @parts ||= content.match(/\A(---\n.*\n---\n+)?(.*)/m).to_a
74
74
  end
75
75
  end
76
76
  end
@@ -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
- @repository = Rugged::Repository.new(path_or_repo)
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
@@ -1,3 +1,3 @@
1
1
  class Licensee
2
- VERSION = "4.4.2"
2
+ VERSION = "4.5.0"
3
3
  end
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
- class FakeBlob
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
- def setup
6
- @project = Licensee::Project.new fixture_path("licenses.git")
7
- end
6
+ [true, false].each do |as_git|
7
+ describe(as_git ? "git" : "non-git") do
8
8
 
9
- should "detect the license file" do
10
- assert_equal Licensee::LicenseFile, @project.license_file.class
11
- end
9
+ def make_project(fixture_name, as_git)
10
+ fixture = fixture_path fixture_name
12
11
 
13
- should "detect the license" do
14
- assert_equal "mit", @project.license.key
15
- end
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
- should "know the last commit" do
18
- commit = @project.send(:commit)
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
- should "retrieve the tree" do
24
- tree = @project.send(:tree)
25
- assert_equal 1, tree.count
26
- assert_equal "bcb552d06d9cf1cd4c048a6d3bf716849c2216cc", tree.first[:oid]
27
- end
23
+ unless as_git
24
+ def teardown
25
+ FileUtils.rm_rf "tmp/fixtures"
26
+ end
27
+ end
28
28
 
29
- should "return the license blob" do
30
- assert_equal "LICENSE", @project.send(:license_blob)[:name]
31
- end
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
- should "detect an atypically cased license file" do
34
- project = Licensee::Project.new fixture_path("case-sensitive.git")
35
- assert_equal Licensee::LicenseFile, project.license_file.class
36
- end
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
- should "detect MIT-LICENSE licensed projects" do
39
- project = Licensee::Project.new fixture_path("named-license-file-prefix.git")
40
- assert_equal "mit", project.license.key
41
- end
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
- should "detect LICENSE-MIT licensed projects" do
44
- project = Licensee::Project.new fixture_path("named-license-file-suffix.git")
45
- assert_equal "mit", project.license.key
46
- end
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
- should "not error out on repos with folders names license" do
49
- project = Licensee::Project.new fixture_path("license-folder.git")
50
- assert_equal nil, project.license
51
- end
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
- should "detect licence files" do
54
- project = Licensee::Project.new fixture_path("licence.git")
55
- assert_equal "mit", project.license.key
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.2
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-04-01 00:00:00.000000000 Z
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.0
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