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,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require 'xmlsimple'
|
2
|
+
require_relative 'maven_dependency_finder'
|
3
3
|
|
4
4
|
module LicenseFinder
|
5
5
|
class Maven < PackageManager
|
6
|
-
def initialize(options={})
|
6
|
+
def initialize(options = {})
|
7
7
|
super
|
8
8
|
@ignored_groups = options[:ignored_groups]
|
9
9
|
@include_groups = options[:maven_include_groups]
|
@@ -12,18 +12,18 @@ module LicenseFinder
|
|
12
12
|
|
13
13
|
def current_packages
|
14
14
|
command = "#{package_management_command} org.codehaus.mojo:license-maven-plugin:download-licenses"
|
15
|
-
command += " -Dlicense.excludedScopes=#{@ignored_groups.to_a.join(',')}" if @ignored_groups
|
16
|
-
command += " #{@maven_options}"
|
17
|
-
|
18
|
-
raise "Command '#{command}' failed to execute: #{
|
15
|
+
command += " -Dlicense.excludedScopes=#{@ignored_groups.to_a.join(',')}" if @ignored_groups && !@ignored_groups.empty?
|
16
|
+
command += " #{@maven_options}" unless @maven_options.nil?
|
17
|
+
_stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
|
18
|
+
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
|
19
19
|
|
20
20
|
dependencies = MavenDependencyFinder.new(project_path).dependencies
|
21
21
|
packages = dependencies.flat_map do |xml|
|
22
22
|
options = {
|
23
23
|
'GroupTags' => { 'licenses' => 'license', 'dependencies' => 'dependency' },
|
24
|
-
'ForceArray' => [
|
24
|
+
'ForceArray' => %w[license dependency]
|
25
25
|
}
|
26
|
-
contents = XmlSimple.xml_in(xml, options)[
|
26
|
+
contents = XmlSimple.xml_in(xml, options)['dependencies']
|
27
27
|
contents.map do |dep|
|
28
28
|
MavenPackage.new(dep, logger: logger, include_groups: @include_groups)
|
29
29
|
end
|
@@ -32,21 +32,20 @@ module LicenseFinder
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def package_management_command
|
35
|
-
if Platform.windows?
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
35
|
+
wrapper = if Platform.windows?
|
36
|
+
'mvnw.cmd'
|
37
|
+
else
|
38
|
+
'./mvnw'
|
39
|
+
end
|
40
|
+
maven = 'mvn'
|
42
41
|
|
43
42
|
File.exist?(File.join(project_path, wrapper)) ? wrapper : maven
|
44
43
|
end
|
45
44
|
|
46
45
|
private
|
47
46
|
|
48
|
-
def
|
49
|
-
project_path.join('pom.xml')
|
47
|
+
def possible_package_paths
|
48
|
+
[project_path.join('pom.xml')]
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|
@@ -1,16 +1,14 @@
|
|
1
1
|
module LicenseFinder
|
2
2
|
class MavenPackage < Package
|
3
|
-
def initialize(spec, options={})
|
3
|
+
def initialize(spec, options = {})
|
4
4
|
name = spec['artifactId']
|
5
|
-
if options[:include_groups]
|
6
|
-
name = "#{spec['groupId']}:#{name}"
|
7
|
-
end
|
5
|
+
name = "#{spec['groupId']}:#{name}" if options[:include_groups]
|
8
6
|
|
9
7
|
super(
|
10
8
|
name,
|
11
|
-
spec[
|
9
|
+
spec['version'],
|
12
10
|
options.merge(
|
13
|
-
spec_licenses: Array(spec[
|
11
|
+
spec_licenses: Array(spec['licenses']).map { |l| l['name'] }
|
14
12
|
)
|
15
13
|
)
|
16
14
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module LicenseFinder
|
2
2
|
class MergedPackage
|
3
|
-
|
4
3
|
attr_reader :dependency
|
5
4
|
|
6
5
|
def initialize(dependency, subproject_paths)
|
@@ -24,6 +23,30 @@ module LicenseFinder
|
|
24
23
|
dependency.install_path
|
25
24
|
end
|
26
25
|
|
26
|
+
def authors
|
27
|
+
dependency.authors
|
28
|
+
end
|
29
|
+
|
30
|
+
def homepage
|
31
|
+
dependency.homepage
|
32
|
+
end
|
33
|
+
|
34
|
+
def summary
|
35
|
+
dependency.summary
|
36
|
+
end
|
37
|
+
|
38
|
+
def description
|
39
|
+
dependency.description
|
40
|
+
end
|
41
|
+
|
42
|
+
def groups
|
43
|
+
dependency.groups
|
44
|
+
end
|
45
|
+
|
46
|
+
def package_manager
|
47
|
+
dependency.package_manager
|
48
|
+
end
|
49
|
+
|
27
50
|
def subproject_paths
|
28
51
|
@subproject_paths.map { |p| p.expand_path.to_s }
|
29
52
|
end
|
@@ -40,7 +63,7 @@ module LicenseFinder
|
|
40
63
|
dependency.hash
|
41
64
|
end
|
42
65
|
|
43
|
-
def method_missing(
|
66
|
+
def method_missing(_method_name)
|
44
67
|
nil
|
45
68
|
end
|
46
69
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module LicenseFinder
|
2
|
+
class Mix < PackageManager
|
3
|
+
def initialize(options = {})
|
4
|
+
super
|
5
|
+
@command = options[:mix_command] || Mix.package_management_command
|
6
|
+
@deps_path = Pathname(options[:mix_deps_dir] || 'deps')
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_packages
|
10
|
+
mix_output.map do |name, version|
|
11
|
+
MixPackage.new(
|
12
|
+
name,
|
13
|
+
version,
|
14
|
+
install_path: @deps_path.join(name),
|
15
|
+
logger: logger
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.package_management_command
|
21
|
+
'mix'
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def mix_output
|
27
|
+
command = "#{@command} deps"
|
28
|
+
stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
|
29
|
+
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
|
30
|
+
|
31
|
+
stdout
|
32
|
+
.each_line
|
33
|
+
.map(&:strip)
|
34
|
+
.select { |line| line_of_interest? line }
|
35
|
+
.each_slice(2).to_a
|
36
|
+
.map { |line1, line2| [line1.split(' ')[1], resolve_version(line2)] }
|
37
|
+
end
|
38
|
+
|
39
|
+
def line_of_interest?(line)
|
40
|
+
line.start_with?('* ', 'locked at', 'the dependency is not available')
|
41
|
+
end
|
42
|
+
|
43
|
+
def resolve_version(line)
|
44
|
+
line =~ /locked at ([^\s]+)/ ? Regexp.last_match(1) : line
|
45
|
+
end
|
46
|
+
|
47
|
+
def possible_package_paths
|
48
|
+
[project_path.join('mix.exs')]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -4,49 +4,25 @@ require 'tempfile'
|
|
4
4
|
module LicenseFinder
|
5
5
|
class NPM < PackageManager
|
6
6
|
def current_packages
|
7
|
-
NpmPackage.packages_from_json(npm_json,
|
7
|
+
NpmPackage.packages_from_json(npm_json, detected_package_path)
|
8
8
|
end
|
9
9
|
|
10
|
-
private
|
11
|
-
|
12
10
|
def self.package_management_command
|
13
11
|
'npm'
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
project_path.join('package.json')
|
18
|
-
end
|
14
|
+
private
|
19
15
|
|
20
|
-
def
|
21
|
-
|
22
|
-
begin
|
23
|
-
output, success = Dir.chdir(project_path) { capture("#{command} > #{tempfile.path}") }
|
24
|
-
result = block.call(File.read(tempfile.path))
|
25
|
-
ensure
|
26
|
-
tempfile.close
|
27
|
-
tempfile.unlink
|
28
|
-
end
|
29
|
-
[output, result, success]
|
16
|
+
def possible_package_paths
|
17
|
+
[project_path.join('package.json')]
|
30
18
|
end
|
31
19
|
|
32
20
|
def npm_json
|
33
|
-
command = "#{NPM
|
34
|
-
|
35
|
-
unless success
|
36
|
-
if json
|
37
|
-
$stderr.puts "Command '#{command}' returned an error but parsing succeeded."
|
38
|
-
else
|
39
|
-
raise "Command '#{command}' failed to execute: #{output}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
json
|
43
|
-
end
|
44
|
-
end
|
21
|
+
command = "#{NPM.package_management_command} list --json --long"
|
22
|
+
stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
|
23
|
+
raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
|
45
24
|
|
46
|
-
|
47
|
-
def parse_json_safely
|
48
|
-
JSON.parse(self) rescue nil
|
25
|
+
JSON.parse(stdout)
|
49
26
|
end
|
50
27
|
end
|
51
|
-
|
52
28
|
end
|
@@ -2,11 +2,56 @@ module LicenseFinder
|
|
2
2
|
class NpmPackage < Package
|
3
3
|
attr_accessor :identifier, :dependencies, :groups, :json
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
class << self
|
6
|
+
def packages_from_json(npm_json, package_path)
|
7
|
+
@packages = flattened_dependencies(npm_json)
|
8
|
+
package_json = PackageJson.new(package_path)
|
9
|
+
populate_groups(package_json)
|
10
|
+
@packages.values
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def flattened_dependencies(npm_json, existing_packages = {})
|
16
|
+
identifier = Identifier.from_hash npm_json
|
17
|
+
if existing_packages[identifier].nil?
|
18
|
+
existing_packages[identifier] = NpmPackage.new(npm_json) if identifier
|
19
|
+
npm_json.fetch('dependencies', {}).values.map do |d|
|
20
|
+
flattened_dependencies(d, existing_packages)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
duplicate_package = NpmPackage.new(npm_json)
|
24
|
+
unless existing_packages[identifier].dependencies.include?(duplicate_package.dependencies)
|
25
|
+
existing_packages[identifier].dependencies |= duplicate_package.dependencies
|
26
|
+
npm_json.fetch('dependencies', {}).values.map do |d|
|
27
|
+
flattened_dependencies(d, existing_packages)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
existing_packages
|
32
|
+
end
|
33
|
+
|
34
|
+
def populate_groups(package_json)
|
35
|
+
package_json.groups.each do |group|
|
36
|
+
group.package_names.each do |package_name|
|
37
|
+
@packages.each_key do |identifier|
|
38
|
+
next unless identifier.name == package_name
|
39
|
+
dependency = @packages[identifier]
|
40
|
+
dependency.groups |= [group.name]
|
41
|
+
populate_child_groups(dependency, @packages)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def populate_child_groups(dependency, packages, populated_ids = [])
|
48
|
+
dependency.dependencies.each do |id|
|
49
|
+
next if populated_ids.include? id
|
50
|
+
populated_ids.push id
|
51
|
+
packages[id].groups |= dependency.groups
|
52
|
+
populate_child_groups(packages[id], packages, populated_ids)
|
53
|
+
end
|
54
|
+
end
|
10
55
|
end
|
11
56
|
|
12
57
|
def initialize(npm_json)
|
@@ -36,45 +81,6 @@ module LicenseFinder
|
|
36
81
|
|
37
82
|
private
|
38
83
|
|
39
|
-
def self.flattened_dependencies(npm_json, existing_packages={})
|
40
|
-
identifier = Identifier.from_hash npm_json
|
41
|
-
if existing_packages[identifier].nil?
|
42
|
-
existing_packages[identifier] = NpmPackage.new(npm_json) if identifier
|
43
|
-
npm_json.fetch('dependencies', {}).values.map { |d| NpmPackage.flattened_dependencies(d, existing_packages) }
|
44
|
-
else
|
45
|
-
duplicate_package = NpmPackage.new(npm_json)
|
46
|
-
unless existing_packages[identifier].dependencies.include?(duplicate_package.dependencies)
|
47
|
-
existing_packages[identifier].dependencies |= duplicate_package.dependencies
|
48
|
-
npm_json.fetch('dependencies', {}).values.map { |d| NpmPackage.flattened_dependencies(d, existing_packages) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
existing_packages
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.populate_groups(package_json)
|
55
|
-
package_json.groups.each do |group|
|
56
|
-
group.package_names.each do |package_name|
|
57
|
-
@packages.keys.each do |identifier|
|
58
|
-
if identifier.name == package_name
|
59
|
-
dependency = @packages[identifier]
|
60
|
-
dependency.groups |= [group.name]
|
61
|
-
NpmPackage.populate_child_groups(dependency, @packages)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.populate_child_groups(dependency, packages, populated_ids = [])
|
69
|
-
dependency.dependencies.each do |id|
|
70
|
-
unless populated_ids.include? id
|
71
|
-
populated_ids.push id
|
72
|
-
packages[id].groups |= dependency.groups
|
73
|
-
populate_child_groups(packages[id], packages, populated_ids)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
84
|
def deps_from_json
|
79
85
|
@json.fetch('dependencies', {}).values.map { |dep| Identifier.from_hash(dep) }.compact
|
80
86
|
end
|
@@ -114,7 +120,6 @@ module LicenseFinder
|
|
114
120
|
def to_s
|
115
121
|
"#{@name} - #{@version}"
|
116
122
|
end
|
117
|
-
|
118
123
|
end
|
119
124
|
|
120
125
|
class Group
|
@@ -132,12 +137,11 @@ module LicenseFinder
|
|
132
137
|
def to_s
|
133
138
|
@name
|
134
139
|
end
|
135
|
-
|
136
140
|
end
|
137
141
|
|
138
142
|
class PackageJson
|
139
143
|
attr_reader :groups
|
140
|
-
DEPENDENCY_GROUPS = %w
|
144
|
+
DEPENDENCY_GROUPS = %w[dependencies devDependencies].freeze
|
141
145
|
|
142
146
|
def initialize(path)
|
143
147
|
json = JSON.parse(File.read(path), max_nesting: false)
|
@@ -147,7 +151,6 @@ module LicenseFinder
|
|
147
151
|
def groups_for(identifier)
|
148
152
|
@groups.select { |g| g.include? identifier }.map(&:name)
|
149
153
|
end
|
150
|
-
|
151
154
|
end
|
152
155
|
end
|
153
156
|
end
|
@@ -1,25 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require 'rexml/document'
|
2
2
|
require 'zip'
|
3
3
|
|
4
4
|
module LicenseFinder
|
5
5
|
class Nuget < PackageManager
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
class Assembly
|
7
|
+
attr_reader :name, :path
|
8
|
+
def initialize(path, name)
|
9
|
+
@path = path
|
10
|
+
@name = name
|
11
|
+
end
|
12
|
+
|
13
|
+
def dependencies
|
14
|
+
xml = REXML::Document.new(File.read(path.join('packages.config')))
|
15
|
+
packages = REXML::XPath.match(xml, '//package')
|
16
|
+
packages.map do |p|
|
17
|
+
attrs = p.attributes
|
18
|
+
Dependency.new(attrs['id'], attrs['version'], name)
|
15
19
|
end
|
16
|
-
else
|
17
|
-
Pathname(nuget_dir.first)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
Dependency = Struct.new(:name, :version, :assembly)
|
24
|
+
|
25
|
+
def possible_package_paths
|
26
|
+
path = project_path.join('vendor/*.nupkg')
|
27
|
+
nuget_dir = Dir[path].map { |pkg| File.dirname(pkg) }.uniq
|
28
|
+
possible_paths = [project_path.join('.nuget'), project_path.join('packages')]
|
29
|
+
possible_paths.unshift(Pathname(nuget_dir.first)) unless nuget_dir.empty?
|
30
|
+
possible_paths
|
31
|
+
end
|
32
|
+
|
21
33
|
def assemblies
|
22
|
-
Dir.glob(project_path.join(
|
34
|
+
Dir.glob(project_path.join('**', 'packages.config'), File::FNM_DOTMATCH).map do |d|
|
23
35
|
path = Pathname.new(d).dirname
|
24
36
|
name = path.basename.to_s
|
25
37
|
Assembly.new path, name
|
@@ -27,48 +39,26 @@ module LicenseFinder
|
|
27
39
|
end
|
28
40
|
|
29
41
|
def current_packages
|
30
|
-
dependencies.
|
42
|
+
dependencies.each_with_object({}) do |dep, memo|
|
31
43
|
licenses = license_urls(dep)
|
32
44
|
memo[dep.name] ||= NugetPackage.new(dep.name, dep.version, spec_licenses: licenses)
|
33
|
-
memo[dep.name].groups << dep.assembly
|
34
|
-
memo
|
45
|
+
memo[dep.name].groups << dep.assembly unless memo[dep.name].groups.include? dep.assembly
|
35
46
|
end.values
|
36
47
|
end
|
37
48
|
|
38
|
-
def license_urls
|
49
|
+
def license_urls(dep)
|
39
50
|
files = Dir["**/#{dep.name}.#{dep.version}.nupkg"]
|
40
51
|
return nil if files.empty?
|
41
52
|
file = files.first
|
42
53
|
Zip::File.open file do |zipfile|
|
43
|
-
content = zipfile.read(dep.name +
|
54
|
+
content = zipfile.read(dep.name + '.nuspec')
|
44
55
|
xml = REXML::Document.new(content)
|
45
|
-
REXML::XPath.match(xml,
|
56
|
+
REXML::XPath.match(xml, '//metadata//licenseUrl').map(&:get_text)
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
49
60
|
def dependencies
|
50
61
|
assemblies.flat_map(&:dependencies)
|
51
62
|
end
|
52
|
-
|
53
|
-
class Assembly
|
54
|
-
attr_reader :name, :path
|
55
|
-
def initialize(path, name)
|
56
|
-
@path = path
|
57
|
-
@name = name
|
58
|
-
end
|
59
|
-
|
60
|
-
def dependencies
|
61
|
-
xml = REXML::Document.new(File.read(path.join("packages.config")))
|
62
|
-
packages = REXML::XPath.match(xml, "//package")
|
63
|
-
packages.map do |p|
|
64
|
-
attrs = p.attributes
|
65
|
-
Dependency.new(attrs["id"], attrs["version"], self.name)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class Dependency < Struct.new(:name, :version, :assembly)
|
71
|
-
end
|
72
63
|
end
|
73
64
|
end
|
74
|
-
|