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,7 +1,7 @@
1
1
  module LicenseFinder
2
2
  class License
3
3
  class NoneMatcher
4
- def matches_text?(text)
4
+ def matches_text?(_text)
5
5
  false
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module LicenseFinder
2
2
  class License
3
3
  class Template
4
- TEMPLATE_PATH = ROOT_PATH.join("license", "templates")
4
+ TEMPLATE_PATH = ROOT_PATH.join('license', 'templates')
5
5
 
6
6
  def self.named(name)
7
7
  new TEMPLATE_PATH.join("#{name}.txt").read
@@ -17,4 +17,3 @@ module LicenseFinder
17
17
  end
18
18
  end
19
19
  end
20
-
@@ -18,6 +18,7 @@ module LicenseFinder
18
18
  def aggregate_packages
19
19
  @subprojects.flat_map do |project_path|
20
20
  finder = LicenseFinder::Core.new(@license_finder_config.merge(project_path: project_path))
21
+ finder.prepare_projects if @license_finder_config[:prepare]
21
22
  finder.acknowledged.map { |dep| MergedPackage.new(dep, [project_path]) }
22
23
  end
23
24
  end
@@ -1,6 +1,6 @@
1
1
  module LicenseFinder
2
2
  module Logger
3
- def self.new options={}
3
+ def self.new(options = {})
4
4
  klass = if options[:quiet]
5
5
  Quiet
6
6
  elsif options[:debug]
@@ -11,79 +11,36 @@ module LicenseFinder
11
11
  klass.new
12
12
  end
13
13
 
14
- class Base
15
- def installed package_manager, is_installed
16
- if String === is_installed
17
- log package_manager, is_installed
18
- elsif is_installed
19
- log package_manager, Logger.green("is installed")
20
- else
21
- log package_manager, Logger.red("is not installed")
22
- end
23
- end
24
-
25
- def active package_manager, is_active
26
- if is_active
27
- log package_manager, Logger.green("is active")
28
- else
29
- log package_manager, "is not active"
30
- end
31
- end
32
-
33
- def package package_manager, package
34
- dependencies = package.children
35
- if dependencies.empty?
36
- log package_manager, sprintf("package '%s' has no dependencies", package.name)
37
- else
38
- log package_manager, sprintf("package '%s' has dependencies:", package.name)
39
- dependencies.each do |dep|
40
- log package_manager, sprintf("- %s", dep)
41
- end
42
- end
43
- end
44
-
45
- def activation activation
46
- preamble = sprintf("package %s:", activation.package.name)
47
- if activation.sources.empty?
48
- log activation.package.class, sprintf("%s no licenses found", preamble)
49
- else
50
- activation.sources.each do |source|
51
- log activation.package.class, sprintf("%s found license '%s' %s", preamble, activation.license.name, source)
52
- end
53
- end
54
- end
55
-
56
- def log prefix, string
57
- raise NotImplementedError, "#log must be implemented"
14
+ def self.colorize(string, color)
15
+ case color
16
+ when :red
17
+ "\e[31m#{string}\e[0m"
18
+ when :green
19
+ "\e[32m#{string}\e[0m"
20
+ else
21
+ string
58
22
  end
59
23
  end
60
24
 
61
- def self.green string
62
- colorize 32, string
63
- end
64
-
65
- def self.red string
66
- colorize 31, string
67
- end
68
-
69
- def self.colorize color_code, string
70
- "\e[#{color_code}m#{string}\e[0m"
25
+ class Base
26
+ def log(_prefix, _string, _options = {})
27
+ raise NotImplementedError, '#log must be implemented'
28
+ end
71
29
  end
72
30
 
73
31
  class Quiet < Base
74
- def log prefix, string
75
- end
32
+ def log(prefix, string, options = {}); end
76
33
  end
77
34
 
78
35
  class Progress < Base
79
- def log prefix, string
80
- print(".") && $stdout.flush
36
+ def log(_prefix, _string, _options = {})
37
+ print('.') && $stdout.flush
81
38
  end
82
39
  end
83
40
 
84
41
  class Verbose < Base
