bundler_gemfile_license_audit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/bundler_gemfile_license_audit.gemspec +24 -0
- data/lib/bundler_gemfile_license_audit.rb +55 -0
- data/lib/bundler_gemfile_license_audit/license.rb +53 -0
- data/lib/bundler_gemfile_license_audit/version.rb +3 -0
- data/lib/rubygems_plugin.rb +1 -0
- data/spec/bundler_gemfile_license_audit_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9388f97886493ff6e8dc09b6a844bb5ec729f8e7
|
4
|
+
data.tar.gz: b7d2a29916cf298e4d5a978aad592909132036e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 799a759aed09639817a08e0d418e685fda5392143098458644c22273bff7652ccd8d701ebf84bf81ba9dae7875752f6ee59b426d2a5174670318f77f27d49ab6
|
7
|
+
data.tar.gz: e81f25c172b5e9c90c56919de0c4c1ea4b9ddce60789a8d1c162618fe0c84e4204c267d9e6df59d66a703c108d06d8ce9a23d2509e7724544fc209299b6f0b88
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sho Hashimoto
|
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,35 @@
|
|
1
|
+
# BundlerGemfileLicenseAudit
|
2
|
+
|
3
|
+
Audit Gemfile's license dependency violations.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bundler_gemfile_license_audit'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bundler_gemfile_license_audit
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To make bundler to use this gem as well, you need to load the rubygems_plugin before. The easiest way is to make an alias in your ~/.bashrc or so:
|
24
|
+
|
25
|
+
```
|
26
|
+
alias bundle='RUBYOPT="-rbundler_gemfile_license_audit" bundle'
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it ( https://github.com/[my-github-username]/bundler_gemfile_license_audit/fork )
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bundler_gemfile_license_audit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bundler_gemfile_license_audit"
|
8
|
+
spec.version = BundlerGemfileLicenseAudit::VERSION
|
9
|
+
spec.authors = ["Sho Hashimoto"]
|
10
|
+
spec.email = ["sho.hsmt@gmail.com"]
|
11
|
+
spec.summary = "Audit Gemfile's license dependency violations."
|
12
|
+
spec.description = "Audit Gemfile's license dependency violations."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'bundler_gemfile_license_audit/version'
|
2
|
+
require 'bundler_gemfile_license_audit/license'
|
3
|
+
|
4
|
+
module BundlerGemfileLicenseAudit
|
5
|
+
module LicenceCheckerForInstall
|
6
|
+
def self.prepended(base)
|
7
|
+
class << base
|
8
|
+
self.prepend(ClassMethods)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def install(root, definition, options = {})
|
14
|
+
Bundler.ui.debug("bundler_gemfile_license_audit enabled.")
|
15
|
+
Bundler.ui.debug("start checking dependency library licenses...")
|
16
|
+
|
17
|
+
# TODO: use more good method.
|
18
|
+
base_dep = Bundler.definition.dependencies.detect { |dep|
|
19
|
+
path = dep.to_spec.source.options["path"]
|
20
|
+
path && path == "."
|
21
|
+
}
|
22
|
+
|
23
|
+
if base_dep.nil?
|
24
|
+
Bundler.ui.debug("base license: nil")
|
25
|
+
Bundler.ui.debug("skip checking.")
|
26
|
+
return super
|
27
|
+
end
|
28
|
+
|
29
|
+
base_spec = base_dep.to_spec
|
30
|
+
Bundler.ui.debug("base license: #{base_spec.license.inspect}")
|
31
|
+
Bundler.definition.dependencies.each do |dependency|
|
32
|
+
# do not check recursive because it is depend gem's license problem.
|
33
|
+
dep_spec = dependency.to_spec
|
34
|
+
Bundler.ui.debug("checking with #{dep_spec.name}(#{dep_spec.license.inspect})...")
|
35
|
+
BundlerGemfileLicenseAudit::License.check_violation(dep_spec.name, dep_spec.license, *base_spec.license)
|
36
|
+
end
|
37
|
+
|
38
|
+
# TODO: need to check violation during each dependencies?
|
39
|
+
# Bundler.definition.dependencies.combination(2).each do |dep_a, dep_b|
|
40
|
+
# Bundler.ui.debug("checking #{dep_a.name}(#{dep_a.license.inspect}) with #{dep_b.name}(#{dep_b.license.inspect})...")
|
41
|
+
# BundlerGemfileLicenseAudit::License.check_violation(dep_a.name, dep_a.license, *dep_b.license)
|
42
|
+
# end
|
43
|
+
|
44
|
+
Bundler.ui.debug("done checking dependency library licenses.")
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Bundler
|
52
|
+
class Installer
|
53
|
+
prepend BundlerGemfileLicenseAudit::LicenceCheckerForInstall
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module BundlerGemfileLicenseAudit
|
2
|
+
class LicenseError < StandardError; end
|
3
|
+
|
4
|
+
module License
|
5
|
+
LICENSES = {
|
6
|
+
mit: /MIT/i,
|
7
|
+
ruby: /Ruby/i,
|
8
|
+
gpl2: /GPL[-v]?2/i,
|
9
|
+
gpl3: /GPL[-v]?3/i,
|
10
|
+
apache2: /Apache[- ]2.0/i,
|
11
|
+
bsd4: /BSD\z/i, # Original(4-clause)BSD License
|
12
|
+
bsd3: /BSD-3-Clause\z/i, # Modified(3-clause)BSD License
|
13
|
+
}
|
14
|
+
VIOLATION_MAP = {
|
15
|
+
mit: [],
|
16
|
+
ruby: [],
|
17
|
+
# http://www.gnu.org/licenses/license-list.ja.html#GPLIncompatibleLicenses
|
18
|
+
gpl2: [:bsd4, :apache2],
|
19
|
+
gpl3: [:bsd4],
|
20
|
+
apache2: [:gpl2],
|
21
|
+
bsd4: [],
|
22
|
+
bsd3: [],
|
23
|
+
}
|
24
|
+
|
25
|
+
def check_violation(gemname, depend_license, *gemspec_licenses)
|
26
|
+
return if gemspec_licenses.empty?
|
27
|
+
gemspec_license_syms = gemspec_licenses.collect { |s|
|
28
|
+
to_license_sym(s)
|
29
|
+
}
|
30
|
+
depend_license_sym = to_license_sym(depend_license)
|
31
|
+
|
32
|
+
violated = true
|
33
|
+
gemspec_license_syms.each do |sym|
|
34
|
+
if !VIOLATION_MAP[sym].include?(depend_license_sym)
|
35
|
+
violated = false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
if violated
|
39
|
+
msg = "#{gemspec_licenses.inspect} and #{depend_license}(#{gemname}) is violated!!"
|
40
|
+
raise LicenseError, msg
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module_function :check_violation
|
45
|
+
|
46
|
+
def to_license_sym(s)
|
47
|
+
sym, = LICENSES.detect { |_sym, regexp| regexp.match(s) }
|
48
|
+
sym
|
49
|
+
end
|
50
|
+
|
51
|
+
module_function :to_license_sym
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler_gemfile_license_audit'
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundler_gemfile_license_audit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sho Hashimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Audit Gemfile's license dependency violations.
|
56
|
+
email:
|
57
|
+
- sho.hsmt@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- bundler_gemfile_license_audit.gemspec
|
68
|
+
- lib/bundler_gemfile_license_audit.rb
|
69
|
+
- lib/bundler_gemfile_license_audit/license.rb
|
70
|
+
- lib/bundler_gemfile_license_audit/version.rb
|
71
|
+
- lib/rubygems_plugin.rb
|
72
|
+
- spec/bundler_gemfile_license_audit_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Audit Gemfile's license dependency violations.
|
98
|
+
test_files:
|
99
|
+
- spec/bundler_gemfile_license_audit_spec.rb
|
100
|
+
- spec/spec_helper.rb
|