license_finder 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ For a Rails project add license_finder to your Gemfile:
10
10
  gem 'license_finder', :git => "https://github.com/pivotal/LicenseFinder.git"
11
11
 
12
12
  Run 'rake license:init'
13
- This will create a config/license_finder.yml file that lets you configure license finder.
13
+ This will create a config/license_finder.yml file that lets you configure license finder. This is where you should add licenses which are allowed on the project, so they will be automatically approved.
14
14
 
15
15
  Run 'rake license:generate_dependencies'
16
16
  This will write out a dependencies.yml and dependencies.txt file in the root of your project.
@@ -19,6 +19,9 @@ It will also merge in an existing dependencies.yml file, if one exists.
19
19
  Run 'rake license:action_items'
20
20
  This will output a list of unapproved dependencies to the console
21
21
 
22
+ Run 'rake license:action_items:ok'
23
+ This will return a non-zero exit status if there are unapproved dependencies. Great for CI.
24
+
22
25
  As a standalone script:
23
26
  cd ~
24
27
  git clone http://github.com/pivotal/LicenseFinder.git license_finder
@@ -81,4 +84,14 @@ bin/license_finder:
81
84
  disclaimer_of_liability: "mit: THE AUTHORS OR COPYRIGHT HOLDERS"
82
85
  readme_files:
83
86
  - file_name: README
84
- mentions_license: true
87
+ mentions_license: true
88
+
89
+ Gem Maintainers
90
+ ===============
91
+
92
+ Please add a license to your gemspec!
93
+
94
+ Gem::Specification.new do |s|
95
+ s.name = "my_great_gem"
96
+ s.license = "MIT"
97
+ end
@@ -28,5 +28,13 @@ module LicenseFinder
28
28
  rescue
29
29
  ''
30
30
  end
31
+
32
+ def without_punctuation(text)
33
+ text.gsub('#', '').gsub(' ', '')
34
+ end
35
+
36
+ def cleaned_up(text)
37
+ without_punctuation(on_single_line(text))
38
+ end
31
39
  end
32
40
  end
@@ -28,9 +28,11 @@ module LicenseFinder
28
28
  end
29
29
 
30
30
  def determine_license
31
+ return @spec.license if @spec.license
31
32
  return 'MIT' if license_files.any?{|f| f.mit_license_body? || f.mit_license_header?}
32
33
  return 'Apache 2.0' if license_files.any?(&:apache_license_body?)
33
34
  return 'GPLv2' if license_files.any?(&:gplv2_license_body?)
35
+ return 'ruby' if license_files.any?(&:ruby_license_body?)
34
36
  'other'
35
37
  end
36
38
 
@@ -7,7 +7,8 @@ module LicenseFinder
7
7
  MIT_DISCLAIMER_REGEX = /THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\. IN NO EVENT SHALL ((\w+ ){2,8})BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE\./
8
8
  MIT_ONE_LINER_REGEX = /is released under the MIT license/