85
- def log prefix, string
86
- printf("%s: %s\n", prefix, string)
42
+ def log(prefix, string, options = {})
43
+ printf("%s: %s\n", prefix, Logger.colorize(string, options[:color]))
87
44
  end
88
45
  end
89
46
 
@@ -18,27 +18,27 @@ module LicenseFinder
18
18
  attr_reader :logger
19
19
 
20
20
  def self.license_names_from_standard_spec(spec)
21
- licenses = spec["licenses"] || [spec["license"]].compact
21
+ licenses = spec['licenses'] || [spec['license']].compact
22
22
  licenses = [licenses] unless licenses.is_a?(Array)
23
23
  licenses.map do |license|
24
24
  if license.is_a? Hash
25
- license["type"]
25
+ license['type']
26
26
  else
27
27
  license
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
- def initialize(name, version = nil, options={})
32
+ def initialize(name, version = nil, options = {})
33
33
  @logger = options[:logger] || Core.default_logger
34
34
 
35
35
  ## DESCRIPTION
36
36
  @name = name
37
37
  @version = version
38
- @authors = options[:authors] || ""
39
- @summary = options[:summary] || ""
40
- @description = options[:description] || ""
41
- @homepage = options[:homepage] || ""
38
+ @authors = options[:authors] || ''
39
+ @summary = options[:summary] || ''
40
+ @description = options[:description] || ''
41
+ @homepage = options[:homepage] || ''
42
42
  @children = options[:children] || []
43
43
  @parents = Set.new # will be figured out later by package manager
44
44
  @groups = options[:groups] || []
@@ -100,7 +100,7 @@ module LicenseFinder
100
100
 
101
101
  def <=>(other)
102
102
  eq_name = name <=> other.name
103
- return eq_name unless eq_name == 0
103
+ return eq_name unless eq_name.zero?
104
104
  version <=> other.version
105
105
  end
106
106
 
@@ -109,7 +109,7 @@ module LicenseFinder
109
109
  end
110
110
 
111
111
  def hash
112
- [name,version].hash
112
+ [name, version].hash
113
113
  end
114
114
 
115
115
  ## LICENSING
@@ -123,7 +123,7 @@ module LicenseFinder
123
123
 
124
124
  def activations
125
125
  licensing.activations.tap do |activations|
126
- activations.each { |activation| logger.activation(activation) }
126
+ activations.each { |activation| log_activation activation }
127
127
  end
128
128
  end
129
129
 
@@ -146,12 +146,23 @@ module LicenseFinder
146
146
  end
147
147
 
148
148
  def package_manager
149
- "unknown"
149
+ 'unknown'
150
150
  end
151
151
 
152
152
  def missing?
153
153
  @missing
154
154
  end
155
+
156
+ def log_activation(activation)
157
+ preamble = format('package %s:', activation.package.name)
158
+ if activation.sources.empty?
159
+ logger.log activation.package.class, format('%s no licenses found', preamble)
160
+ else
161
+ activation.sources.each do |source|
162
+ logger.log activation.package.class, format("%s found license '%s' %s", preamble, activation.license.name, source)
163
+ end
164
+ end
165
+ end
155
166
  end
156
167
  end
157
168
 
@@ -164,6 +175,9 @@ require 'license_finder/package_managers/npm_package'
164
175
  require 'license_finder/package_managers/maven_package'
165
176
  require 'license_finder/package_managers/gradle_package'
166
177
  require 'license_finder/package_managers/cocoa_pods_package'
178
+ require 'license_finder/package_managers/carthage_package'
167
179
  require 'license_finder/package_managers/rebar_package'
180
+ require 'license_finder/package_managers/mix_package'
168
181
  require 'license_finder/package_managers/merged_package'
169
182
  require 'license_finder/package_managers/nuget_package'
183
+ require 'license_finder/package_managers/conan_package'
@@ -1,6 +1,6 @@
1
1
  module LicenseFinder
2
2
  class PackageDelta
3
- STATUSES = [:added, :removed, :unchanged]
3
+ STATUSES = %i[added removed unchanged].freeze
4
4
 
5
5
  def initialize(status, current_package, previous_package)
6
6
  @status = status
@@ -16,14 +16,11 @@ module LicenseFinder
16
16
  pick_package.version
17
17
  end
18
18
 
19
-
20
19
  def subproject_paths
21
20
  pick_package.subproject_paths
22
21
  end
23
22
 
24
- def status
25
- @status
26
- end
23
+ attr_reader :status
27
24
 
28
25
  def licenses
29
26
  pick_package.licenses
@@ -33,7 +30,7 @@ module LicenseFinder
33
30
  pick_package.class == MergedPackage
34
31
  end
35
32
 
36
- def method_missing(method_name)
33
+ def method_missing(_method_name)
37
34
  nil
38
35
  end
39
36
 
@@ -9,72 +9,107 @@ module LicenseFinder
9
9
  # Additional guidelines are:
10
10
  #
11
11
  # - implement #current_packages, to return a list of `Package`s this package manager is tracking
12
- # - implement #package_path, a `Pathname` which, if the file exists, indicates the package manager is in use on this project
13
- #
12
+ # - implement #possible_package_paths, an array of `Pathname`s which are the possible locations which contain a configuration file/folder indicating the package manager is in use.
13
+ # - implement(Optional) #package_management_command, string for invoking the package manager
14
+ # - implement(Optional) #prepare_command, string for fetching dependencies for package manager (runs when the --prepare flag is passed to license_finder)
15
+
14
16
  class PackageManager
15
- def self.package_managers
16
- [GoDep, GoWorkspace, GoVendor, Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget]
17
- end
17
+ include LicenseFinder::SharedHelpers
18
18
 
19
- def self.current_packages(options)
20
- active_package_managers = package_managers
21
- .map { |pm| pm.new(options) }
22
- .select(&:active?)
23
- active_package_managers.flat_map(&:current_packages_with_relations)
24
- end
19
+ class << self
20
+ def package_managers
21
+ [GoDep, GoWorkspace, Go15VendorExperiment, Glide, Gvt, Govendor, Dep, Bundler, NPM, Pip,
22
+ Yarn, Bower, Maven, Gradle, CocoaPods, Rebar, Nuget, Carthage, Mix, Conan]
23
+ end
25
24
 
26
- def self.installed?(logger=Core.default_logger)
27
- if package_management_command.nil?
28
- logger.installed self, "no command defined" # TODO comment me out
29
- return true
25
+ def active_packages(options)
26
+ active_package_managers(options).flat_map(&:current_packages_with_relations)
30
27
  end
31
28
 
32
- if command_exists?(package_management_command)
33
- logger.installed self, true
34
- return true
29
+ def active_package_managers(options = { project_path: Pathname.new('') })
30
+ active_pm_classes = package_managers.select { |pm_class| pm_class.new(options).active? }
31
+ active_pm_classes -= active_pm_classes.map(&:takes_priority_over)
32
+ active_pm_classes.map { |pm_class| pm_class.new(options) }
35
33
  end
36
34
 
37
- logger.installed self, false
38
- return false
39
- end
35
+ def takes_priority_over
36
+ nil
37
+ end
38
+
39
+ def installed?(logger = Core.default_logger)
40
+ if package_management_command.nil?
41
+ logger.log self, 'no command defined' # TODO: comment me out
42
+ true
43
+ elsif command_exists?(package_management_command)
44
+ logger.log self, 'is installed', color: :green
45
+ true
46
+ else
47
+ logger.log self, 'is not installed', color: :red
48
+ false
49
+ end
50
+ end
40
51
 
41
- def self.package_management_command
42
- nil
52
+ # see class description
53
+ def package_management_command
54
+ nil
55
+ end
56
+
57
+ # see class description
58
+ def prepare_command
59
+ nil
60
+ end
43
61
  end
44
62
 
45
- def initialize options={}
63
+ def initialize(options = {})
46
64
  @logger = options[:logger] || Core.default_logger
47
65
  @project_path = options[:project_path]
48
66
  end
49
67
 
50
68
  def active?
69
+ path = detected_package_path
51
70
  self.class.installed?(logger) &&
52
- package_path.exist?.tap { |is_active| logger.active self.class, is_active }
71
+ !path.nil? &&
72
+ path.exist?.tap do |is_active|
73
+ if is_active
74
+ logger.log self.class, 'is active', color: :green
75
+ else
76
+ logger.log self.class, 'is not active'
77
+ end
78
+ end
53
79
  end
54
80
 
55
- def capture(command)
56
- [`#{command}`, $?.success?]
81
+ def detected_package_path
82
+ possible_package_paths.find(&:exist?)
83
+ end
84
+
85
+ def prepare
86
+ if self.class.prepare_command
87
+ _stdout, _stderr, status = Cmd.run(self.class.prepare_command)
88
+ raise "Prepare command '#{self.class.prepare_command}' failed" unless status.success?
89
+ else
90
+ logger.log self.class, 'no prepare step provided', color: :red
91
+ end
57
92
  end
58
93
 
59
94
  def current_packages_with_relations
60
95
  packages = current_packages
61
96
  packages.each do |parent|
62
97
  parent.children.each do |child_name|
63
- child = packages.detect { |child| child.name == child_name }
98
+ child = packages.detect { |child_package| child_package.name == child_name }
64
99
  child.parents << parent.name if child
65
100
  end
66
101
  end
67
102
  packages
68
103
  end
69
104
 
70
- def self.command_exists? command
105
+ def self.command_exists?(command)
71
106
  if LicenseFinder::Platform.windows?
72
- `where #{command} 2>NUL`
107
+ _stdout, _stderr, status = Cmd.run("where #{command} 2>NUL")
73
108
  else
74
- `which #{command} 2>/dev/null`
109
+ _stdout, _stderr, status = Cmd.run("which #{command} 2>/dev/null")
75
110
  end
76
- status = $?
77
- return status.success?
111
+
112
+ status.success?
78
113
  end
79
114
 
80
115
  private
@@ -85,15 +120,23 @@ end
85
120
 
86
121
  require 'license_finder/package_managers/bower'
87
122
  require 'license_finder/package_managers/go_workspace'
88
- require 'license_finder/package_managers/go_vendor'
123
+ require 'license_finder/package_managers/go_15vendorexperiment'
89
124
  require 'license_finder/package_managers/go_dep'
125
+ require 'license_finder/package_managers/gvt'
126
+ require 'license_finder/package_managers/glide'
127
+ require 'license_finder/package_managers/govendor'
90
128
  require 'license_finder/package_managers/bundler'
91
129
  require 'license_finder/package_managers/npm'
130
+ require 'license_finder/package_managers/yarn'
92
131
  require 'license_finder/package_managers/pip'
93
132
  require 'license_finder/package_managers/maven'
133
+ require 'license_finder/package_managers/mix'
94
134
  require 'license_finder/package_managers/cocoa_pods'
135
+ require 'license_finder/package_managers/carthage'
95
136
  require 'license_finder/package_managers/gradle'
96
137
  require 'license_finder/package_managers/rebar'
97
138
  require 'license_finder/package_managers/nuget'
139
+ require 'license_finder/package_managers/dep'
140
+ require 'license_finder/package_managers/conan'
98
141
 
99
142
  require 'license_finder/package'
@@ -9,23 +9,23 @@ module LicenseFinder
9
9
  end
10
10
 
11
11
  def self.package_management_command
12
- "bower"
12
+ 'bower'
13
13
  end
14
14
 
15
15
  private
16
16
 
17
17
  def bower_output
18
- command = "#{Bower::package_management_command} list --json -l action --allow-root"
19
- output, success = Dir.chdir(project_path) { capture(command) }
20
- raise "Command '#{command}' failed to execute: #{output}" unless success
18
+ command = "#{Bower.package_management_command} list --json -l action --allow-root"
19
+ stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
20
+ raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?
21
21
 
22
- JSON(output)
23
- .fetch("dependencies", {})
22
+ JSON(stdout)
23
+ .fetch('dependencies', {})
24
24
  .values
25
25
  end
26
26
 
27
- def package_path
28
- project_path.join('bower.json')
27
+ def possible_package_paths
28
+ [project_path.join('bower.json')]
29
29
  end
30
30
  end
31
31
  end