gem-licenses 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,20 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem 'rspec', '~> 2.5.0'
4
+ gem "rspec", "~> 2.5.0"
5
5
  gem "jeweler", "~> 1.5.2"
6
6
  end
7
7
 
8
+ =begin
9
+ group :test do
10
+ gem "mongo"
11
+ gem "bson"
12
+ gem "rubyzip"
13
+ gem "json"
14
+ gem "ffi"
15
+ gem "ruby-debug-base19"
16
+ gem "daemons"
17
+ gem "frac"
18
+ end
19
+ =end
20
+
data/README.md CHANGED
@@ -17,11 +17,13 @@ Usage
17
17
 
18
18
  Include in your project. To list licenses try the following Rake task.
19
19
 
20
+ require 'gem_licenses'
21
+
20
22
  task :licenses do
21
23
  Gem.licenses.each do |license, gems|
22
24
  puts "#{license}"
23
- gems.each do |gem|
24
- puts " #{gem.name} (#{gem.full_gem_path})"
25
+ gems.sort_by { |gem| gem.name }.each do |gem|
26
+ puts "* #{gem.name} #{gem.version} (#{gem.homepage}) - #{gem.summary}"
25
27
  end
26
28
  end
27
29
  end
data/Rakefile CHANGED
@@ -37,9 +37,12 @@ require 'gem_licenses.rb'
37
37
  task :licenses do
38
38
  Gem.licenses.each do |license, gems|
39
39
  puts "#{license}"
40
- gems.each do |gem|
41
- puts " #{gem.name} (#{gem.full_gem_path})"
40
+ puts "=" * license.length
41
+ gems.sort_by { |gem| gem.name }.each do |gem|
42
+ puts "* #{gem.name} #{gem.version} (#{gem.homepage}) - #{gem.summary.strip}"
43
+ puts gem.full_gem_path
42
44
  end
45
+ puts ""
43
46
  end
44
47
  end
45
48
 
data/VERSION CHANGED
@@ -1,2 +1 @@
1
- 0.1.0
2
-
1
+ 0.1.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gem-licenses}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Doubrovkine"]
@@ -7,10 +7,9 @@ module Gem
7
7
  def licenses
8
8
  licenses = {}
9
9
  Gem.loaded_specs.each do |key, spec|
10
- # gemspec defines licenses
11
10
  spec.licenses.each do |license|
12
- licenses[license.to_sym] ||= []
13
- licenses[license.to_sym] << spec
11
+ licenses[license.capitalize.to_sym] ||= []
12
+ licenses[license.capitalize.to_sym] << spec
14
13
  end
15
14
  end
16
15
  licenses
@@ -2,7 +2,7 @@ class Gem::Specification
2
2
  alias_method :__licenses, :licenses
3
3
 
4
4
  def licenses
5
- ary = __licenses || []
5
+ ary = (__licenses || []).keep_if { |l| l.length > 0 }
6
6
  ary.length == 0 ? guess_licenses : ary
7
7
  end
8
8
 
@@ -10,22 +10,52 @@ class Gem::Specification
10
10
  licenses = []
11
11
  Dir.foreach(full_gem_path) do |filename|
12
12
  filename_without_extension = File.basename(filename, File.extname(filename)).downcase
13
- next unless filename_without_extension.include?("license")
14
- parts = filename.split('-')
15
- if (parts.length >= 2)
16
- licenses << parts[0].upcase
17
- else
18
- license_file = File.join(full_gem_path, filename)
19
- license_file_handle = File.new(license_file, "r")
20
- while (line = license_file_handle.gets)
21
- line = line.strip
22
- licenses << "MIT" if line.include? "MIT License"
13
+ if filename_without_extension.include?("license")
14
+ parts = filename.split('-')
15
+ if (parts.length >= 2)
16
+ licenses << parts[0].upcase
17
+ else
18
+ licenses = guess_licenses_from_file_contents File.join(full_gem_path, filename)
23
19
  end
20
+ elsif filename_without_extension.include?("readme")
21
+ licenses = guess_licenses_from_file_contents File.join(full_gem_path, filename)
24
22
  end
23
+ break if licenses.length > 0
25
24
  end
26
25
  licenses << :unknown if licenses.length == 0
27
26
  licenses
28
27
  end
29
28
 
29
+ private
30
+
31
+ def guess_licenses_from_file_contents(path)
32
+ licenses = []
33
+ file_handle = File.new(path, "r")
34
+ begin
35
+ while (line = file_handle.gets) && (licenses.size == 0)
36
+ line = line.strip
37
+ # positive matches
38
+ [
39
+ /released under the (?<l>[\s\w]*) license/i,
40
+ /same license as (?<l>[\s\w]*)/i,
41
+ /^(?<l>[\s\w]*) License, see/i,
42
+ /^(?<l>[\w]*) license$/i,
43
+ /\(the (?<l>[\s\w]*) license\)/i,
44
+ /^license: (?<l>[\s\w]*)/i,
45
+ /^released under the (?<l>[\s\w]*) license/i,
46
+ ].each do |r|
47
+ res = Regexp.new(r).match(line)
48
+ next unless res
49
+ licenses << res['l']
50
+ break
51
+ end
52
+ end
53
+ rescue
54
+ # TODO: warning
55
+ end
56
+ file_handle.close
57
+ licenses
58
+ end
59
+
30
60
  end
31
61
 
@@ -4,7 +4,7 @@ describe Gem do
4
4
  it "collects 3rd party licenses" do
5
5
  licenses = Gem.licenses
6
6
  licenses.size.should == 2
7
- licenses[:MIT].size.should == 7
8
- licenses[:unknown].size.should == 2
7
+ licenses[:Mit].size.should == 7
8
+ licenses[:Unknown].size.should == 2
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-licenses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &85711830 !ruby/object:Gem::Requirement
17
+ requirement: &88778540 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.5.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *85711830
25
+ version_requirements: *88778540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: jeweler
28
- requirement: &85711590 !ruby/object:Gem::Requirement
28
+ requirement: &88778250 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.5.2
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *85711590
36
+ version_requirements: *88778250
37
37
  description: Attempts to figure out what licenses various gems use.
38
38
  email: dblock@dblock.org
39
39
  executables: []
@@ -69,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
69
  version: '0'
70
70
  segments:
71
71
  - 0
72
- hash: -437104687
72
+ hash: -550813773
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements: