license_scout 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -5
- data/bin/license_scout +39 -1
- data/bin/rebar_lock_json +0 -0
- data/erl_src/rebar_lock_json/README.md +17 -0
- data/erl_src/rebar_lock_json/rebar.config +19 -0
- data/erl_src/rebar_lock_json/rebar.lock +36 -0
- data/erl_src/rebar_lock_json/src/rebar_lock_json.app.src +17 -0
- data/erl_src/rebar_lock_json/src/rebar_lock_json.erl +20 -0
- data/lib/license_scout/canonical_licenses/BSD-2-Clause.txt +19 -0
- data/lib/license_scout/canonical_licenses/BSD-3-Clause.txt +27 -0
- data/lib/license_scout/canonical_licenses/Chef-MLSA.txt +5 -0
- data/lib/license_scout/collector.rb +1 -1
- data/lib/license_scout/dependency_manager/base.rb +8 -1
- data/lib/license_scout/dependency_manager/berkshelf.rb +1 -1
- data/lib/license_scout/dependency_manager/bundler.rb +1 -1
- data/lib/license_scout/dependency_manager/cpanm.rb +160 -0
- data/lib/license_scout/dependency_manager/dep.rb +87 -0
- data/lib/license_scout/dependency_manager/glide.rb +79 -0
- data/lib/license_scout/dependency_manager/godep.rb +71 -0
- data/lib/license_scout/dependency_manager/rebar.rb +6 -35
- data/lib/license_scout/dependency_manager.rb +5 -2
- data/lib/license_scout/license_file_analyzer/definitions.rb +8 -1
- data/lib/license_scout/license_file_analyzer/templates/Apache2.txt +0 -2
- data/lib/license_scout/license_file_analyzer/templates/Chef-MLSA.txt +5 -0
- data/lib/license_scout/net_fetcher.rb +1 -0
- data/lib/license_scout/options.rb +1 -1
- data/lib/license_scout/overrides.rb +553 -19
- data/lib/license_scout/version.rb +1 -1
- metadata +45 -13
- data/.gitignore +0 -9
- data/.rspec +0 -3
- data/.rubocop.yml +0 -4
- data/.travis.yml +0 -11
- data/Gemfile +0 -24
- data/Rakefile +0 -39
- data/appveyor.yml +0 -19
- data/bin/config_to_json +0 -0
- data/lib/license_scout/dependency_manager/cpan.rb +0 -322
- data/license_scout.gemspec +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e457b9a208151ac27a602231842b51bbb238ab63f8e89352e731e2ccf375dd1b
|
4
|
+
data.tar.gz: 5c77592e6f9a5781ab16e5348abb9246d56056345e363e96a77040b043de99b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 892170c7c155c080d93917c3bca10006c812c3fd8becc014b3918d26032533520d056349bf909d9bb7ecc245ae1eb2f7d503c4d4bdaaa7833852ce4ea9af526f
|
7
|
+
data.tar.gz: 62691f59c045e70555cfc5dba3e0d6f5e3eeceb6161f945f84d8b5c4ce96042b61050098b12e15a55f47be9b394a394ba18c7d310174abd9b5411138a224a6e2
|
data/README.md
CHANGED
@@ -5,16 +5,24 @@ dependencies, including transitive dependencies.
|
|
5
5
|
|
6
6
|
Currently supported project types are:
|
7
7
|
|
8
|
-
*
|
8
|
+
* Chef - Berkshelf
|
9
9
|
* Erlang - rebar
|
10
|
-
*
|
11
|
-
*
|
10
|
+
* Golang - godeps
|
11
|
+
* Javascript - npm
|
12
|
+
* Perl - CPAN
|
13
|
+
* Ruby - bundler
|
12
14
|
|
13
15
|
## Usage
|
14
16
|
|
15
|
-
|
17
|
+
```bash
|
18
|
+
$ bin/license_scout /dir/to/scout/successfully/
|
19
|
+
|
20
|
+
$ bin/license_scout /dir/to/scout/unsuccessfully/
|
21
|
+
Dependency 'gopkg.in_yaml.v2' version '53feefa2559fb8dfa8d81baad31be332c97d6c77' under 'go_godep' is missing license information.
|
22
|
+
>> Found 41 dependencies for go_godep. 40 OK, 1 with problems
|
23
|
+
```
|
16
24
|
|
17
|
-
|
25
|
+
Detailed instructions for fixing licensing failures found by license_scout are now provided in the script's output. See [bin/license_scout](bin/license_scout) for more details.
|
18
26
|
|
19
27
|
## Contributing
|
20
28
|
|
data/bin/license_scout
CHANGED
@@ -38,4 +38,42 @@ collector = LicenseScout::Collector.new(project_name, project_dir, output_dir, o
|
|
38
38
|
collector.run
|
39
39
|
report = collector.issue_report
|
40
40
|
|
41
|
-
|
41
|
+
unless report.empty?
|
42
|
+
puts report
|
43
|
+
|
44
|
+
puts <<-EXPLANATION
|
45
|
+
|
46
|
+
How to fix this depends on what information license_scout was unable to
|
47
|
+
determine:
|
48
|
+
|
49
|
+
* If the package is missing license information, that means license_scout was
|
50
|
+
unable to determine which license the package was released under. Depending
|
51
|
+
on the package manager, this is usually specified in the package's metadata,
|
52
|
+
for example, in the gemspec file for rubygems or in the package.json for npm.
|
53
|
+
If you know which license a package was released under, MIT for example, you
|
54
|
+
can add an override in license_scout's overrides.rb file in the section for
|
55
|
+
the appropriate package manager like this:
|
56
|
+
["package-name", "MIT", nil]
|
57
|
+
|
58
|
+
* If the package is missing the license file, that means license_scout could not
|
59
|
+
find the license text in any of the places the license is typically found, for
|
60
|
+
example, in a file named LICENSE in the root of the package. If the package
|
61
|
+
includes the license text in a non standard location or in its source repo,
|
62
|
+
you can indicate this by adding an override in license_scout's overrides.rb
|
63
|
+
file in the section for the appropriate package manager like this:
|
64
|
+
["package-name", nil, ["https://example.com/foocorp/package-name/master/LICENSE"]],
|
65
|
+
|
66
|
+
If you know that the package was released under one of the common software
|
67
|
+
licenses, MIT for example, but does not include the license text in packaged
|
68
|
+
releases or in its source repo, you can add an override in license_scout's
|
69
|
+
overrides.rb file in the section for the appropriate package manager like
|
70
|
+
this:
|
71
|
+
["package-name", nil, [canonical("MIT")]]
|
72
|
+
|
73
|
+
See the closed pull requests on the license_scout repo for examples of how to
|
74
|
+
do this:
|
75
|
+
https://github.com/chef/license_scout/pulls?q=is%3Apr+is%3Aclosed
|
76
|
+
EXPLANATION
|
77
|
+
|
78
|
+
exit 2
|
79
|
+
end
|
data/bin/rebar_lock_json
ADDED
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
rebar_lock_json
|
2
|
+
===============
|
3
|
+
|
4
|
+
A minimal escript converting a rebar.lock file to json output.
|
5
|
+
|
6
|
+
Should work with any version of rebar (2 or 3)'s rebar.lock file.
|
7
|
+
|
8
|
+
Build
|
9
|
+
-----
|
10
|
+
|
11
|
+
$ rebar3 escriptize # this also copies the escript file to bin/
|
12
|
+
|
13
|
+
Run
|
14
|
+
---
|
15
|
+
|
16
|
+
$ bin/rebar_lock_json path/to/rebar.lock
|
17
|
+
{"amqp_client":{"type":"git","git_url":"git:\/\/github.com\/seth\/amqp_client.git","git_ref":"7622ad8093a41b7288a1aa44dd16d3e92ce8f833"}}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{erl_opts, [no_debug_info]}.
|
2
|
+
{deps, [
|
3
|
+
jsone,
|
4
|
+
{rebar3, {git, "https://github.com/erlang/rebar3", {branch, "master"}}}
|
5
|
+
]}.
|
6
|
+
|
7
|
+
{escript_incl_apps,
|
8
|
+
[rebar_lock_json]}.
|
9
|
+
{escript_main_app, rebar_lock_json}.
|
10
|
+
{escript_name, rebar_lock_json}.
|
11
|
+
{escript_emu_args, "%%! +sbtu +A0\n"}.
|
12
|
+
|
13
|
+
{post_hooks, [
|
14
|
+
{escriptize, "cp $REBAR_BUILD_DIR/bin/rebar_lock_json ../../bin/"}
|
15
|
+
]}.
|
16
|
+
|
17
|
+
{profiles, [{test,
|
18
|
+
[{erl_opts, [debug_info]}
|
19
|
+
]}]}.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{"1.1.0",
|
2
|
+
[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.3.0">>},1},
|
3
|
+
{<<"certifi">>,{pkg,<<"certifi">>,<<"0.4.0">>},1},
|
4
|
+
{<<"cf">>,{pkg,<<"cf">>,<<"0.2.2">>},1},
|
5
|
+
{<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.2.3">>},1},
|
6
|
+
{<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"1.0.0">>},1},
|
7
|
+
{<<"eunit_formatters">>,{pkg,<<"eunit_formatters">>,<<"0.3.1">>},1},
|
8
|
+
{<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},1},
|
9
|
+
{<<"jiffy">>,{pkg,<<"jiffy">>,<<"0.14.11">>},0},
|
10
|
+
{<<"jsone">>,{pkg,<<"jsone">>,<<"1.4.1">>},0},
|
11
|
+
{<<"providers">>,{pkg,<<"providers">>,<<"1.6.0">>},1},
|
12
|
+
{<<"rebar">>,
|
13
|
+
{git,"https://github.com/erlang/rebar3",
|
14
|
+
{ref,"4725d363c5b5583c9910f078da38c5b3a1d97aab"}},
|
15
|
+
0},
|
16
|
+
{<<"rebar3">>,
|
17
|
+
{git,"https://github.com/erlang/rebar3",
|
18
|
+
{ref,"86e883b8d8d1d16487e245fff02eba8c83da2cdd"}},
|
19
|
+
0},
|
20
|
+
{<<"relx">>,{pkg,<<"relx">>,<<"3.22.2">>},1},
|
21
|
+
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.1">>},1}]}.
|
22
|
+
[
|
23
|
+
{pkg_hash,[
|
24
|
+
{<<"bbmustache">>, <<"2010ADAE78830992A4C69680115ECD7D475DD03A72C076BBADDCCBF2D4B32035">>},
|
25
|
+
{<<"certifi">>, <<"A7966EFB868B179023618D29A407548F70C52466BF1849B9E8EBD0E34B7EA11F">>},
|
26
|
+
{<<"cf">>, <<"7F2913FFF90ABCABD0F489896CFEB0B0674F6C8DF6C10B17A83175448029896C">>},
|
27
|
+
{<<"cth_readable">>, <<"293120673DFF82F0768612C5282E35C40CACC1B6F94FE99077438FD3749D0E27">>},
|
28
|
+
{<<"erlware_commons">>, <<"087467DE5833C0BB5B3CCDD387F9E9C1FB816A75B7A709629BF24B5ED3246C51">>},
|
29
|
+
{<<"eunit_formatters">>, <<"7A6FC351EB5B873E2356B8852EB751E20C13A72FBCA03393CF682B8483509573">>},
|
30
|
+
{<<"getopt">>, <<"B17556DB683000BA50370B16C0619DF1337E7AF7ECBF7D64FBF8D1D6BCE3109B">>},
|
31
|
+
{<<"jiffy">>, <<"919A87D491C5A6B5E3BBC27FAFEDC3A0761CA0B4C405394F121F582FD4E3F0E5">>},
|
32
|
+
{<<"jsone">>, <<"10ECFB2E2FD216D6451AF71CF14F276E063A096E15B685DE7535FD680466C9B5">>},
|
33
|
+
{<<"providers">>, <<"DB0E2F9043AE60C0155205FCD238D68516331D0E5146155E33D1E79DC452964A">>},
|
34
|
+
{<<"relx">>, <<"AEE2EF6E9AC6D21D6661133B7A0BE6E81424DE9CDCA0012FC008BC677297C469">>},
|
35
|
+
{<<"ssl_verify_fun">>, <<"28A4D65B7F59893BC2C7DE786DEC1E1555BD742D336043FE644AE956C3497FBE">>}]}
|
36
|
+
].
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{application, rebar_lock_json,
|
2
|
+
[{description, "An escript util returning json representation of rebar.lock"},
|
3
|
+
{vsn, "0.1.0"},
|
4
|
+
{registered, []},
|
5
|
+
{applications,
|
6
|
+
[kernel,
|
7
|
+
stdlib,
|
8
|
+
rebar,
|
9
|
+
jsone
|
10
|
+
]},
|
11
|
+
{env,[]},
|
12
|
+
{modules, []},
|
13
|
+
|
14
|
+
{maintainers, []},
|
15
|
+
{licenses, []},
|
16
|
+
{links, []}
|
17
|
+
]}.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
-module(rebar_lock_json).
|
2
|
+
|
3
|
+
-export([main/1]).
|
4
|
+
|
5
|
+
main([LockPath|_]) ->
|
6
|
+
Deps = rebar_config:consult_lock_file(LockPath),
|
7
|
+
Ejson = lists:map(fun dep_to_ejson/1, Deps),
|
8
|
+
io:format("~s~n", [jsone:encode({Ejson})]).
|
9
|
+
|
10
|
+
dep_to_ejson({Name, {pkg, PkgName, PkgVersion, Hash}, Lvl}) ->
|
11
|
+
{Name, {[{<<"type">>, <<"pkg">>},
|
12
|
+
{<<"level">>, Lvl},
|
13
|
+
{<<"pkg_name">>, PkgName},
|
14
|
+
{<<"pkg_version">>, PkgVersion},
|
15
|
+
{<<"pkg_hash">>, Hash}]}};
|
16
|
+
dep_to_ejson({Name, {git, GitUrl, {ref, GitRef}}, Lvl}) ->
|
17
|
+
{Name, {[{<<"type">>, <<"git">>},
|
18
|
+
{<<"level">>, Lvl},
|
19
|
+
{<<"git_url">>, erlang:iolist_to_binary(GitUrl)},
|
20
|
+
{<<"git_ref">>, erlang:iolist_to_binary(GitRef)}]}}.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without
|
2
|
+
modification, are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
5
|
+
list of conditions and the following disclaimer.
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
8
|
+
and/or other materials provided with the distribution.
|
9
|
+
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE <COPYRIGHT HOLDERS> "AS IS" AND
|
11
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
12
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
13
|
+
DISCLAIMED. IN NO EVENT SHALL THE <COPYRIGHT HOLDERS> BE LIABLE FOR
|
14
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
15
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
16
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
17
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
18
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
19
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) <year> <owner> . All rights reserved. Redistribution and use in
|
2
|
+
source and binary forms, with or without modification, are permitted provided
|
3
|
+
that the following conditions are met:
|
4
|
+
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
6
|
+
list of conditions and the following disclaimer.
|
7
|
+
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
9
|
+
this list of conditions and the following disclaimer in the documentation
|
10
|
+
and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
13
|
+
may be used to endorse or promote products derived from this software without
|
14
|
+
specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
|
@@ -44,7 +44,7 @@ module LicenseScout
|
|
44
44
|
def run
|
45
45
|
reset_license_manifest
|
46
46
|
|
47
|
-
if !File.
|
47
|
+
if !File.exist?(project_dir)
|
48
48
|
raise LicenseScout::Exceptions::ProjectDirectoryMissing.new(project_dir)
|
49
49
|
end
|
50
50
|
FileUtils.mkdir_p(output_dir) unless File.exist?(output_dir)
|
@@ -16,6 +16,7 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require "license_scout/dependency"
|
19
|
+
require "license_scout/license_file_analyzer"
|
19
20
|
|
20
21
|
module LicenseScout
|
21
22
|
module DependencyManager
|
@@ -24,7 +25,9 @@ module LicenseScout
|
|
24
25
|
POSSIBLE_LICENSE_FILES = %w{
|
25
26
|
LICENSE
|
26
27
|
LICENSE.txt
|
28
|
+
LICENSE.TXT
|
27
29
|
LICENSE.md
|
30
|
+
LICENSE.mkd
|
28
31
|
LICENSE.rdoc
|
29
32
|
License
|
30
33
|
License.text
|
@@ -36,6 +39,9 @@ module LicenseScout
|
|
36
39
|
license
|
37
40
|
LICENCE
|
38
41
|
licence
|
42
|
+
license.md
|
43
|
+
licence.md
|
44
|
+
APACHE.LICENSE
|
39
45
|
MIT-LICENSE
|
40
46
|
MIT-LICENSE.txt
|
41
47
|
LICENSE.MIT
|
@@ -46,6 +52,7 @@ module LicenseScout
|
|
46
52
|
COPYING
|
47
53
|
BSD_LICENSE
|
48
54
|
LICENSE.BSD
|
55
|
+
UNLICENSE
|
49
56
|
}
|
50
57
|
|
51
58
|
attr_reader :project_dir
|
@@ -56,7 +63,7 @@ module LicenseScout
|
|
56
63
|
@options = options
|
57
64
|
end
|
58
65
|
|
59
|
-
def create_dependency(dep_name, version, license, license_files, dep_mgr_name =
|
66
|
+
def create_dependency(dep_name, version, license, license_files, dep_mgr_name = name)
|
60
67
|
# add name of the dependency manager `name` to the dependency we are
|
61
68
|
# creating.
|
62
69
|
Dependency.new(dep_name, version, license, license_files, dep_mgr_name)
|
@@ -39,7 +39,7 @@ module LicenseScout
|
|
39
39
|
# that created issues with projects like oc_bifrost which is a rebar
|
40
40
|
# project but have a Gemfile at its root to be able to run some rake
|
41
41
|
# commands.
|
42
|
-
File.
|
42
|
+
File.exist?(gemfile_path) && File.exist?(lockfile_path)
|
43
43
|
end
|
44
44
|
|
45
45
|
def dependency_data
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "ffi_yajl"
|
19
|
+
require "psych"
|
20
|
+
require "mixlib/shellout"
|
21
|
+
|
22
|
+
require "license_scout/dependency_manager/base"
|
23
|
+
require "license_scout/exceptions"
|
24
|
+
require "license_scout/dependency"
|
25
|
+
|
26
|
+
module LicenseScout
|
27
|
+
module DependencyManager
|
28
|
+
class Cpanm < Base
|
29
|
+
|
30
|
+
class CpanmDependency
|
31
|
+
|
32
|
+
LICENSE_TYPE_MAP = {
|
33
|
+
"perl_5" => "Perl-5",
|
34
|
+
"perl" => "Perl-5",
|
35
|
+
"apache_2_0" => "Apache-2.0",
|
36
|
+
"artistic_2" => "Artistic-2.0",
|
37
|
+
"gpl_3" => "GPL-3.0",
|
38
|
+
}.freeze
|
39
|
+
|
40
|
+
attr_reader :unpack_path
|
41
|
+
attr_reader :overrides
|
42
|
+
attr_reader :metadata
|
43
|
+
|
44
|
+
def initialize(unpack_path, overrides)
|
45
|
+
@unpack_path = unpack_path
|
46
|
+
@overrides = overrides
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_dep
|
50
|
+
parse_metadata!
|
51
|
+
|
52
|
+
Dependency.new(
|
53
|
+
name,
|
54
|
+
version.to_s,
|
55
|
+
license,
|
56
|
+
license_files,
|
57
|
+
"perl_cpanm"
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_metadata!
|
62
|
+
# Packages can contain metadata files named META.yml, META.json,
|
63
|
+
# MYMETA.json, MYMETA.yml. META.* files are created by the authors of
|
64
|
+
# the plugins whereas MYMETA.* files are created by the build system
|
65
|
+
# after dynamic dependencies are resolved. For our purposes META.*
|
66
|
+
# files are enough. And for no good reason we prioritize json files
|
67
|
+
# over yml files.
|
68
|
+
@metadata ||= begin
|
69
|
+
json_path = File.join(unpack_path, "META.json")
|
70
|
+
yml_path = File.join(unpack_path, "META.yml")
|
71
|
+
|
72
|
+
if File.exist?(json_path)
|
73
|
+
FFI_Yajl::Parser.parse(File.read(json_path))
|
74
|
+
elsif File.exist?(yml_path)
|
75
|
+
Psych.safe_load(File.read(yml_path))
|
76
|
+
else
|
77
|
+
raise LicenseScout::Exceptions::Error.new("Can not find a metadata file for the perl package at '#{unpack_path}'.")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def name
|
83
|
+
metadata["name"]
|
84
|
+
end
|
85
|
+
|
86
|
+
def version
|
87
|
+
metadata["version"]
|
88
|
+
end
|
89
|
+
|
90
|
+
def license
|
91
|
+
@license ||= begin
|
92
|
+
override_license = overrides.license_for("perl_cpanm", name, version)
|
93
|
+
|
94
|
+
if override_license
|
95
|
+
override_license
|
96
|
+
elsif metadata && metadata.key?("license")
|
97
|
+
given_type = Array(metadata["license"]).reject { |l| l == "unknown" }.first
|
98
|
+
|
99
|
+
# Normalize the common perl license strings to the strings we commonly use
|
100
|
+
LICENSE_TYPE_MAP[given_type] || given_type
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def license_files
|
106
|
+
@license_files ||= begin
|
107
|
+
override_license_files = overrides.license_files_for("perl_cpanm", name, version)
|
108
|
+
|
109
|
+
if override_license_files.empty?
|
110
|
+
find_license_files
|
111
|
+
else
|
112
|
+
override_license_files.resolve_locations(unpack_path)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def find_license_files
|
118
|
+
Dir["#{unpack_path}/*"].select do |f|
|
119
|
+
Cpanm::POSSIBLE_LICENSE_FILES.include?(File.basename(f))
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def name
|
126
|
+
"perl_cpanm"
|
127
|
+
end
|
128
|
+
|
129
|
+
def cpanm_root
|
130
|
+
# By default cpanm downloads all the dependencies into ~/.cpanm directory
|
131
|
+
File.expand_path("~/.cpanm")
|
132
|
+
end
|
133
|
+
|
134
|
+
def dependencies
|
135
|
+
@dependencies ||= begin
|
136
|
+
deps = []
|
137
|
+
|
138
|
+
Dir.glob("#{cpanm_root}/latest-build/*").each do |dep_path|
|
139
|
+
next unless File.directory?(dep_path)
|
140
|
+
|
141
|
+
deps << CpanmDependency.new(dep_path, options.overrides).to_dep
|
142
|
+
end
|
143
|
+
|
144
|
+
deps
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# NOTE: it's possible that projects won't have a META.yml, but the two
|
149
|
+
# that we care about for Chef Server do have one. As of 2015, 84% of perl
|
150
|
+
# distribution packages have one: http://neilb.org/2015/10/18/spotters-guide.html
|
151
|
+
def detected?
|
152
|
+
meta_yml_path = File.join(project_dir, "META.yml")
|
153
|
+
meta_json_path = File.join(project_dir, "META.json")
|
154
|
+
|
155
|
+
File.exist?(meta_yml_path) || File.exist?(meta_json_path)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "ffi_yajl"
|
19
|
+
require "yaml"
|
20
|
+
require "toml-rb"
|
21
|
+
require "license_scout/dependency_manager/base"
|
22
|
+
|
23
|
+
module LicenseScout
|
24
|
+
module DependencyManager
|
25
|
+
# dep(https://github.com/golang/dep) is a new dependency manger available from go 1.8
|
26
|
+
class Dep < Base
|
27
|
+
|
28
|
+
def name
|
29
|
+
"go_dep"
|
30
|
+
end
|
31
|
+
|
32
|
+
def detected?
|
33
|
+
File.exist?(root_dep_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
def dependencies
|
37
|
+
deps = File.open(root_dep_file) do |f|
|
38
|
+
TomlRB.parse(f)
|
39
|
+
end
|
40
|
+
return [] unless deps.has_key?("projects")
|
41
|
+
deps["projects"].map do |pkg_info|
|
42
|
+
pkg_import_name = pkg_info["name"]
|
43
|
+
pkg_file_name = pkg_import_name.tr("/", "_")
|
44
|
+
pkg_version = pkg_info["version"] || pkg_info["revision"]
|
45
|
+
license = options.overrides.license_for("go", pkg_import_name, pkg_version)
|
46
|
+
|
47
|
+
override_license_files = options.overrides.license_files_for("go", pkg_import_name, pkg_version)
|
48
|
+
if override_license_files.empty?
|
49
|
+
license_files = find_license_files_for_package_in_gopath_or_vendor_dir(pkg_import_name)
|
50
|
+
else
|
51
|
+
license_files = override_license_files.resolve_locations(gopath(pkg_import_name))
|
52
|
+
end
|
53
|
+
|
54
|
+
if license.nil? && !license_files.empty?
|
55
|
+
license = scan_licenses(license_files)
|
56
|
+
end
|
57
|
+
|
58
|
+
create_dependency(pkg_file_name, pkg_version, license, license_files)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def scan_licenses(license_files)
|
65
|
+
found_license = LicenseScout::LicenseFileAnalyzer.find_by_text(IO.read(license_files.first))
|
66
|
+
found_license && found_license.short_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def root_dep_file
|
70
|
+
File.join(project_dir, "Gopkg.lock")
|
71
|
+
end
|
72
|
+
|
73
|
+
def gopath(pkg)
|
74
|
+
"#{ENV['GOPATH']}/src/#{pkg}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def vendor_dir(pkg = nil)
|
78
|
+
File.join(project_dir, "vendor/#{pkg}")
|
79
|
+
end
|
80
|
+
|
81
|
+
def find_license_files_for_package_in_gopath_or_vendor_dir(pkg)
|
82
|
+
root_files = Dir["#{gopath(pkg)}/*"] + Dir["#{vendor_dir(pkg)}/*"]
|
83
|
+
root_files.select { |f| POSSIBLE_LICENSE_FILES.include?(File.basename(f)) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2017, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "yaml"
|
19
|
+
require "license_scout/dependency_manager/base"
|
20
|
+
|
21
|
+
module LicenseScout
|
22
|
+
module DependencyManager
|
23
|
+
class Glide < Base
|
24
|
+
|
25
|
+
def name
|
26
|
+
"go_glide"
|
27
|
+
end
|
28
|
+
|
29
|
+
def detected?
|
30
|
+
File.exist?(glide_yaml)
|
31
|
+
end
|
32
|
+
|
33
|
+
def dependencies
|
34
|
+
unless File.file?(glide_yaml_locked)
|
35
|
+
raise "Detected Go/Glide project that is missing its \"glide.lock\" "\
|
36
|
+
"file in #{project_dir}"
|
37
|
+
end
|
38
|
+
|
39
|
+
deps = YAML.load(File.read(glide_yaml_locked))
|
40
|
+
deps["imports"].map { |i| add_glide_dep(i) }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def add_glide_dep(import_field)
|
46
|
+
pkg_import_name = import_field["name"]
|
47
|
+
pkg_file_name = pkg_import_name.tr("/", "_")
|
48
|
+
pkg_version = import_field["version"]
|
49
|
+
license = options.overrides.license_for("go", pkg_import_name, pkg_version)
|
50
|
+
|
51
|
+
override_license_files = options.overrides.license_files_for("go", pkg_import_name, pkg_version)
|
52
|
+
if override_license_files.empty?
|
53
|
+
license_files = find_license_files_for_package_in_gopath(pkg_import_name)
|
54
|
+
else
|
55
|
+
license_files = override_license_files.resolve_locations(gopath(pkg_import_name))
|
56
|
+
end
|
57
|
+
|
58
|
+
create_dependency(pkg_file_name, pkg_version, license, license_files)
|
59
|
+
end
|
60
|
+
|
61
|
+
def glide_yaml
|
62
|
+
File.join(project_dir, "glide.yaml")
|
63
|
+
end
|
64
|
+
|
65
|
+
def glide_yaml_locked
|
66
|
+
File.join(project_dir, "glide.lock")
|
67
|
+
end
|
68
|
+
|
69
|
+
def gopath(pkg)
|
70
|
+
"#{ENV['GOPATH']}/src/#{pkg}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def find_license_files_for_package_in_gopath(pkg)
|
74
|
+
root_files = Dir["#{gopath(pkg)}/*"]
|
75
|
+
root_files.select { |f| POSSIBLE_LICENSE_FILES.include?(File.basename(f)) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|