gemlicense 0.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.
Files changed (8) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +15 -0
  5. data/Rakefile +2 -0
  6. data/bin/gemlicense +73 -0
  7. data/gemlicense.gemspec +14 -0
  8. metadata +54 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemlicense.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 zzzhc
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Gemlicense
2
+
3
+ a small tool used to list all bundled gems's license
4
+
5
+ ## Installation
6
+
7
+ $ gem install gemlicense
8
+
9
+ ## Usage
10
+
11
+ ``` bash
12
+ $ cd $DIR_INCLUDED_A_GEMFILE
13
+ $ gemlicense
14
+ ```
15
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/gemlicense ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ class GemInfo
5
+ LICENSE_MAPPING = {
6
+ %r(MIT License|Permission is hereby granted, free of charge, to any person)i => "MIT License",
7
+ %r(MIT Licence|http://www.opensource.org/licenses/mit-license.html)i => "MIT License",
8
+ %r(Licensed under the (Apache License, Version [\d\.]+))i => lambda { |m| m[1] },
9
+ %r(Ruby-specific license|Ruby License|http://www.ruby-lang.org/en/LICENSE.txt)i => "Ruby License",
10
+ %r(under the same terms as Ruby|Ruby's License)i => "Ruby License",
11
+ %r(Redistributions of source code must retain the above copyright notice)i => "BSD License",
12
+ %r(GNU GENERAL PUBLIC LICENSE Version 3)i => "GPL v3",
13
+ %r(GNU General Public License)i => "GPL",
14
+ %r(http://www.gnu.org/licenses/lgpl-2.1.txt)i => "LGPL v2.1",
15
+ %r(http://www.gnu.org/licenses/lgpl-3.0.txt)i => "LGPL v3.0",
16
+ %r(\WGPL\W) => "GPL",
17
+ %r(GPL version 2)i => "GPL v2",
18
+ %r(LGPL)i => "LGPL"
19
+ }
20
+
21
+ attr_reader :name, :version, :full_name
22
+
23
+ def initialize(name, version)
24
+ @name, @version = name, version
25
+ @full_name = "#{name}-#{version}"
26
+ end
27
+
28
+ def detect_licenses
29
+ licenses = find_license("*license*", "*Licence*", "*LEGAL*", "*COPYING*", "*readme*")
30
+ licenses += find_license("lib/**/*.rb") if licenses.empty?
31
+ licenses.flatten.compact.sort.uniq
32
+ end
33
+
34
+ private
35
+ def find_license(*patterns)
36
+ find_files(*patterns).map do |license_path|
37
+ content = File.read(license_path)
38
+ content = content.force_encoding("iso8859-1") if content.respond_to?(:force_encoding)
39
+ content = content.gsub(/[\r\n]+/, " ").gsub(/\s+/, " ")
40
+ LICENSE_MAPPING.map do |rule, name|
41
+ if m = rule.match(content)
42
+ name.respond_to?(:call) ? name.call(m) : name
43
+ end
44
+ end
45
+ end.flatten.compact.sort.uniq
46
+ end
47
+
48
+ def find_files(*patterns)
49
+ self.class.gem_paths.map do |path|
50
+ gem_path = File.join(path, "gems", full_name)
51
+ next unless File.exists?(gem_path)
52
+
53
+ patterns.map do |pattern|
54
+ Dir.glob(File.join(gem_path, pattern), File::FNM_CASEFOLD)
55
+ end
56
+ end.compact.flatten
57
+ end
58
+
59
+ def self.gem_paths
60
+ @@gem_paths ||= ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
61
+ end
62
+ end
63
+
64
+ gems = `bundle list`.split(/[\r\n]+/).map do |line|
65
+ next GemInfo.new($1, $2) if (line =~ /\*\s+([^ ]+)\s+\((.+)\)/)
66
+ end.compact
67
+
68
+ name_max_size = gems.map {|g| g.full_name.size }.max
69
+ gems.each do |gem|
70
+ licenses = gem.detect_licenses
71
+ printf("%-#{name_max_size}s %s\n", gem.full_name, licenses.join(", "))
72
+ end
73
+
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["zzzhc"]
5
+ gem.email = ["chhuang@freewheel.tv"]
6
+ gem.description = %q{a small tool used to list all bundled gems's license}
7
+ gem.summary = %q{}
8
+ gem.homepage = ""
9
+
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.name = "gemlicense"
13
+ gem.version = '0.1'
14
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemlicense
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - zzzhc
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: a small tool used to list all bundled gems's license
15
+ email:
16
+ - chhuang@freewheel.tv
17
+ executables:
18
+ - gemlicense
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/gemlicense
28
+ - gemlicense.gemspec
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: ''
53
+ test_files: []
54
+ has_rdoc: