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.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +56 -0
  3. data/CHANGELOG.md +29 -2
  4. data/CONTRIBUTING.md +5 -1
  5. data/Dockerfile +33 -10
  6. data/Gemfile +2 -2
  7. data/README.md +27 -5
  8. data/Rakefile +15 -21
  9. data/ci/pipelines/pipeline.yml.erb +40 -6
  10. data/ci/pipelines/release.yml +11 -5
  11. data/ci/scripts/containerize-tests.sh +16 -0
  12. data/ci/scripts/run-rubocop.sh +8 -0
  13. data/ci/scripts/run-tests.sh +22 -0
  14. data/ci/scripts/test.ps1 +81 -0
  15. data/ci/tasks/build-windows.yml +6 -0
  16. data/ci/tasks/build.yml +2 -2
  17. data/ci/tasks/rubocop.yml +13 -0
  18. data/features/features/cli/cli_spec.rb +8 -8
  19. data/features/features/configure/add_dependencies_spec.rb +7 -7
  20. data/features/features/configure/approve_dependencies_spec.rb +15 -15
  21. data/features/features/configure/assign_licenses_spec.rb +4 -4
  22. data/features/features/configure/blacklist_licenses_spec.rb +3 -3
  23. data/features/features/configure/ignore_dependencies_spec.rb +3 -3
  24. data/features/features/configure/ignore_groups_spec.rb +4 -4
  25. data/features/features/configure/name_project_spec.rb +4 -4
  26. data/features/features/configure/set_project_path_spec.rb +2 -2
  27. data/features/features/configure/whitelist_licenses_spec.rb +4 -4
  28. data/features/features/package_managers/bower_spec.rb +3 -3
  29. data/features/features/package_managers/carthage_spec.rb +14 -0
  30. data/features/features/package_managers/cocoapods_spec.rb +3 -3
  31. data/features/features/package_managers/conan_spec.rb +11 -0
  32. data/features/features/package_managers/dep_spec.rb +15 -0
  33. data/features/features/package_managers/glide_spec.rb +14 -0
  34. data/features/features/package_managers/govendor_spec.rb +15 -0
  35. data/features/features/package_managers/gradle_spec.rb +1 -1
  36. data/features/features/package_managers/gvt_spec.rb +14 -0
  37. data/features/features/package_managers/maven_spec.rb +2 -3
  38. data/features/features/package_managers/mix_spec.rb +16 -0
  39. data/features/features/package_managers/npm_spec.rb +3 -3
  40. data/features/features/package_managers/nuget_spec.rb +4 -4
  41. data/features/features/package_managers/pip_spec.rb +2 -2
  42. data/features/features/package_managers/rebar_spec.rb +3 -3
  43. data/features/features/package_managers/yarn_spec.rb +14 -0
  44. data/features/features/report/composite_spec.rb +1 -1
  45. data/features/features/report/csv_spec.rb +3 -3
  46. data/features/features/report/diff_spec.rb +20 -10
  47. data/features/features/report/html_spec.rb +10 -10
  48. data/features/features/report/subproject_spec.rb +15 -4
  49. data/features/fixtures/Cartfile +1 -0
  50. data/features/fixtures/Podfile +1 -1
  51. data/features/fixtures/alternate-build-file-gradle/build-alt.gradle +5 -15
  52. data/features/fixtures/build.gradle +5 -15
  53. data/features/fixtures/conanfile.txt +11 -0
  54. data/features/fixtures/file-based-libs-gradle/build.gradle +5 -7
  55. data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.lock +9 -0
  56. data/features/fixtures/gopath_dep/src/foo-dep/Gopkg.toml +7 -0
  57. data/features/fixtures/gopath_dep/src/foo-dep/bar/bar.go +10 -0
  58. data/features/fixtures/gopath_dep/src/foo-dep/foo.go +7 -0
  59. data/features/fixtures/gopath_glide/src/glide.lock +9 -0
  60. data/features/fixtures/gopath_glide/src/glide.yaml +6 -0
  61. data/features/fixtures/gopath_govendor/src/vendor/vendor.json +19 -0
  62. data/features/fixtures/gopath_gvt/src/vendor/manifest +22 -0
  63. data/features/fixtures/gradle-wrapper/build.gradle +5 -15
  64. data/features/fixtures/gradle-wrapper/gradlew +6 -1
  65. data/features/fixtures/gradle-wrapper/gradlew.bat +9 -1
  66. data/features/fixtures/mix.exs +22 -0
  67. data/features/fixtures/multi-module-gradle/build.gradle +7 -15
  68. data/features/fixtures/single-module-gradle/build.gradle +5 -15
  69. data/features/support/testing_dsl.rb +155 -43
  70. data/lib/license_finder.rb +4 -3
  71. data/lib/license_finder/cli.rb +0 -3
  72. data/lib/license_finder/cli/approvals.rb +3 -3
  73. data/lib/license_finder/cli/base.rb +11 -8
  74. data/lib/license_finder/cli/blacklist.rb +7 -7
  75. data/lib/license_finder/cli/dependencies.rb +8 -8
  76. data/lib/license_finder/cli/ignored_dependencies.rb +4 -4
  77. data/lib/license_finder/cli/ignored_groups.rb +4 -4
  78. data/lib/license_finder/cli/licenses.rb +2 -2
  79. data/lib/license_finder/cli/main.rb +59 -39
  80. data/lib/license_finder/cli/makes_decisions.rb +2 -2
  81. data/lib/license_finder/cli/patched_thor.rb +6 -7
  82. data/lib/license_finder/cli/project_name.rb +5 -6
  83. data/lib/license_finder/cli/whitelist.rb +7 -7
  84. data/lib/license_finder/configuration.rb +15 -4
  85. data/lib/license_finder/core.rb +20 -4
  86. data/lib/license_finder/decision_applier.rb +0 -1
  87. data/lib/license_finder/decisions.rb +12 -14
  88. data/lib/license_finder/diff.rb +33 -31
  89. data/lib/license_finder/license.rb +13 -9
  90. data/lib/license_finder/license/definitions.rb +55 -55
  91. data/lib/license_finder/license/none_matcher.rb +1 -1
  92. data/lib/license_finder/license/template.rb +1 -1
  93. data/lib/license_finder/license/text.rb +0 -1
  94. data/lib/license_finder/license_aggregator.rb +1 -0
  95. data/lib/license_finder/logger.rb +18 -61
  96. data/lib/license_finder/package.rb +25 -11
  97. data/lib/license_finder/package_delta.rb +3 -6
  98. data/lib/license_finder/package_manager.rb +77 -34
  99. data/lib/license_finder/package_managers/bower.rb +8 -8
  100. data/lib/license_finder/package_managers/bower_package.rb +12 -12
  101. data/lib/license_finder/package_managers/bundler.rb +21 -9
  102. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  103. data/lib/license_finder/package_managers/carthage.rb +66 -0
  104. data/lib/license_finder/package_managers/carthage_package.rb +16 -0
  105. data/lib/license_finder/package_managers/cocoa_pods.rb +13 -13
  106. data/lib/license_finder/package_managers/cocoa_pods_package.rb +1 -1
  107. data/lib/license_finder/package_managers/conan.rb +26 -0
  108. data/lib/license_finder/package_managers/conan_info_parser.rb +74 -0
  109. data/lib/license_finder/package_managers/conan_package.rb +17 -0
  110. data/lib/license_finder/package_managers/dep.rb +33 -0
  111. data/lib/license_finder/package_managers/glide.rb +30 -0
  112. data/lib/license_finder/package_managers/{go_vendor.rb → go_15vendorexperiment.rb} +19 -24
  113. data/lib/license_finder/package_managers/go_dep.rb +15 -12
  114. data/lib/license_finder/package_managers/go_package.rb +15 -13
  115. data/lib/license_finder/package_managers/go_workspace.rb +39 -34
  116. data/lib/license_finder/package_managers/govendor.rb +32 -0
  117. data/lib/license_finder/package_managers/gradle.rb +16 -16
  118. data/lib/license_finder/package_managers/gradle_package.rb +8 -8
  119. data/lib/license_finder/package_managers/gvt.rb +61 -0
  120. data/lib/license_finder/package_managers/maven.rb +17 -18
  121. data/lib/license_finder/package_managers/maven_package.rb +4 -6
  122. data/lib/license_finder/package_managers/merged_package.rb +25 -2
  123. data/lib/license_finder/package_managers/mix.rb +51 -0
  124. data/lib/license_finder/package_managers/mix_package.rb +7 -0
  125. data/lib/license_finder/package_managers/npm.rb +8 -32
  126. data/lib/license_finder/package_managers/npm_package.rb +51 -48
  127. data/lib/license_finder/package_managers/nuget.rb +30 -40
  128. data/lib/license_finder/package_managers/pip.rb +11 -11
  129. data/lib/license_finder/package_managers/pip_package.rb +8 -8
  130. data/lib/license_finder/package_managers/rebar.rb +11 -11
  131. data/lib/license_finder/package_managers/yarn.rb +62 -0
  132. data/lib/license_finder/packages/activation.rb +2 -2
  133. data/lib/license_finder/packages/license_files.rb +6 -6
  134. data/lib/license_finder/packages/licensing.rb +8 -10
  135. data/lib/license_finder/packages/manual_package.rb +2 -2
  136. data/lib/license_finder/project_finder.rb +6 -5
  137. data/lib/license_finder/report.rb +1 -0
  138. data/lib/license_finder/reports/csv_report.rb +4 -4
  139. data/lib/license_finder/reports/diff_report.rb +2 -2
  140. data/lib/license_finder/reports/erb_report.rb +2 -4
  141. data/lib/license_finder/reports/html_report.rb +2 -2
  142. data/lib/license_finder/reports/markdown_report.rb +1 -1
  143. data/lib/license_finder/reports/merged_report.rb +1 -1
  144. data/lib/license_finder/reports/text_report.rb +3 -5
  145. data/lib/license_finder/shared_helpers/cmd.rb +11 -0
  146. data/lib/license_finder/version.rb +1 -1
  147. data/license_finder-2.1.2.gem +0 -0
  148. data/license_finder.gemspec +38 -38
  149. metadata +84 -118
  150. data/ci/scripts/test.sh +0 -26
  151. data/ci/tasks/create-source-archives.yml +0 -23
  152. data/spec/dummy_app/Gemfile +0 -6
  153. data/spec/fixtures/all_pms/.envrc +0 -1
  154. data/spec/fixtures/all_pms/.nuget/.keep +0 -0
  155. data/spec/fixtures/all_pms/Gemfile +0 -0
  156. data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
  157. data/spec/fixtures/all_pms/Podfile +0 -0
  158. data/spec/fixtures/all_pms/bower.json +0 -0
  159. data/spec/fixtures/all_pms/build.gradle +0 -0
  160. data/spec/fixtures/all_pms/package.json +0 -0
  161. data/spec/fixtures/all_pms/pom.xml +0 -0
  162. data/spec/fixtures/all_pms/rebar.config +0 -0
  163. data/spec/fixtures/all_pms/requirements.txt +0 -0
  164. data/spec/fixtures/all_pms/vendor/.gitkeep +0 -0
  165. data/spec/fixtures/composite/Gemfile +0 -0
  166. data/spec/fixtures/composite/nested_project/.envrc +0 -8
  167. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +0 -16
  168. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +0 -5
  169. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +0 -6
  170. data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
  171. data/spec/fixtures/composite/project1/Gemfile +0 -0
  172. data/spec/fixtures/composite/project2/package.json +0 -0
  173. data/spec/fixtures/config/license_finder.yml +0 -5
  174. data/spec/fixtures/license_directory/COPYING +0 -1
  175. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -1
  176. data/spec/fixtures/license_directory/LICENSE/lib/unrelated.txt +0 -2
  177. data/spec/fixtures/license_names/COPYING.txt +0 -1
  178. data/spec/fixtures/license_names/LICENSE +0 -1
  179. data/spec/fixtures/license_names/Licence.rdoc +0 -1
  180. data/spec/fixtures/license_names/Mit-License +0 -1
  181. data/spec/fixtures/license_names/README.rdoc +0 -1
  182. data/spec/fixtures/nested_gem/vendor/LICENSE +0 -1
  183. data/spec/fixtures/npm-circular-dependencies/npm-list.json +0 -5339
  184. data/spec/fixtures/npm-circular-dependencies/package.json +0 -5
  185. data/spec/fixtures/npm-circular-licenses/npm-list.json +0 -7597
  186. data/spec/fixtures/npm-circular-licenses/package.json +0 -23
  187. data/spec/fixtures/npm-licenses-string/npm-list.json +0 -7597
  188. data/spec/fixtures/npm-licenses-string/package.json +0 -23
  189. data/spec/fixtures/npm-recursive-dependencies/npm-list.json +0 -5158
  190. data/spec/fixtures/npm-recursive-dependencies/package.json +0 -15
  191. data/spec/fixtures/npm-stack-too-deep/npm-list.json +0 -13464
  192. data/spec/fixtures/npm-stack-too-deep/package.json +0 -5
  193. data/spec/fixtures/utf8_gem/README +0 -210
  194. data/spec/lib/license_finder/cli/approvals_spec.rb +0 -71
  195. data/spec/lib/license_finder/cli/blacklist_spec.rb +0 -58
  196. data/spec/lib/license_finder/cli/dependencies_spec.rb +0 -73
  197. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +0 -47
  198. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +0 -40
  199. data/spec/lib/license_finder/cli/licenses_spec.rb +0 -60
  200. data/spec/lib/license_finder/cli/main_spec.rb +0 -243
  201. data/spec/lib/license_finder/cli/project_name_spec.rb +0 -40
  202. data/spec/lib/license_finder/cli/whitelist_spec.rb +0 -58
  203. data/spec/lib/license_finder/configuration_spec.rb +0 -115
  204. data/spec/lib/license_finder/core_spec.rb +0 -54
  205. data/spec/lib/license_finder/decision_applier_spec.rb +0 -219
  206. data/spec/lib/license_finder/decisions_spec.rb +0 -408
  207. data/spec/lib/license_finder/diff_spec.rb +0 -129
  208. data/spec/lib/license_finder/license/definitions_spec.rb +0 -177
  209. data/spec/lib/license_finder/license_aggregator_spec.rb +0 -61
  210. data/spec/lib/license_finder/license_spec.rb +0 -106
  211. data/spec/lib/license_finder/package_delta_spec.rb +0 -18
  212. data/spec/lib/license_finder/package_manager_spec.rb +0 -62
  213. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +0 -71
  214. data/spec/lib/license_finder/package_managers/bower_spec.rb +0 -39
  215. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +0 -35
  216. data/spec/lib/license_finder/package_managers/bundler_spec.rb +0 -56
  217. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +0 -48
  218. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +0 -59
  219. data/spec/lib/license_finder/package_managers/go_dep_spec.rb +0 -126
  220. data/spec/lib/license_finder/package_managers/go_package_spec.rb +0 -33
  221. data/spec/lib/license_finder/package_managers/go_vendor_spec.rb +0 -144
  222. data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +0 -286
  223. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +0 -80
  224. data/spec/lib/license_finder/package_managers/gradle_spec.rb +0 -180
  225. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +0 -63
  226. data/spec/lib/license_finder/package_managers/maven_spec.rb +0 -128
  227. data/spec/lib/license_finder/package_managers/merged_package_spec.rb +0 -60
  228. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +0 -57
  229. data/spec/lib/license_finder/package_managers/npm_spec.rb +0 -253
  230. data/spec/lib/license_finder/package_managers/nuget_package_spec.rb +0 -9
  231. data/spec/lib/license_finder/package_managers/nuget_spec.rb +0 -157
  232. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +0 -87
  233. data/spec/lib/license_finder/package_managers/pip_spec.rb +0 -47
  234. data/spec/lib/license_finder/package_managers/rebar_package_spec.rb +0 -24
  235. data/spec/lib/license_finder/package_managers/rebar_spec.rb +0 -50
  236. data/spec/lib/license_finder/package_spec.rb +0 -179
  237. data/spec/lib/license_finder/packages/activation_spec.rb +0 -41
  238. data/spec/lib/license_finder/packages/license_files_spec.rb +0 -46
  239. data/spec/lib/license_finder/packages/licensing_spec.rb +0 -1
  240. data/spec/lib/license_finder/packages/possible_license_file_spec.rb +0 -38
  241. data/spec/lib/license_finder/project_finder_spec.rb +0 -33
  242. data/spec/lib/license_finder/reports/csv_report_spec.rb +0 -70
  243. data/spec/lib/license_finder/reports/diff_report_spec.rb +0 -56
  244. data/spec/lib/license_finder/reports/html_report_spec.rb +0 -101
  245. data/spec/lib/license_finder/reports/markdown_report_spec.rb +0 -45
  246. data/spec/lib/license_finder/reports/merged_report_spec.rb +0 -21
  247. data/spec/lib/license_finder/reports/text_report_spec.rb +0 -43
  248. data/spec/spec_helper.rb +0 -27
  249. data/spec/support/shared_examples_for_package_manager.rb +0 -52
  250. data/spec/support/stdout_helpers.rb +0 -31
  251. data/spec/support/test_fixtures.rb +0 -7
@@ -1,9 +1,9 @@
1
- require "xmlsimple"
2
- require_relative "maven_dependency_finder"
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 and !@ignored_groups.empty?
16
- command += " #{@maven_options}" if !@maven_options.nil?
17
- output, success = Dir.chdir(project_path) { capture(command) }
18
- raise "Command '#{command}' failed to execute: #{output}" unless success
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' => ['license', 'dependency']
24
+ 'ForceArray' => %w[license dependency]
25
25
  }
26
- contents = XmlSimple.xml_in(xml, options)["dependencies"]
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
- wrapper = 'mvnw.cmd'
37
- maven = 'mvn'
38
- else
39
- wrapper = './mvnw'
40
- maven = 'mvn'
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 package_path
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["version"],
9
+ spec['version'],
12
10
  options.merge(
13
- spec_licenses: Array(spec["licenses"]).map { |l| l["name"] }
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(method_name)
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
@@ -0,0 +1,7 @@
1
+ module LicenseFinder
2
+ class MixPackage < Package
3
+ def package_manager
4
+ 'Mix'
5
+ end
6
+ end
7
+ 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, package_path)
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
- def package_path
17
- project_path.join('package.json')
18
- end
14
+ private
19
15
 
20
- def run_command_with_tempfile_buffer(command, &block)
21
- tempfile = Tempfile.new 'npm-list.json'
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::package_management_command} list --json --long"
34
- output, json, success = run_command_with_tempfile_buffer(command, &:parse_json_safely)
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
- String.class_eval do
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
- def self.packages_from_json(npm_json, package_path)
6
- @packages = NpmPackage.flattened_dependencies(npm_json)
7
- package_json = PackageJson.new(package_path)
8
- populate_groups(package_json)
9
- @packages.values
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(dependencies devDependencies)
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 "rexml/document"
1
+ require 'rexml/document'
2
2
  require 'zip'
3
3
 
4
4
  module LicenseFinder
5
5
  class Nuget < PackageManager
6
- def package_path
7
- path = project_path.join("vendor/*.nupkg")
8
- nuget_dir = Dir[path].map{|pkg| File.dirname(pkg)}.uniq
9
- if nuget_dir.length == 0
10
- path = project_path.join(".nuget")
11
- if File.directory?(path)
12
- path
13
- else
14
- project_path.join("packages")
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("**", "packages.config"), File::FNM_DOTMATCH).map do |d|
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.reduce({}) do |memo, dep|
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 if !memo[dep.name].groups.include? 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 dep
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 + ".nuspec")
54
+ content = zipfile.read(dep.name + '.nuspec')
44
55
  xml = REXML::Document.new(content)
45
- REXML::XPath.match(xml,"//metadata//licenseUrl").map(&:get_text)
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
-