license_finder 3.0.4 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +56 -0
- data/CHANGELOG.md +29 -2
- data/CONTRIBUTING.md +5 -1
- data/Dockerfile +33 -10
- data/Gemfile +2 -2
- data/README.md +27 -5
- data/Rakefile +15 -21
- data/ci/pipelines/pipeline.yml.erb +40 -6
- data/ci/pipelines/release.yml +11 -5
- data/ci/scripts/containerize-tests.sh +16 -0
- data/ci/scripts/run-rubocop.sh +8 -0
- data/ci/scripts/run-tests.sh +22 -0
- data/ci/scripts/test.ps1 +81 -0
- data/ci/tasks/build-windows.yml +6 -0
- data/ci/tasks/build.yml +2 -2
- data/ci/tasks/rubocop.yml +13 -0
- data/features/features/cli/cli_spec.rb +8 -8
- data/features/features/configure/add_dependencies_spec.rb +7 -7
- data/features/features/configure/approve_dependencies_spec.rb +15 -15
- data/features/features/configure/assign_licenses_spec.rb +4 -4
- data/features/features/configure/blacklist_licenses_spec.rb +3 -3
- data/features/features/configure/ignore_dependencies_spec.rb +3 -3
- data/features/features/configure/ignore_groups_spec.rb +4 -4
- data/features/features/configure/name_project_spec.rb +4 -4
- data/features/features/configure/set_project_path_spec.rb +2 -2
- data/features/features/configure/whitelist_licenses_spec.rb +4 -4
- data/features/features/package_managers/bower_spec.rb +3 -3
- data/features/features/package_managers/carthage_spec.rb +14 -0
- data/features/features/package_managers/cocoapods_spec.rb +3 -3
- data/features/features/package_managers/conan_spec.rb +11 -0
- data/features/features/package_managers/dep_spec.rb +15 -0
- data/features/features/package_managers/glide_spec.rb +14 -0
- data/features/features/package_managers/govendor_spec.rb +15 -0
- data/features/features/package_managers/gradle_spec.rb +1 -1
- data/features/features/package_managers/gvt_spec.rb +14 -0
- data/features/features/package_managers/maven_spec.rb +2 -3
- data/features/features/package_managers/mix_spec.rb +16 -0
- data/features/features/package_managers/npm_spec.rb +3 -3
- data/features/features/package_managers/nuget_spec.rb +4 -4
- data/features/features/package_managers/pip_spec.rb +2 -2
- data/features/features/package_managers/rebar_spec.rb +3 -3
- data/features/features/package_managers/yarn_spec.rb +14 -0
- data/features/features/report/composite_spec.rb +1 -1
- data/features/features/report/csv_spec.rb +3 -3
- data/features/features/report/diff_spec.rb +20 -10
- data/features/features/report/html_spec.rb +10 -10
- data/features/features/report/subproject_spec.rb +15 -4
- data/features/fixtures/Cartfile +1 -0
- data/features/fixtures/Podfile +1 -1
- data/features/fixtures/alternate-build-file-gradle/build-alt.gradle +5 -15
- data/features/fixtures/build.gradle +5 -15
- data/features/fixtures/conanfile.txt +11 -0
- data/features/fixtures/file-based-libs-gradle/build.gradle +5 -7
- data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.lock +9 -0
- data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.toml +7 -0
- data/features/fixtures/gopath_dep/src/foo-dep/bar/bar.go +10 -0
- data/features/fixtures/gopath_dep/src/foo-dep/foo.go +7 -0
- data/features/fixtures/gopath_glide/src/glide.lock +9 -0
- data/features/fixtures/gopath_glide/src/glide.yaml +6 -0
- data/features/fixtures/gopath_govendor/src/vendor/vendor.json +19 -0
- data/features/fixtures/gopath_gvt/src/vendor/manifest +22 -0
- data/features/fixtures/gradle-wrapper/build.gradle +5 -15
- data/features/fixtures/gradle-wrapper/gradlew +6 -1
- data/features/fixtures/gradle-wrapper/gradlew.bat +9 -1
- data/features/fixtures/mix.exs +22 -0
- data/features/fixtures/multi-module-gradle/build.gradle +7 -15
- data/features/fixtures/single-module-gradle/build.gradle +5 -15
- data/features/support/testing_dsl.rb +155 -43
- data/lib/license_finder.rb +4 -3
- data/lib/license_finder/cli.rb +0 -3
- data/lib/license_finder/cli/approvals.rb +3 -3
- data/lib/license_finder/cli/base.rb +11 -8
- data/lib/license_finder/cli/blacklist.rb +7 -7
- data/lib/license_finder/cli/dependencies.rb +8 -8
- data/lib/license_finder/cli/ignored_dependencies.rb +4 -4
- data/lib/license_finder/cli/ignored_groups.rb +4 -4
- data/lib/license_finder/cli/licenses.rb +2 -2
- data/lib/license_finder/cli/main.rb +59 -39
- data/lib/license_finder/cli/makes_decisions.rb +2 -2
- data/lib/license_finder/cli/patched_thor.rb +6 -7
- data/lib/license_finder/cli/project_name.rb +5 -6
- data/lib/license_finder/cli/whitelist.rb +7 -7
- data/lib/license_finder/configuration.rb +15 -4
- data/lib/license_finder/core.rb +20 -4
- data/lib/license_finder/decision_applier.rb +0 -1
- data/lib/license_finder/decisions.rb +12 -14
- data/lib/license_finder/diff.rb +33 -31
- data/lib/license_finder/license.rb +13 -9
- data/lib/license_finder/license/definitions.rb +55 -55
- data/lib/license_finder/license/none_matcher.rb +1 -1
- data/lib/license_finder/license/template.rb +1 -1
- data/lib/license_finder/license/text.rb +0 -1
- data/lib/license_finder/license_aggregator.rb +1 -0
- data/lib/license_finder/logger.rb +18 -61
- data/lib/license_finder/package.rb +25 -11
- data/lib/license_finder/package_delta.rb +3 -6
- data/lib/license_finder/package_manager.rb +77 -34
- data/lib/license_finder/package_managers/bower.rb +8 -8
- data/lib/license_finder/package_managers/bower_package.rb +12 -12
- data/lib/license_finder/package_managers/bundler.rb +21 -9
- data/lib/license_finder/package_managers/bundler_package.rb +1 -1
- data/lib/license_finder/package_managers/carthage.rb +66 -0
- data/lib/license_finder/package_managers/carthage_package.rb +16 -0
- data/lib/license_finder/package_managers/cocoa_pods.rb +13 -13
- data/lib/license_finder/package_managers/cocoa_pods_package.rb +1 -1
- data/lib/license_finder/package_managers/conan.rb +26 -0
- data/lib/license_finder/package_managers/conan_info_parser.rb +74 -0
- data/lib/license_finder/package_managers/conan_package.rb +17 -0
- data/lib/license_finder/package_managers/dep.rb +33 -0
- data/lib/license_finder/package_managers/glide.rb +30 -0
- data/lib/license_finder/package_managers/{go_vendor.rb → go_15vendorexperiment.rb} +19 -24
- data/lib/license_finder/package_managers/go_dep.rb +15 -12
- data/lib/license_finder/package_managers/go_package.rb +15 -13
- data/lib/license_finder/package_managers/go_workspace.rb +39 -34
- data/lib/license_finder/package_managers/govendor.rb +32 -0
- data/lib/license_finder/package_managers/gradle.rb +16 -16
- data/lib/license_finder/package_managers/gradle_package.rb +8 -8
- data/lib/license_finder/package_managers/gvt.rb +61 -0
- data/lib/license_finder/package_managers/maven.rb +17 -18
- data/lib/license_finder/package_managers/maven_package.rb +4 -6
- data/lib/license_finder/package_managers/merged_package.rb +25 -2
- data/lib/license_finder/package_managers/mix.rb +51 -0
- data/lib/license_finder/package_managers/mix_package.rb +7 -0
- data/lib/license_finder/package_managers/npm.rb +8 -32
- data/lib/license_finder/package_managers/npm_package.rb +51 -48
- data/lib/license_finder/package_managers/nuget.rb +30 -40
- data/lib/license_finder/package_managers/pip.rb +11 -11
- data/lib/license_finder/package_managers/pip_package.rb +8 -8
- data/lib/license_finder/package_managers/rebar.rb +11 -11
- data/lib/license_finder/package_managers/yarn.rb +62 -0
- data/lib/license_finder/packages/activation.rb +2 -2
- data/lib/license_finder/packages/license_files.rb +6 -6
- data/lib/license_finder/packages/licensing.rb +8 -10
- data/lib/license_finder/packages/manual_package.rb +2 -2
- data/lib/license_finder/project_finder.rb +6 -5
- data/lib/license_finder/report.rb +1 -0
- data/lib/license_finder/reports/csv_report.rb +4 -4
- data/lib/license_finder/reports/diff_report.rb +2 -2
- data/lib/license_finder/reports/erb_report.rb +2 -4
- data/lib/license_finder/reports/html_report.rb +2 -2
- data/lib/license_finder/reports/markdown_report.rb +1 -1
- data/lib/license_finder/reports/merged_report.rb +1 -1
- data/lib/license_finder/reports/text_report.rb +3 -5
- data/lib/license_finder/shared_helpers/cmd.rb +11 -0
- data/lib/license_finder/version.rb +1 -1
- data/license_finder-2.1.2.gem +0 -0
- data/license_finder.gemspec +38 -38
- metadata +84 -118
- data/ci/scripts/test.sh +0 -26
- data/ci/tasks/create-source-archives.yml +0 -23
- data/spec/dummy_app/Gemfile +0 -6
- data/spec/fixtures/all_pms/.envrc +0 -1
- data/spec/fixtures/all_pms/.nuget/.keep +0 -0
- data/spec/fixtures/all_pms/Gemfile +0 -0
- data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
- data/spec/fixtures/all_pms/Podfile +0 -0
- data/spec/fixtures/all_pms/bower.json +0 -0
- data/spec/fixtures/all_pms/build.gradle +0 -0
- data/spec/fixtures/all_pms/package.json +0 -0
- data/spec/fixtures/all_pms/pom.xml +0 -0
- data/spec/fixtures/all_pms/rebar.config +0 -0
- data/spec/fixtures/all_pms/requirements.txt +0 -0
- data/spec/fixtures/all_pms/vendor/.gitkeep +0 -0
- data/spec/fixtures/composite/Gemfile +0 -0
- data/spec/fixtures/composite/nested_project/.envrc +0 -8
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +0 -16
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +0 -5
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +0 -6
- data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
- data/spec/fixtures/composite/project1/Gemfile +0 -0
- data/spec/fixtures/composite/project2/package.json +0 -0
- data/spec/fixtures/config/license_finder.yml +0 -5
- data/spec/fixtures/license_directory/COPYING +0 -1
- data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -1
- data/spec/fixtures/license_directory/LICENSE/lib/unrelated.txt +0 -2
- data/spec/fixtures/license_names/COPYING.txt +0 -1
- data/spec/fixtures/license_names/LICENSE +0 -1
- data/spec/fixtures/license_names/Licence.rdoc +0 -1
- data/spec/fixtures/license_names/Mit-License +0 -1
- data/spec/fixtures/license_names/README.rdoc +0 -1
- data/spec/fixtures/nested_gem/vendor/LICENSE +0 -1
- data/spec/fixtures/npm-circular-dependencies/npm-list.json +0 -5339
- data/spec/fixtures/npm-circular-dependencies/package.json +0 -5
- data/spec/fixtures/npm-circular-licenses/npm-list.json +0 -7597
- data/spec/fixtures/npm-circular-licenses/package.json +0 -23
- data/spec/fixtures/npm-licenses-string/npm-list.json +0 -7597
- data/spec/fixtures/npm-licenses-string/package.json +0 -23
- data/spec/fixtures/npm-recursive-dependencies/npm-list.json +0 -5158
- data/spec/fixtures/npm-recursive-dependencies/package.json +0 -15
- data/spec/fixtures/npm-stack-too-deep/npm-list.json +0 -13464
- data/spec/fixtures/npm-stack-too-deep/package.json +0 -5
- data/spec/fixtures/utf8_gem/README +0 -210
- data/spec/lib/license_finder/cli/approvals_spec.rb +0 -71
- data/spec/lib/license_finder/cli/blacklist_spec.rb +0 -58
- data/spec/lib/license_finder/cli/dependencies_spec.rb +0 -73
- data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +0 -47
- data/spec/lib/license_finder/cli/ignored_groups_spec.rb +0 -40
- data/spec/lib/license_finder/cli/licenses_spec.rb +0 -60
- data/spec/lib/license_finder/cli/main_spec.rb +0 -243
- data/spec/lib/license_finder/cli/project_name_spec.rb +0 -40
- data/spec/lib/license_finder/cli/whitelist_spec.rb +0 -58
- data/spec/lib/license_finder/configuration_spec.rb +0 -115
- data/spec/lib/license_finder/core_spec.rb +0 -54
- data/spec/lib/license_finder/decision_applier_spec.rb +0 -219
- data/spec/lib/license_finder/decisions_spec.rb +0 -408
- data/spec/lib/license_finder/diff_spec.rb +0 -129
- data/spec/lib/license_finder/license/definitions_spec.rb +0 -177
- data/spec/lib/license_finder/license_aggregator_spec.rb +0 -61
- data/spec/lib/license_finder/license_spec.rb +0 -106
- data/spec/lib/license_finder/package_delta_spec.rb +0 -18
- data/spec/lib/license_finder/package_manager_spec.rb +0 -62
- data/spec/lib/license_finder/package_managers/bower_package_spec.rb +0 -71
- data/spec/lib/license_finder/package_managers/bower_spec.rb +0 -39
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +0 -35
- data/spec/lib/license_finder/package_managers/bundler_spec.rb +0 -56
- data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +0 -48
- data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +0 -59
- data/spec/lib/license_finder/package_managers/go_dep_spec.rb +0 -126
- data/spec/lib/license_finder/package_managers/go_package_spec.rb +0 -33
- data/spec/lib/license_finder/package_managers/go_vendor_spec.rb +0 -144
- data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +0 -286
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +0 -80
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +0 -180
- data/spec/lib/license_finder/package_managers/maven_package_spec.rb +0 -63
- data/spec/lib/license_finder/package_managers/maven_spec.rb +0 -128
- data/spec/lib/license_finder/package_managers/merged_package_spec.rb +0 -60
- data/spec/lib/license_finder/package_managers/npm_package_spec.rb +0 -57
- data/spec/lib/license_finder/package_managers/npm_spec.rb +0 -253
- data/spec/lib/license_finder/package_managers/nuget_package_spec.rb +0 -9
- data/spec/lib/license_finder/package_managers/nuget_spec.rb +0 -157
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +0 -87
- data/spec/lib/license_finder/package_managers/pip_spec.rb +0 -47
- data/spec/lib/license_finder/package_managers/rebar_package_spec.rb +0 -24
- data/spec/lib/license_finder/package_managers/rebar_spec.rb +0 -50
- data/spec/lib/license_finder/package_spec.rb +0 -179
- data/spec/lib/license_finder/packages/activation_spec.rb +0 -41
- data/spec/lib/license_finder/packages/license_files_spec.rb +0 -46
- data/spec/lib/license_finder/packages/licensing_spec.rb +0 -1
- data/spec/lib/license_finder/packages/possible_license_file_spec.rb +0 -38
- data/spec/lib/license_finder/project_finder_spec.rb +0 -33
- data/spec/lib/license_finder/reports/csv_report_spec.rb +0 -70
- data/spec/lib/license_finder/reports/diff_report_spec.rb +0 -56
- data/spec/lib/license_finder/reports/html_report_spec.rb +0 -101
- data/spec/lib/license_finder/reports/markdown_report_spec.rb +0 -45
- data/spec/lib/license_finder/reports/merged_report_spec.rb +0 -21
- data/spec/lib/license_finder/reports/text_report_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -27
- data/spec/support/shared_examples_for_package_manager.rb +0 -52
- data/spec/support/stdout_helpers.rb +0 -31
- data/spec/support/test_fixtures.rb +0 -7
@@ -1,45 +1,40 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module LicenseFinder
|
4
|
-
class
|
5
|
-
|
6
|
-
def initialize(options={})
|
4
|
+
class Go15VendorExperiment < PackageManager
|
5
|
+
def initialize(options = {})
|
7
6
|
super
|
8
7
|
@full_version = options[:go_full_version]
|
9
8
|
end
|
10
9
|
|
11
10
|
def active?
|
12
|
-
|
13
|
-
|
14
|
-
(has_go_files? && package_path.exist?).tap do |is_active|
|
15
|
-
logger.active self.class, is_active
|
16
|
-
end
|
11
|
+
super && go_files_exist?
|
17
12
|
end
|
18
13
|
|
19
|
-
def
|
20
|
-
!Dir[project_path.join(
|
14
|
+
def go_files_exist?
|
15
|
+
!Dir[project_path.join('**/*.go')].empty?
|
21
16
|
end
|
22
17
|
|
23
|
-
def
|
24
|
-
project_path.join(
|
18
|
+
def possible_package_paths
|
19
|
+
[project_path.join('vendor')]
|
25
20
|
end
|
26
21
|
|
27
22
|
def project_sha(path)
|
28
23
|
Dir.chdir(path) do
|
29
|
-
|
30
|
-
raise 'git rev-list failed' unless
|
31
|
-
|
24
|
+
stdout, _stderr, status = Cmd.run('git rev-list --max-count 1 HEAD')
|
25
|
+
raise 'git rev-list failed' unless status.success?
|
26
|
+
stdout.strip
|
32
27
|
end
|
33
28
|
end
|
34
29
|
|
35
30
|
def current_packages
|
36
31
|
deps = go_list
|
37
|
-
vendored_deps = deps.select { |dep|
|
32
|
+
vendored_deps = deps.select { |dep| detected_package_path.join(dep).exist? }
|
38
33
|
vendored_deps.map do |dep|
|
39
34
|
GoPackage.from_dependency({
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
'ImportPath' => dep,
|
36
|
+
'InstallPath' => detected_package_path.join(dep),
|
37
|
+
'Rev' => 'vendored-' + project_sha(detected_package_path.join(dep))
|
43
38
|
}, nil, true)
|
44
39
|
end
|
45
40
|
end
|
@@ -57,16 +52,16 @@ module LicenseFinder
|
|
57
52
|
# with status code 1. Setting GOPATH to nil removes those warnings.
|
58
53
|
orig_gopath = ENV['GOPATH']
|
59
54
|
ENV['GOPATH'] = nil
|
60
|
-
val =
|
55
|
+
val, _stderr, status = Cmd.run('go list -f "{{join .Deps \"\n\"}}" ./...')
|
61
56
|
ENV['GOPATH'] = orig_gopath
|
62
|
-
return [] unless
|
57
|
+
return [] unless status.success?
|
63
58
|
# Select non-standard packages. `go list std` returns the list of standard
|
64
59
|
# dependencies. We then filter those dependencies out of the full list of
|
65
60
|
# dependencies.
|
66
|
-
deps = val.
|
67
|
-
|
61
|
+
deps = val.split("\n")
|
62
|
+
Cmd.run('go list std').first.split("\n").each do |std|
|
68
63
|
deps.delete_if do |dep|
|
69
|
-
dep =~
|
64
|
+
dep =~ %r{(\/|^)#{std}(\/|$)}
|
70
65
|
end
|
71
66
|
end
|
72
67
|
deps.map do |d|
|
@@ -2,22 +2,21 @@ require 'json'
|
|
2
2
|
|
3
3
|
module LicenseFinder
|
4
4
|
class GoDep < PackageManager
|
5
|
-
|
6
|
-
def initialize(options={})
|
5
|
+
def initialize(options = {})
|
7
6
|
super
|
8
7
|
@full_version = options[:go_full_version]
|
9
8
|
end
|
10
9
|
|
11
10
|
def current_packages
|
12
|
-
json = JSON.parse(
|
11
|
+
json = JSON.parse(detected_package_path.read)
|
13
12
|
# godep includes subpackages as a seperate dependency, we can de-dup that
|
14
13
|
|
15
|
-
dependencies_info = json['Deps'].map do |
|
14
|
+
dependencies_info = json['Deps'].map do |dep_json|
|
16
15
|
{
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
'Homepage' => homepage(dep_json),
|
17
|
+
'ImportPath' => import_path(dep_json),
|
18
|
+
'InstallPath' => dep_json['InstallPath'],
|
19
|
+
'Rev' => dep_json['Rev']
|
21
20
|
}
|
22
21
|
end
|
23
22
|
dependencies_info.uniq.map do |info|
|
@@ -25,18 +24,22 @@ module LicenseFinder
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
def
|
29
|
-
project_path.join('Godeps/Godeps.json')
|
27
|
+
def possible_package_paths
|
28
|
+
[project_path.join('Godeps/Godeps.json')]
|
30
29
|
end
|
31
30
|
|
32
31
|
def self.package_management_command
|
33
|
-
|
32
|
+
'godep'
|
34
33
|
end
|
35
34
|
|
36
35
|
private
|
37
36
|
|
38
37
|
def install_prefix
|
39
|
-
go_path = workspace_dir.
|
38
|
+
go_path = if workspace_dir.directory?
|
39
|
+
workspace_dir
|
40
|
+
else
|
41
|
+
Pathname(ENV['GOPATH'] || ENV['HOME'] + '/go')
|
42
|
+
end
|
40
43
|
go_path.join('src')
|
41
44
|
end
|
42
45
|
|
@@ -1,22 +1,24 @@
|
|
1
1
|
module LicenseFinder
|
2
2
|
class GoPackage < Package
|
3
|
-
def self.from_dependency(hash, prefix, full_version)
|
4
|
-
name = hash['ImportPath']
|
5
|
-
install_path = hash['InstallPath']
|
6
|
-
install_path ||= install_path(prefix.join(name))
|
7
|
-
version = full_version ? hash['Rev'] : hash['Rev'][0..6]
|
8
|
-
homepage = hash['Homepage']
|
9
|
-
self.new(name, version, {install_path: install_path, package_manager: "Go", homepage: homepage })
|
10
|
-
end
|
11
|
-
|
12
3
|
def package_manager
|
13
|
-
|
4
|
+
'Go'
|
14
5
|
end
|
15
6
|
|
16
|
-
|
7
|
+
class << self
|
8
|
+
def from_dependency(hash, prefix, full_version)
|
9
|
+
name = hash['ImportPath']
|
10
|
+
install_path = hash['InstallPath']
|
11
|
+
install_path ||= install_path(prefix.join(name))
|
12
|
+
version = full_version ? hash['Rev'] : hash['Rev'][0..6]
|
13
|
+
homepage = hash['Homepage']
|
14
|
+
new(name, version, install_path: install_path, package_manager: 'Go', homepage: homepage)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def install_path(path)
|
20
|
+
Pathname(path).cleanpath.to_s
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -5,49 +5,58 @@ module LicenseFinder
|
|
5
5
|
Submodule = Struct.new :install_path, :revision
|
6
6
|
ENVRC_REGEXP = /GOPATH|GO15VENDOREXPERIMENT/
|
7
7
|
|
8
|
-
def initialize(options={})
|
8
|
+
def initialize(options = {})
|
9
9
|
super
|
10
10
|
@full_version = options[:go_full_version]
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.package_management_command
|
14
|
+
'go'
|
15
|
+
end
|
16
|
+
|
13
17
|
def current_packages
|
14
18
|
go_list_packages = go_list
|
15
19
|
git_modules.map do |submodule|
|
16
20
|
# We are filtering the non-standard packages because the word "net"
|
17
21
|
# seems to be common that can give false positive when filtering the git submodules
|
18
|
-
import_path = go_list_packages.select
|
22
|
+
import_path = go_list_packages.select do |gp|
|
19
23
|
submodule.install_path =~ /#{repo_name(gp)}$/
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
24
|
+
end.first
|
25
|
+
next unless import_path
|
26
|
+
dependency_info = {
|
27
|
+
'ImportPath' => repo_name(import_path),
|
28
|
+
'Homepage' => repo_name(import_path),
|
29
|
+
'InstallPath' => submodule.install_path,
|
30
|
+
'Rev' => submodule.revision
|
31
|
+
}
|
32
|
+
GoPackage.from_dependency(dependency_info, nil, @full_version)
|
30
33
|
end.compact
|
31
34
|
end
|
32
35
|
|
33
|
-
def
|
34
|
-
envrc_path.dirname
|
36
|
+
def possible_package_paths
|
37
|
+
[envrc_path.dirname]
|
35
38
|
end
|
36
39
|
|
37
40
|
def active?
|
38
41
|
return false unless self.class.installed?(logger)
|
39
42
|
|
40
|
-
godep = LicenseFinder::GoDep.new(
|
43
|
+
godep = LicenseFinder::GoDep.new(project_path: Pathname(project_path))
|
41
44
|
# go workspace is only active if GoDep wasn't. There are some projects
|
42
45
|
# that will use the .envrc and have a Godep folder as well.
|
43
|
-
active = !!
|
44
|
-
active.tap
|
46
|
+
active = !!(!godep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
|
47
|
+
active.tap do |is_active|
|
48
|
+
if is_active
|
49
|
+
logger.log self.class, 'is active', color: :green
|
50
|
+
else
|
51
|
+
logger.log self.class, 'is not active'
|
52
|
+
end
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
56
|
private
|
48
57
|
|
49
|
-
def repo_name
|
50
|
-
import_path.split(
|
58
|
+
def repo_name(import_path)
|
59
|
+
import_path.split('/')[0..2].join('/')
|
51
60
|
end
|
52
61
|
|
53
62
|
def project_src
|
@@ -56,11 +65,7 @@ module LicenseFinder
|
|
56
65
|
|
57
66
|
def envrc_path
|
58
67
|
p = Pathname.new project_path
|
59
|
-
4.times.reduce([p]) { |memo, _| memo << memo.last.parent }.map { |
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.package_management_command
|
63
|
-
'go'
|
68
|
+
4.times.reduce([p]) { |memo, _| memo << memo.last.parent }.map { |path| path.join('.envrc') }.select(&:exist?).first
|
64
69
|
end
|
65
70
|
|
66
71
|
def go_list
|
@@ -72,16 +77,16 @@ module LicenseFinder
|
|
72
77
|
# with status code 1. Setting GOPATH to nil removes those warnings.
|
73
78
|
orig_gopath = ENV['GOPATH']
|
74
79
|
ENV['GOPATH'] = nil
|
75
|
-
val =
|
80
|
+
val, _stderr, status = Cmd.run('go list -f "{{join .Deps \"\n\"}}" ./...')
|
76
81
|
ENV['GOPATH'] = orig_gopath
|
77
|
-
raise 'go list failed' unless
|
82
|
+
raise 'go list failed' unless status.success?
|
78
83
|
# Select non-standard packages. `go list std` returns the list of standard
|
79
84
|
# dependencies. We then filter those dependencies out of the full list of
|
80
85
|
# dependencies.
|
81
|
-
deps = val.
|
82
|
-
|
86
|
+
deps = val.split("\n")
|
87
|
+
Cmd.run('go list std').first.split("\n").each do |std|
|
83
88
|
deps.delete_if do |dep|
|
84
|
-
dep =~
|
89
|
+
dep =~ %r{(\/|^)#{std}(\/|$)}
|
85
90
|
end
|
86
91
|
end
|
87
92
|
deps
|
@@ -89,12 +94,12 @@ module LicenseFinder
|
|
89
94
|
end
|
90
95
|
|
91
96
|
def git_modules
|
92
|
-
Dir.chdir(
|
93
|
-
result =
|
94
|
-
raise 'git submodule status failed' unless
|
95
|
-
result.
|
97
|
+
Dir.chdir(detected_package_path) do |_d|
|
98
|
+
result, _stderr, status = Cmd.run('git submodule status')
|
99
|
+
raise 'git submodule status failed' unless status.success?
|
100
|
+
result.lines.map do |l|
|
96
101
|
columns = l.split.map(&:strip)
|
97
|
-
Submodule.new File.join(
|
102
|
+
Submodule.new File.join(detected_package_path, columns[1]), columns[0]
|
98
103
|
end
|
99
104
|
end
|
100
105
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class Govendor < PackageManager
|
3
|
+
def possible_package_paths
|
4
|
+
[project_path.join('vendor', 'vendor.json')]
|
5
|
+
end
|
6
|
+
|
7
|
+
def current_packages
|
8
|
+
file = File.read(detected_package_path)
|
9
|
+
json = JSON.parse(file)
|
10
|
+
packages = json['package']
|
11
|
+
packages.map do |package|
|
12
|
+
GoPackage.from_dependency({
|
13
|
+
'ImportPath' => package['path'],
|
14
|
+
'InstallPath' => project_path.join('vendor', package['path']),
|
15
|
+
'Rev' => package['revision']
|
16
|
+
}, nil, true)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.takes_priority_over
|
21
|
+
Go15VendorExperiment
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.package_management_command
|
25
|
+
'govendor'
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.prepare_command
|
29
|
+
'govendor sync'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -4,21 +4,21 @@ require_relative 'gradle_dependency_finder'
|
|
4
4
|
|
5
5
|
module LicenseFinder
|
6
6
|
class Gradle < PackageManager
|
7
|
-
def initialize(options={})
|
7
|
+
def initialize(options = {})
|
8
8
|
super
|
9
9
|
@command = options[:gradle_command] || package_management_command
|
10
10
|
@include_groups = options[:gradle_include_groups]
|
11
11
|
end
|
12
12
|
|
13
13
|
def current_packages
|
14
|
-
WithEnv.with_env(
|
14
|
+
WithEnv.with_env('TERM' => 'dumb') do
|
15
15
|
command = "#{@command} downloadLicenses"
|
16
|
-
|
17
|
-
raise "Command '#{command}' failed to execute: #{
|
16
|
+
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
|
17
|
+
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
|
18
18
|
|
19
19
|
dependencies = GradleDependencyFinder.new(project_path).dependencies
|
20
20
|
packages = dependencies.flat_map do |xml_file|
|
21
|
-
options = {'GroupTags' => {'dependencies' => 'dependency'}}
|
21
|
+
options = { 'GroupTags' => { 'dependencies' => 'dependency' } }
|
22
22
|
contents = XmlSimple.xml_in(xml_file, options).fetch('dependency', [])
|
23
23
|
contents.map do |dep|
|
24
24
|
GradlePackage.new(dep, logger: logger, include_groups: @include_groups)
|
@@ -29,20 +29,20 @@ module LicenseFinder
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def package_management_command
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
if Platform.windows?
|
33
|
+
wrapper = 'gradlew.bat'
|
34
|
+
gradle = 'gradle.bat'
|
35
|
+
else
|
36
|
+
wrapper = './gradlew'
|
37
|
+
gradle = 'gradle'
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
File.exist?(File.join(project_path, wrapper)) ? wrapper : gradle
|
41
41
|
end
|
42
42
|
|
43
43
|
private
|
44
44
|
|
45
|
-
def
|
45
|
+
def detected_package_path
|
46
46
|
alternate_build_file = build_file_from_settings(project_path)
|
47
47
|
return alternate_build_file if alternate_build_file
|
48
48
|
|
@@ -52,7 +52,7 @@ module LicenseFinder
|
|
52
52
|
def build_file_from_settings(project_path)
|
53
53
|
settings_gradle_path = project_path.join 'settings.gradle'
|
54
54
|
|
55
|
-
return nil unless File.
|
55
|
+
return nil unless File.exist? settings_gradle_path
|
56
56
|
|
57
57
|
settings_gradle = File.read settings_gradle_path
|
58
58
|
|
@@ -60,7 +60,7 @@ module LicenseFinder
|
|
60
60
|
|
61
61
|
return nil unless match
|
62
62
|
|
63
|
-
|
63
|
+
project_path.join match[:build_file]
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module LicenseFinder
|
2
2
|
class GradlePackage < Package
|
3
|
-
def initialize(spec, options={})
|
4
|
-
name = spec[
|
5
|
-
if name.scan(
|
6
|
-
group, name, version = name.split(
|
3
|
+
def initialize(spec, options = {})
|
4
|
+
name = spec['name']
|
5
|
+
if name.scan(':').size >= 1
|
6
|
+
group, name, version = name.split(':')
|
7
7
|
else
|
8
|
-
version =
|
8
|
+
version = 'unknown'
|
9
9
|
end
|
10
10
|
|
11
11
|
name = options[:include_groups] ? "#{group}:#{name}" : name
|
12
12
|
|
13
|
-
licenses = Array(spec[
|
14
|
-
|
15
|
-
|
13
|
+
licenses = Array(spec['license'])
|
14
|
+
.map { |l| l['name'] }
|
15
|
+
.reject { |reject_name| reject_name == 'No license found' }
|
16
16
|
|
17
17
|
super(name, version, options.merge(spec_licenses: licenses))
|
18
18
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class Gvt < PackageManager
|
3
|
+
def possible_package_paths
|
4
|
+
potential_path_list = Dir.glob project_path.join('*', 'vendor', 'manifest')
|
5
|
+
potential_path_list << project_path.join('vendor', 'manifest')
|
6
|
+
potential_path_list.map { |path| Pathname path }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.package_management_command
|
10
|
+
'gvt'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.prepare_command
|
14
|
+
'gvt restore'
|
15
|
+
end
|
16
|
+
|
17
|
+
def current_packages
|
18
|
+
split_project_path = project_path.to_s.split('/')
|
19
|
+
project_root_depth = split_project_path.length - 1
|
20
|
+
|
21
|
+
split_package_path = detected_package_path.to_s.split('/')
|
22
|
+
vendor_dir_depth = split_package_path.index('vendor')
|
23
|
+
return [] if vendor_dir_depth.nil?
|
24
|
+
vendor_dir_parent_depth = vendor_dir_depth - 1
|
25
|
+
|
26
|
+
is_project_root_parent_of_vendor_dir = project_root_depth == vendor_dir_parent_depth
|
27
|
+
|
28
|
+
if is_project_root_parent_of_vendor_dir
|
29
|
+
shell_command = 'gvt list -f "{{.Importpath}} {{.Revision}} {{.Repository}}"'
|
30
|
+
path = project_path.join('vendor')
|
31
|
+
else
|
32
|
+
vendor_dir_parent = split_package_path[vendor_dir_parent_depth]
|
33
|
+
shell_command = "cd #{vendor_dir_parent} && gvt list -f \"{{.Importpath}} {{.Revision}} {{.Repository}}\""
|
34
|
+
path = project_path.join(vendor_dir_parent, 'vendor')
|
35
|
+
end
|
36
|
+
|
37
|
+
stdout, _stderr, status = Cmd.run(shell_command)
|
38
|
+
return [] unless status.success?
|
39
|
+
packages_from_output(stdout, path)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.takes_priority_over
|
43
|
+
Go15VendorExperiment
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def packages_from_output(output, path)
|
49
|
+
package_lines = output.split("\n")
|
50
|
+
package_lines.map do |package_line|
|
51
|
+
import_path, revision, repo = package_line.split
|
52
|
+
GoPackage.from_dependency({
|
53
|
+
'ImportPath' => import_path,
|
54
|
+
'InstallPath' => path.join(import_path),
|
55
|
+
'Rev' => revision,
|
56
|
+
'Homepage' => repo
|
57
|
+
}, nil, true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|