9
9
  MIT_URL_REGEX = %r{MIT Licence.*http://www.opensource.org/licenses/mit-license}
10
-
10
+ RUBY_URL_REGEX = %r{http://www.ruby-lang.org/en/LICENSE.txt}
11
+
11
12
  def body_type
12
13
  if mit_license_body?
13
14
  'mit'
@@ -15,6 +16,8 @@ module LicenseFinder
15
16
  'apache'
16
17
  elsif gplv2_license_body?
17
18
  'gplv2'
19
+ elsif ruby_license_body?
20
+ 'ruby'
18
21
  else
19
22
  'other'
20
23
  end
@@ -29,10 +32,14 @@ module LicenseFinder
29
32
  end
30
33
 
31
34
  def mit_license_body?
32
- !!on_single_line(text).index(on_single_line(MIT_LICENSE_TEXT)) ||
35
+ !!cleaned_up(text).index(cleaned_up(MIT_LICENSE_TEXT)) ||
33
36
  !!(on_single_line(text) =~ MIT_URL_REGEX)
34
37
  end
35
38
 
39
+ def ruby_license_body?
40
+ !!(on_single_line(text) =~ RUBY_URL_REGEX)
41
+ end
42
+
36
43
  def apache_license_body?
37
44
  !!on_single_line(text).index(on_single_line(APACHE_LICENSE_TEXT))
38
45
  end
@@ -1,3 +1,3 @@
1
1
  module LicenseFinder
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -20,6 +20,10 @@ describe LicenseFinder::DependencyList do
20
20
  def full_gem_path
21
21
  @path || 'install/path'
22
22
  end
23
+
24
+ def license
25
+ nil
26
+ end
23
27
  end
24
28
 
25
29
  end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2010, 2011 Matthew Kocher
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -24,6 +24,10 @@ describe LicenseFinder::GemSpecDetails do
24
24
  'install/path'
25
25
  end
26
26
  end
27
+
28
+ def license
29
+ nil
30
+ end
27
31
  end
28
32
  end
29
33
 
@@ -34,6 +38,31 @@ describe LicenseFinder::GemSpecDetails do
34
38
  its(:dependency_version) { should == '2.1.3' }
35
39
  its(:install_path) { should == 'install/path' }
36
40
 
41
+ describe "#gemspec licenses" do
42
+ it "returns the license from the gemspec if provided" do
43
+ mock_gemspec = @mock_gemspec.new
44
+ stub(mock_gemspec).license { "MIT" }
45
+ LicenseFinder::GemSpecDetails.new(mock_gemspec).determine_license.should == "MIT"
46
+ end
47
+
48
+ it "returns 'ruby' if if is a ruby license" do
49
+ mock_gemspec = @mock_gemspec.new
50
+ mock_license_file = LicenseFinder::LicenseFile.new('gem', 'gem/license/path')
51
+ stub(mock_license_file).mit_license_body? { false }
52
+ stub(mock_license_file).mit_license_header? { false }
53
+ stub(mock_license_file).apache_license_body? { false }
54
+ stub(mock_license_file).gplv2_license_body? { false }
55
+
56
+ stub(mock_license_file).ruby_license_body? { true }
57
+
58
+
59
+ gemspec_details = LicenseFinder::GemSpecDetails.new(mock_gemspec)
60
+ stub(gemspec_details).license_files { [ mock_license_file ] }
61
+
62
+ gemspec_details.determine_license.should == "ruby"
63
+ end
64
+ end
65
+
37
66
  describe "#license_files" do
38
67
  it "is empty if there aren't any license files" do
39
68
  LicenseFinder::GemSpecDetails.new(@mock_gemspec.new).license_files.should == []
@@ -61,6 +90,8 @@ describe LicenseFinder::GemSpecDetails do
61
90
  end
62
91
  end
63
92
 
93
+
94
+
64
95
  describe "#readme_files" do
65
96
  it "is empty if there aren't any readme files" do
66
97
  LicenseFinder::GemSpecDetails.new(@mock_gemspec.new).readme_files.should == []
@@ -119,6 +150,20 @@ describe LicenseFinder::GemSpecDetails do
119
150
  its(:notes) { should == '' }
120
151
  end
121
152
 
153
+
154
+ describe 'with MIT License with hashes' do
155
+ subject do
156
+ LicenseFinder::GemSpecDetails.new(@mock_gemspec.new('spec/fixtures/mit_licensed_with_hashes'), ['MIT']).dependency
157
+ end
158
+
159
+ its(:name) { should == 'spec_name' }
160
+ its(:version) { should == '2.1.3' }
161
+ its(:license) { should == 'MIT' }
162
+ its(:approved) { should == true }
163
+ its(:license_url) { should == '' }
164
+ its(:notes) { should == '' }
165
+ end
166
+
122
167
  describe 'with Apache License' do
123
168
  subject do
124
169
  LicenseFinder::GemSpecDetails.new(@mock_gemspec.new('spec/fixtures/apache_licensed_gem'), ['Apache 2.0']).dependency
@@ -63,7 +63,17 @@ describe LicenseFinder::LicenseFile do
63
63
  its(:disclaimer_of_liability) { should == 'mit: THE AUTHORS OR COPYRIGHT HOLDERS' }
64
64
  end
65
65
 
66
-
66
+ context "with ruby url in README" do
67
+ before do
68
+ stub(IO).read { "Same as Ruby's \n\nhttp://www.ruby-lang.org/en/LICENSE.txt" }
69
+ stub(IO).binread { "Same as Ruby's \n\nhttp://www.ruby-lang.org/en/LICENSE.txt" }
70
+ end
71
+
72
+ its(:body_type) { should == 'ruby' }
73
+ its(:disclaimer_of_liability) { should == 'other' }
74
+ end
75
+
76
+
67
77
 
68
78
  context "with Apache like license" do
69
79
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: license_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-13 00:00:00.000000000 Z
12
+ date: 2012-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -96,6 +96,7 @@ files:
96
96
  - spec/fixtures/mit_licensed_gem/LICENSE
97
97
  - spec/fixtures/mit_licensed_gem_in_README/README.rdoc
98
98
  - spec/fixtures/mit_licensed_gem_via_url/README
99
+ - spec/fixtures/mit_licensed_with_hashes/MIT-LICENSE
99
100
  - spec/fixtures/nested_gem/vendor/LICENSE
100
101
  - spec/fixtures/nested_readme/vendor/README
101
102
  - spec/fixtures/no_license/.gitkeep
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  version: '0'
128
129
  requirements: []
129
130
  rubyforge_project: license_finder
130
- rubygems_version: 1.8.21
131
+ rubygems_version: 1.8.24
131
132
  signing_key:
132
133
  specification_version: 3
133
134
  summary: License finding heaven.
@@ -156,6 +157,7 @@ test_files:
156
157
  - spec/fixtures/mit_licensed_gem/LICENSE
157
158
  - spec/fixtures/mit_licensed_gem_in_README/README.rdoc
158
159
  - spec/fixtures/mit_licensed_gem_via_url/README
160
+ - spec/fixtures/mit_licensed_with_hashes/MIT-LICENSE
159
161
  - spec/fixtures/nested_gem/vendor/LICENSE
160
162
  - spec/fixtures/nested_readme/vendor/README
161
163
  - spec/fixtures/no_license/.gitkeep