licensed 0.11.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +13 -4
- data/.rubocop.yml +3 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +14 -12
- data/CONTRIBUTING.md +51 -0
- data/Gemfile +2 -1
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +55 -76
- data/Rakefile +3 -2
- data/docs/configuration.md +131 -0
- data/docs/sources/bower.md +5 -0
- data/docs/sources/bundler.md +7 -0
- data/docs/sources/cabal.md +39 -0
- data/docs/sources/go.md +12 -0
- data/docs/sources/manifests.md +26 -0
- data/docs/sources/npm.md +3 -0
- data/docs/sources/stack.md +3 -0
- data/exe/licensed +1 -0
- data/lib/licensed.rb +9 -5
- data/lib/licensed/cli.rb +22 -14
- data/lib/licensed/command/cache.rb +46 -29
- data/lib/licensed/command/list.rb +17 -9
- data/lib/licensed/command/status.rb +78 -0
- data/lib/licensed/configuration.rb +127 -25
- data/lib/licensed/dependency.rb +8 -2
- data/lib/licensed/git.rb +39 -0
- data/lib/licensed/license.rb +1 -0
- data/lib/licensed/shell.rb +28 -0
- data/lib/licensed/source/bower.rb +4 -0
- data/lib/licensed/source/bundler.rb +4 -0
- data/lib/licensed/source/cabal.rb +72 -24
- data/lib/licensed/source/go.rb +23 -36
- data/lib/licensed/source/manifest.rb +26 -23
- data/lib/licensed/source/npm.rb +19 -8
- data/lib/licensed/ui/shell.rb +2 -1
- data/lib/licensed/version.rb +2 -1
- data/licensed.gemspec +9 -5
- data/{bin/setup → script/bootstrap} +13 -8
- data/script/cibuild +7 -0
- data/{bin → script}/console +1 -0
- metadata +53 -158
- data/.bowerrc +0 -3
- data/exe/licensor +0 -5
- data/lib/licensed/command/verify.rb +0 -73
- data/lib/licensed/source/stack.rb +0 -66
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "pathname/common_prefix"
|
2
3
|
|
3
4
|
module Licensed
|
4
5
|
module Source
|
@@ -12,65 +13,67 @@ module Licensed
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def type
|
15
|
-
|
16
|
+
"manifest"
|
16
17
|
end
|
17
18
|
|
18
19
|
def dependencies
|
19
20
|
@dependencies ||= packages.map do |package_name, sources|
|
20
21
|
Dependency.new(sources_license_path(sources), {
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
"type" => type,
|
23
|
+
"name" => package_name,
|
24
|
+
"version" => package_version(sources)
|
24
25
|
})
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
# Returns the top-most directory that is common to all paths in `sources`
|
28
30
|
def sources_license_path(sources)
|
29
31
|
common_prefix = Pathname.common_prefix(*sources).to_path
|
30
32
|
|
31
33
|
# don't allow the repo root to be used as common prefix
|
32
34
|
# the project this is run for should be excluded from the manifest,
|
33
35
|
# or ignored in the config. any license in the root should be ignored.
|
34
|
-
return common_prefix if common_prefix != repository_root
|
36
|
+
return common_prefix if common_prefix != Licensed::Git.repository_root
|
35
37
|
|
36
38
|
# use the first source file as the license path.
|
37
39
|
sources.first
|
38
40
|
end
|
39
41
|
|
42
|
+
# Returns the latest git SHA available from `sources`
|
40
43
|
def package_version(sources)
|
41
44
|
return if sources.nil? || sources.empty?
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
.max_by { |sha|
|
46
|
-
end
|
47
|
-
|
48
|
-
def commit_date_command(sha)
|
49
|
-
`git show -s -1 --format=%ct #{sha}`.strip
|
50
|
-
end
|
51
|
-
|
52
|
-
def source_version_command(source)
|
53
|
-
`git rev-list -1 HEAD -- #{source}`.strip
|
46
|
+
sources.map { |s| Licensed::Git.version(s) }
|
47
|
+
.compact
|
48
|
+
.max_by { |sha| Licensed::Git.commit_date(sha) }
|
54
49
|
end
|
55
50
|
|
51
|
+
# Returns a map of package names -> array of full source paths found
|
52
|
+
# in the app manifest
|
56
53
|
def packages
|
57
54
|
manifest.each_with_object({}) do |(src, package_name), hsh|
|
58
55
|
next if src.nil? || src.empty?
|
59
56
|
hsh[package_name] ||= []
|
60
|
-
hsh[package_name] << File.join(repository_root, src)
|
57
|
+
hsh[package_name] << File.join(Licensed::Git.repository_root, src)
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
61
|
+
# Returns parsed manifest data for the app
|
64
62
|
def manifest
|
65
|
-
|
63
|
+
case manifest_path.extname.downcase.delete "."
|
64
|
+
when "json"
|
65
|
+
JSON.parse(File.read(manifest_path))
|
66
|
+
when "yml", "yaml"
|
67
|
+
YAML.load_file(manifest_path)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
71
|
+
# Returns the manifest location for the app
|
68
72
|
def manifest_path
|
69
|
-
@config
|
70
|
-
|
73
|
+
path = @config["manifest"]["path"] if @config["manifest"]
|
74
|
+
return Licensed::Git.repository_root.join(path) if path
|
71
75
|
|
72
|
-
|
73
|
-
@root ||= `git rev-parse --show-toplevel`.strip
|
76
|
+
@config.cache_path.join("manifest.json")
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
data/lib/licensed/source/npm.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "json"
|
2
3
|
|
3
4
|
module Licensed
|
@@ -39,14 +40,8 @@ module Licensed
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def package_metadata_command
|
47
|
-
`npm list --json --production --long 2>/dev/null`
|
48
|
-
end
|
49
|
-
|
43
|
+
# Recursively parse dependency JSON data. Returns a hash mapping the
|
44
|
+
# package name to it's metadata
|
50
45
|
def recursive_dependencies(dependencies, result = {})
|
51
46
|
dependencies.each do |name, dependency|
|
52
47
|
(result[name] ||= {}).update(dependency)
|
@@ -54,6 +49,22 @@ module Licensed
|
|
54
49
|
end
|
55
50
|
result
|
56
51
|
end
|
52
|
+
|
53
|
+
# Returns the output from running `npm list` to get package paths
|
54
|
+
def package_location_command
|
55
|
+
npm_list_command("--parseable", "--production", "--long")
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the output from running `npm list` to get package metadata
|
59
|
+
def package_metadata_command
|
60
|
+
npm_list_command("--json", "--production", "--long")
|
61
|
+
end
|
62
|
+
|
63
|
+
# Executes an `npm list` command with the provided args and returns the
|
64
|
+
# output from stdout
|
65
|
+
def npm_list_command(*args)
|
66
|
+
Licensed::Shell.execute("npm", "list", *args)
|
67
|
+
end
|
57
68
|
end
|
58
69
|
end
|
59
70
|
end
|
data/lib/licensed/ui/shell.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "thor"
|
2
3
|
|
3
4
|
module Licensed
|
@@ -7,7 +8,7 @@ module Licensed
|
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
@shell = STDOUT.tty? ? Thor::Base.shell.new : Thor::Shell::Basic.new
|
10
|
-
@level = ENV[
|
11
|
+
@level = ENV["DEBUG"] ? "debug" : "info"
|
11
12
|
end
|
12
13
|
|
13
14
|
def debug(msg, newline = true)
|
data/lib/licensed/version.rb
CHANGED
data/licensed.gemspec
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require "licensed/version"
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
8
|
spec.name = "licensed"
|
8
9
|
spec.version = Licensed::VERSION
|
9
10
|
spec.authors = ["GitHub"]
|
10
|
-
spec.email = ["opensource@github.com"]
|
11
|
+
spec.email = ["opensource+licensed@github.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Extract and validate the licenses of dependencies.}
|
14
|
+
spec.description = "Licensed automates extracting and validating the licenses of dependencies."
|
11
15
|
|
12
|
-
spec.summary = %q{extract and validate the licenses of dependencies.}
|
13
|
-
spec.description = File.read("README.md")
|
14
16
|
spec.homepage = "https://github.com/github/licensed"
|
15
17
|
spec.license = "MIT"
|
16
18
|
|
@@ -29,4 +31,6 @@ Gem::Specification.new do |spec|
|
|
29
31
|
spec.add_development_dependency "minitest", "~> 5.8"
|
30
32
|
spec.add_development_dependency "vcr", "~> 2.9"
|
31
33
|
spec.add_development_dependency "webmock", "~> 1.21"
|
34
|
+
spec.add_development_dependency "rubocop", "~> 0.49"
|
35
|
+
spec.add_development_dependency "rubocop-github", "~> 0.6"
|
32
36
|
end
|
@@ -3,24 +3,29 @@ set -euo pipefail
|
|
3
3
|
IFS=$'\n\t'
|
4
4
|
|
5
5
|
if [ -n "$(which bundle)" ]; then
|
6
|
-
bundle install
|
6
|
+
bundle install --path vendor/gems
|
7
|
+
fi
|
8
|
+
|
9
|
+
cd test/fixtures
|
10
|
+
|
11
|
+
if [ -n "$(which bundle)" ]; then
|
12
|
+
pushd bundler
|
13
|
+
bundle install --path vendor/gems
|
14
|
+
popd
|
7
15
|
fi
|
8
16
|
|
9
17
|
# Install bower fixtures
|
10
18
|
if [ -n "$(which bower)" ]; then
|
19
|
+
pushd bower
|
11
20
|
bower install
|
21
|
+
popd
|
12
22
|
fi
|
13
23
|
|
14
|
-
cd test/fixtures
|
15
|
-
|
16
24
|
# Install npm fixtures
|
17
25
|
if [ -n "$(which npm)" ]; then
|
26
|
+
pushd npm
|
18
27
|
npm install
|
19
|
-
|
20
|
-
|
21
|
-
# Install stack fixtures
|
22
|
-
if [ -n "$(which stack)" ]; then
|
23
|
-
stack build
|
28
|
+
popd
|
24
29
|
fi
|
25
30
|
|
26
31
|
if [ -n "$(which go)" ]; then
|
data/script/cibuild
ADDED
data/{bin → script}/console
RENAMED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: licensee
|
@@ -136,189 +136,84 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '1.21'
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
vendor/licenses/rubygem/bundler.txt:
|
169
|
-
- license needs reviewed: mit.
|
170
|
-
|
171
|
-
vendor/licenses/rubygem/licensee.txt:
|
172
|
-
- missing license data
|
173
|
-
|
174
|
-
vendor/licenses/bower/jquery.txt:
|
175
|
-
- license needs reviewed: mit.
|
176
|
-
- cached license data out of date
|
177
|
-
|
178
|
-
3 dependencies checked, 3 warnings found.
|
179
|
-
```
|
180
|
-
|
181
|
-
### Configuration
|
182
|
-
|
183
|
-
Configuration is managed by `vendor/licenses/config.yml`.
|
184
|
-
|
185
|
-
```yml
|
186
|
-
# Dependencies with these licenses are approved by default.
|
187
|
-
whitelist:
|
188
|
-
- mit
|
189
|
-
- apache-2.0
|
190
|
-
- bsd-2-clause
|
191
|
-
- bsd-3-clause
|
192
|
-
- cc0-1.0
|
193
|
-
|
194
|
-
# These dependencies are explicitly ignored.
|
195
|
-
ignored:
|
196
|
-
rubygem:
|
197
|
-
- some-internal-gem
|
198
|
-
|
199
|
-
bower:
|
200
|
-
- some-internal-package
|
201
|
-
|
202
|
-
# These dependencies have been reviewed.
|
203
|
-
reviewed:
|
204
|
-
rubygem:
|
205
|
-
- bcrypt-ruby
|
206
|
-
|
207
|
-
bower:
|
208
|
-
- classlist # public domain
|
209
|
-
- octicons
|
210
|
-
```
|
211
|
-
|
212
|
-
### Sources
|
213
|
-
|
214
|
-
Dependencies will be automatically detected for
|
215
|
-
1. Bundler (rubygem)
|
216
|
-
2. NPM
|
217
|
-
3. Bower
|
218
|
-
4. HaskellStack
|
219
|
-
5. Cabal
|
220
|
-
6. Go
|
221
|
-
7. Manifest lists
|
222
|
-
|
223
|
-
You can disable any of them in `vendor/licenses/config.yml`:
|
224
|
-
|
225
|
-
```yml
|
226
|
-
sources:
|
227
|
-
rubygem: false
|
228
|
-
npm: false
|
229
|
-
bower: false
|
230
|
-
stack: false
|
231
|
-
```
|
232
|
-
|
233
|
-
#### Special Considerations for Sources
|
234
|
-
##### rubygem
|
235
|
-
The rubygem source will explicitly exclude gems in the `:development` and `:test` groups. Be aware that if you have a local
|
236
|
-
bundler configuration (e.g. `.bundle`), that configuration will be respected as well. For example, if you have a local
|
237
|
-
configuration set for `without: [':server']`, the rubygem source will exclude all gems in the `:server` group.
|
238
|
-
|
239
|
-
##### cabal
|
240
|
-
Cabal sourced dependencies are found exclusively through `ghc-pkg`. `licensed` makes no assumptions on where `ghc` package dbs are found.
|
241
|
-
As a result, it is up to the caller to set `GHC_PACKAGE_PATHS` to all package db directories prior to calling into `licensed`.
|
242
|
-
|
243
|
-
##### manifests
|
244
|
-
Manifests are intended to be a stopgap if no package managers are available. The manifest is a JSON file that should be placed in
|
245
|
-
the same directory as `config.yml` and should have the following format
|
246
|
-
```JSON
|
247
|
-
{
|
248
|
-
"file1": "package1",
|
249
|
-
"path/to/file2": "package1",
|
250
|
-
"other/file3": "package2"
|
251
|
-
}
|
252
|
-
```
|
253
|
-
Paths to files are expected to be relative to the git repository root. Package names will match 1:1 with metadata files at `<licenses directory>/manifest/*.txt`.
|
254
|
-
|
255
|
-
It is the responsibility of the repository owner to maintain the manifest file.
|
256
|
-
|
257
|
-
## Development
|
258
|
-
|
259
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
260
|
-
|
261
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
262
|
-
|
263
|
-
#### Adding sources
|
264
|
-
|
265
|
-
When adding new dependency sources, ensure that `bin/setup` scripting and tests are only run if the required tooling is available on the development machine.
|
266
|
-
|
267
|
-
* See `bin/setup` for examples of gating scripting based on whether tooling executables are found.
|
268
|
-
* Use `tool_available?` when writing test files to gate running a test suite when tooling executables aren't available.
|
269
|
-
```ruby
|
270
|
-
if tool_available?('bundle')
|
271
|
-
describe Licensed::Source::Bundler do
|
272
|
-
...
|
273
|
-
end
|
274
|
-
end
|
275
|
-
```
|
276
|
-
|
277
|
-
## Contributing
|
278
|
-
|
279
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/github/licensed. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/) code of conduct.
|
280
|
-
|
281
|
-
## License
|
282
|
-
|
283
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.49'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.49'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-github
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.6'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.6'
|
167
|
+
description: Licensed automates extracting and validating the licenses of dependencies.
|
284
168
|
email:
|
285
|
-
- opensource@github.com
|
169
|
+
- opensource+licensed@github.com
|
286
170
|
executables:
|
287
171
|
- licensed
|
288
|
-
- licensor
|
289
172
|
extensions: []
|
290
173
|
extra_rdoc_files: []
|
291
174
|
files:
|
292
|
-
- ".bowerrc"
|
293
175
|
- ".gitignore"
|
176
|
+
- ".rubocop.yml"
|
177
|
+
- ".ruby-version"
|
294
178
|
- ".travis.yml"
|
179
|
+
- CHANGELOG.md
|
295
180
|
- CODE_OF_CONDUCT.md
|
181
|
+
- CONTRIBUTING.md
|
296
182
|
- Gemfile
|
297
|
-
- LICENSE
|
183
|
+
- LICENSE
|
298
184
|
- README.md
|
299
185
|
- Rakefile
|
300
|
-
-
|
301
|
-
-
|
186
|
+
- docs/configuration.md
|
187
|
+
- docs/sources/bower.md
|
188
|
+
- docs/sources/bundler.md
|
189
|
+
- docs/sources/cabal.md
|
190
|
+
- docs/sources/go.md
|
191
|
+
- docs/sources/manifests.md
|
192
|
+
- docs/sources/npm.md
|
193
|
+
- docs/sources/stack.md
|
302
194
|
- exe/licensed
|
303
|
-
- exe/licensor
|
304
195
|
- lib/licensed.rb
|
305
196
|
- lib/licensed/cli.rb
|
306
197
|
- lib/licensed/command/cache.rb
|
307
198
|
- lib/licensed/command/list.rb
|
308
|
-
- lib/licensed/command/
|
199
|
+
- lib/licensed/command/status.rb
|
309
200
|
- lib/licensed/configuration.rb
|
310
201
|
- lib/licensed/dependency.rb
|
202
|
+
- lib/licensed/git.rb
|
311
203
|
- lib/licensed/license.rb
|
204
|
+
- lib/licensed/shell.rb
|
312
205
|
- lib/licensed/source/bower.rb
|
313
206
|
- lib/licensed/source/bundler.rb
|
314
207
|
- lib/licensed/source/cabal.rb
|
315
208
|
- lib/licensed/source/go.rb
|
316
209
|
- lib/licensed/source/manifest.rb
|
317
210
|
- lib/licensed/source/npm.rb
|
318
|
-
- lib/licensed/source/stack.rb
|
319
211
|
- lib/licensed/ui/shell.rb
|
320
212
|
- lib/licensed/version.rb
|
321
213
|
- licensed.gemspec
|
214
|
+
- script/bootstrap
|
215
|
+
- script/cibuild
|
216
|
+
- script/console
|
322
217
|
homepage: https://github.com/github/licensed
|
323
218
|
licenses:
|
324
219
|
- MIT
|
@@ -339,8 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
339
234
|
version: '0'
|
340
235
|
requirements: []
|
341
236
|
rubyforge_project:
|
342
|
-
rubygems_version: 2.6.
|
237
|
+
rubygems_version: 2.6.8
|
343
238
|
signing_key:
|
344
239
|
specification_version: 4
|
345
|
-
summary:
|
240
|
+
summary: Extract and validate the licenses of dependencies.
|
346
241
|
test_files: []
|