license_finder 1.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.rdoc +27 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/README.md +139 -159
  6. data/Rakefile +17 -13
  7. data/features/features/cli_spec.rb +43 -0
  8. data/features/features/configure/add_dependencies_spec.rb +37 -0
  9. data/features/features/configure/approve_dependencies_spec.rb +30 -0
  10. data/features/features/configure/assign_licenses_spec.rb +20 -0
  11. data/features/features/configure/ignore_dependencies_spec.rb +35 -0
  12. data/features/features/configure/ignore_groups_spec.rb +31 -0
  13. data/features/features/configure/name_project_spec.rb +32 -0
  14. data/features/features/configure/whitelist_licenses_spec.rb +40 -0
  15. data/features/features/package_managers/bower_spec.rb +14 -0
  16. data/features/features/package_managers/cocoapods_spec.rb +14 -0
  17. data/features/features/package_managers/gradle_spec.rb +14 -0
  18. data/features/features/package_managers/maven_spec.rb +14 -0
  19. data/features/features/package_managers/npm_spec.rb +14 -0
  20. data/features/features/package_managers/pip_spec.rb +14 -0
  21. data/features/features/report/csv_spec.rb +17 -0
  22. data/features/features/report/html_spec.rb +50 -0
  23. data/{spec → features}/fixtures/Podfile +0 -0
  24. data/{spec → features}/fixtures/build.gradle +0 -0
  25. data/{spec → features}/fixtures/pom.xml +0 -0
  26. data/features/support/testing_dsl.rb +295 -0
  27. data/lib/license_finder.rb +16 -50
  28. data/lib/license_finder/cli.rb +13 -253
  29. data/lib/license_finder/cli/approvals.rb +26 -0
  30. data/lib/license_finder/cli/base.rb +20 -0
  31. data/lib/license_finder/cli/dependencies.rb +39 -0
  32. data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
  33. data/lib/license_finder/cli/ignored_groups.rb +30 -0
  34. data/lib/license_finder/cli/licenses.rb +24 -0
  35. data/lib/license_finder/cli/main.rb +82 -0
  36. data/lib/license_finder/cli/makes_decisions.rb +48 -0
  37. data/lib/license_finder/cli/patched_thor.rb +34 -0
  38. data/lib/license_finder/cli/project_name.rb +31 -0
  39. data/lib/license_finder/cli/whitelist.rb +32 -0
  40. data/lib/license_finder/configuration.rb +14 -145
  41. data/lib/license_finder/decision_applier.rb +46 -0
  42. data/lib/license_finder/decisions.rb +174 -0
  43. data/lib/license_finder/license.rb +13 -32
  44. data/lib/license_finder/license/definitions.rb +15 -13
  45. data/lib/license_finder/license/template.rb +1 -1
  46. data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
  47. data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
  48. data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
  49. data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
  50. data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
  51. data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
  52. data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
  53. data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
  54. data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
  55. data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
  56. data/lib/license_finder/package.rb +77 -7
  57. data/lib/license_finder/package_manager.rb +43 -0
  58. data/lib/license_finder/package_managers/bower.rb +1 -1
  59. data/lib/license_finder/package_managers/bower_package.rb +23 -44
  60. data/lib/license_finder/package_managers/bundler.rb +4 -7
  61. data/lib/license_finder/package_managers/bundler_package.rb +14 -31
  62. data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
  63. data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
  64. data/lib/license_finder/package_managers/gradle.rb +6 -2
  65. data/lib/license_finder/package_managers/gradle_package.rb +6 -30
  66. data/lib/license_finder/package_managers/manual_package.rb +25 -0
  67. data/lib/license_finder/package_managers/maven_package.rb +8 -37
  68. data/lib/license_finder/package_managers/npm.rb +16 -4
  69. data/lib/license_finder/package_managers/npm_package.rb +12 -43
  70. data/lib/license_finder/package_managers/pip_package.rb +17 -37
  71. data/lib/license_finder/platform.rb +0 -16
  72. data/lib/license_finder/possible_license_file.rb +9 -14
  73. data/lib/license_finder/possible_license_files.rb +1 -5
  74. data/lib/license_finder/report.rb +26 -0
  75. data/lib/license_finder/reports/csv_report.rb +58 -0
  76. data/lib/license_finder/reports/erb_report.rb +61 -0
  77. data/lib/license_finder/reports/html_report.rb +10 -1
  78. data/lib/license_finder/reports/markdown_report.rb +7 -1
  79. data/lib/license_finder/reports/templates/bootstrap.css +9 -0
  80. data/lib/license_finder/reports/templates/html_report.erb +105 -0
  81. data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
  82. data/lib/license_finder/reports/text_report.rb +5 -3
  83. data/lib/license_finder/version.rb +3 -0
  84. data/license_finder.gemspec +2 -6
  85. data/release/instructions.md +8 -0
  86. data/spec/feature_helper.rb +11 -0
  87. data/spec/fixtures/config/license_finder.yml +3 -0
  88. data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
  89. data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
  90. data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
  91. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
  92. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
  93. data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
  94. data/spec/lib/license_finder/cli/main_spec.rb +110 -0
  95. data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
  96. data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
  97. data/spec/lib/license_finder/configuration_spec.rb +46 -191
  98. data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
  99. data/spec/lib/license_finder/decisions_spec.rb +347 -0
  100. data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
  101. data/spec/lib/license_finder/license_spec.rb +2 -30
  102. data/spec/lib/license_finder/package_manager_spec.rb +22 -0
  103. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
  104. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
  105. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
  106. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
  107. data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
  108. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
  109. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
  110. data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
  111. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
  112. data/spec/lib/license_finder/package_spec.rb +121 -0
  113. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
  114. data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
  115. data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
  116. data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
  117. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
  118. data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
  119. data/spec/spec_helper.rb +1 -4
  120. data/spec/support/shared_examples_for_package.rb +0 -11
  121. data/spec/support/shared_examples_for_package_manager.rb +1 -0
  122. data/spec/support/stdout_helpers.rb +4 -11
  123. metadata +73 -158
  124. data/db/migrate/201303290935_create_dependencies.rb +0 -14
  125. data/db/migrate/201303291155_create_licenses.rb +0 -13
  126. data/db/migrate/201303291402_create_approvals.rb +0 -13
  127. data/db/migrate/201303291456_create_ancestries.rb +0 -9
  128. data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
  129. data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
  130. data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
  131. data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
  132. data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
  133. data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
  134. data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
  135. data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
  136. data/db/migrate/201307251107_reassociate_license.rb +0 -23
  137. data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
  138. data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
  139. data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
  140. data/db/migrate/201311192010_drop_approvals.rb +0 -5
  141. data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
  142. data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
  143. data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
  144. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
  145. data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
  146. data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
  147. data/features/cli.feature +0 -37
  148. data/features/cocoapods_dependencies.feature +0 -10
  149. data/features/configure_bundler_groups.feature +0 -23
  150. data/features/configure_ignore_dependencies.feature +0 -16
  151. data/features/configure_project_name.feature +0 -10
  152. data/features/configure_whitelist.feature +0 -27
  153. data/features/gradle_dependencies.feature +0 -9
  154. data/features/manually_added.feature +0 -19
  155. data/features/manually_approved.feature +0 -10
  156. data/features/manually_assigned_license.feature +0 -16
  157. data/features/maven_dependencies.feature +0 -9
  158. data/features/multiple_licenses.feature +0 -9
  159. data/features/node_dependencies.feature +0 -9
  160. data/features/python_dependencies.feature +0 -9
  161. data/features/report_csv.feature +0 -15
  162. data/features/report_html.feature +0 -24
  163. data/features/step_definitions/cli_steps.rb +0 -51
  164. data/features/step_definitions/cocoapod_steps.rb +0 -8
  165. data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
  166. data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
  167. data/features/step_definitions/configure_project_name_steps.rb +0 -3
  168. data/features/step_definitions/configure_whitelist_steps.rb +0 -45
  169. data/features/step_definitions/gradle_steps.rb +0 -8
  170. data/features/step_definitions/manually_added_steps.rb +0 -28
  171. data/features/step_definitions/manually_approved_steps.rb +0 -24
  172. data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
  173. data/features/step_definitions/maven_steps.rb +0 -8
  174. data/features/step_definitions/multiple_licenses_steps.rb +0 -14
  175. data/features/step_definitions/node_steps.rb +0 -8
  176. data/features/step_definitions/python_steps.rb +0 -8
  177. data/features/step_definitions/report_csv_steps.rb +0 -20
  178. data/features/step_definitions/report_html_steps.rb +0 -60
  179. data/features/step_definitions/shared_steps.rb +0 -307
  180. data/lib/data/license_finder.example.yml +0 -12
  181. data/lib/license_finder/dependency_manager.rb +0 -92
  182. data/lib/license_finder/package_saver.rb +0 -44
  183. data/lib/license_finder/reports/dependency_report.rb +0 -34
  184. data/lib/license_finder/reports/detailed_text_report.rb +0 -19
  185. data/lib/license_finder/reports/formatted_report.rb +0 -40
  186. data/lib/license_finder/reports/reporter.rb +0 -27
  187. data/lib/license_finder/tables.rb +0 -9
  188. data/lib/license_finder/tables/bundler_group.rb +0 -7
  189. data/lib/license_finder/tables/dependency.rb +0 -113
  190. data/lib/license_finder/tables/manual_approval.rb +0 -13
  191. data/lib/license_finder/yml_to_sql.rb +0 -117
  192. data/lib/templates/html_report.erb +0 -117
  193. data/lib/templates/text_report.erb +0 -3
  194. data/release/gem_version.rb +0 -3
  195. data/release/manual_instructions.md +0 -29
  196. data/release/publish.sh +0 -32
  197. data/spec/fixtures/APACHE-2-LICENSE +0 -202
  198. data/spec/fixtures/GPLv2 +0 -339
  199. data/spec/fixtures/ISC-LICENSE +0 -10
  200. data/spec/fixtures/MIT-LICENSE +0 -22
  201. data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
  202. data/spec/fixtures/README-with-MIT-LICENSE +0 -222
  203. data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
  204. data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
  205. data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
  206. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
  207. data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
  208. data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
  209. data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
  210. data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
  211. data/spec/fixtures/readme/README +0 -0
  212. data/spec/fixtures/readme/Readme.markdown +0 -0
  213. data/spec/lib/license_finder/cli_spec.rb +0 -298
  214. data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
  215. data/spec/lib/license_finder/package_saver_spec.rb +0 -82
  216. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
  217. data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
  218. data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
  219. data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
  220. data/spec/lib/license_finder_spec.rb +0 -16
@@ -1,5 +1,29 @@
1
1
  module LicenseFinder
2
+ # Super-class for the different package managers
3
+ # (Bundler, NPM, Pip, etc.)
4
+ #
5
+ # For guidance on adding a new package manager use the shared behavior
6
+ #
7
+ # it_behaves_like "a PackageManager"
8
+ #
9
+ # Additional guidelines are:
10
+ #
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
+ #
2
14
  class PackageManager
15
+ def self.package_managers
16
+ [Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods]
17
+ end
18
+
19
+ def self.current_packages(options)
20
+ package_managers.
21
+ map { |pm| pm.new(options) }.
22
+ select(&:active?).
23
+ map(&:current_packages_with_relations).
24
+ flatten
25
+ end
26
+
3
27
  attr_reader :logger
4
28
 
5
29
  def initialize options={}
@@ -11,6 +35,17 @@ module LicenseFinder
11
35
  injected_package_path.exist?.tap { |is_active| logger.active self.class, is_active }
12
36
  end
13
37
 
38
+ def current_packages_with_relations
39
+ packages = current_packages
40
+ packages.each do |parent|
41
+ parent.children.each do |child_name|
42
+ child = packages.detect { |child| child.name == child_name }
43
+ child.parents << parent.name if child
44
+ end
45
+ end
46
+ packages
47
+ end
48
+
14
49
  private
15
50
 
16
51
  def injected_package_path
@@ -18,3 +53,11 @@ module LicenseFinder
18
53
  end
19
54
  end
20
55
  end
56
+
57
+ require 'license_finder/package_managers/bower'
58
+ require 'license_finder/package_managers/bundler'
59
+ require 'license_finder/package_managers/npm'
60
+ require 'license_finder/package_managers/pip'
61
+ require 'license_finder/package_managers/maven'
62
+ require 'license_finder/package_managers/cocoa_pods'
63
+ require 'license_finder/package_managers/gradle'
@@ -3,7 +3,7 @@ require 'json'
3
3
  module LicenseFinder
4
4
  class Bower < PackageManager
5
5
  def current_packages
6
- output = `bower list --json`
6
+ output = `bower list --json -l action`
7
7
 
8
8
  json = JSON(output)
9
9
 
@@ -1,50 +1,29 @@
1
1
  module LicenseFinder
2
2
  class BowerPackage < Package
3
3
  def initialize(bower_module, options={})
4
- super options
5
- @bower_module = bower_module
6
- @module_metadata = bower_module.fetch("pkgMeta", Hash.new)
7
- end
8
-
9
- def name
10
- module_metadata.fetch("name", nil)
11
- end
12
-
13
- def version
14
- module_metadata.fetch("version", nil)
15
- end
16
-
17
- def summary
18
- module_metadata.fetch("description", nil)
19
- end
20
-
21
- def description
22
- module_metadata.fetch("readme", nil)
23
- end
24
-
25
- def homepage
26
- module_metadata.fetch("homepage", nil)
27
- end
28
-
29
- def children
30
- [] # no way to determine child deps from bower (maybe?)
31
- end
32
-
33
- def groups
34
- [] # no concept of dev/test groups in bower (maybe?)
35
- end
36
-
37
- private
38
-
39
- attr_reader :bower_module
40
- attr_reader :module_metadata
41
-
42
- def install_path
43
- bower_module["canonicalDir"]
44
- end
45
-
46
- def license_names_from_spec
47
- Package.license_names_from_standard_spec(module_metadata)
4
+ spec = bower_module.fetch("pkgMeta", Hash.new)
5
+
6
+ if spec.empty?
7
+ endpoint = bower_module.fetch("endpoint", Hash.new)
8
+ name = endpoint["name"]
9
+ version = endpoint["target"]
10
+ else
11
+ name = spec["name"]
12
+ version = spec["version"]
13
+ end
14
+
15
+ super(
16
+ name,
17
+ version,
18
+ options.merge(
19
+ summary: spec["description"],
20
+ description: spec["readme"],
21
+ homepage: spec["homepage"],
22
+ spec_licenses: Package.license_names_from_standard_spec(spec),
23
+ install_path: bower_module["canonicalDir"],
24
+ missing: bower_module["missing"]
25
+ )
26
+ )
48
27
  end
49
28
  end
50
29
  end
@@ -4,8 +4,8 @@ module LicenseFinder
4
4
  class Bundler < PackageManager
5
5
  def initialize options={}
6
6
  super
7
- @ignore_groups = options[:ignore_groups] # dependency injection for tests
8
- @definition = options[:definition] # dependency injection for tests
7
+ @ignore_groups = options[:ignore_groups]
8
+ @definition = options[:definition] # dependency injection for tests
9
9
  end
10
10
 
11
11
  def current_packages
@@ -20,16 +20,13 @@ module LicenseFinder
20
20
 
21
21
  private
22
22
 
23
+ attr_reader :ignore_groups
24
+
23
25
  def definition
24
26
  # DI
25
27
  @definition ||= ::Bundler::Definition.build(package_path, lockfile_path, nil)
26
28
  end
27
29
 
28
- def ignore_groups
29
- # DI
30
- @ignore_groups ||= LicenseFinder.config.ignore_groups
31
- end
32
-
33
30
  def package_path
34
31
  Pathname.new("Gemfile")
35
32
  end
@@ -1,36 +1,19 @@
1
1
  module LicenseFinder
2
2
  class BundlerPackage < Package
3
- extend Forwardable
4
- def_delegators :gem_def, :summary, :description, :name, :homepage
5
-
6
- attr_reader :gem_def
7
-
8
- def initialize(gem_def, bundler_def, options={})
9
- super options
10
- @gem_def = gem_def
11
- @bundler_def = bundler_def
12
- end
13
-
14
- def groups
15
- Array(@bundler_def && @bundler_def.groups)
16
- end
17
-
18
- def version
19
- gem_def.version.to_s
20
- end
21
-
22
- def children
23
- gem_def.dependencies.map(&:name)
24
- end
25
-
26
- private
27
-
28
- def install_path
29
- gem_def.full_gem_path
30
- end
31
-
32
- def license_names_from_spec
33
- gem_def.licenses
3
+ def initialize(spec, bundler_def, options={})
4
+ super(
5
+ spec.name,
6
+ spec.version.to_s,
7
+ options.merge(
8
+ summary: spec.summary,
9
+ description: spec.description,
10
+ homepage: spec.homepage,
11
+ children: spec.dependencies.map(&:name),
12
+ groups: Array(bundler_def && bundler_def.groups),
13
+ spec_licenses: spec.licenses,
14
+ install_path: spec.full_gem_path
15
+ )
16
+ )
34
17
  end
35
18
  end
36
19
  end
@@ -33,7 +33,7 @@ module LicenseFinder
33
33
  'Pods/Target Support Files/Pods' # cocoapods >= 0.34
34
34
  ]
35
35
 
36
- directories.map { |dir| Pathname.new(File.join(dir, filename)) }.find(&:exist?)
36
+ directories.map { |dir| Pathname.new(dir).join(filename) }.find(&:exist?)
37
37
  end
38
38
 
39
39
  def read_plist pathname
@@ -1,18 +1,10 @@
1
1
  module LicenseFinder
2
2
  class CocoaPodsPackage < Package
3
- attr_reader :name, :version
4
- attr_reader :summary, :description, :homepage
5
-
6
- def initialize(name, version, license_text, options={})
7
- super options
8
- @name = name
9
- @version = version
3
+ def initialize(name, version, license_text)
4
+ super(name, version)
10
5
  @license_text = license_text
11
6
  end
12
7
 
13
- def groups; []; end
14
- def children; []; end
15
-
16
8
  def licenses
17
9
  [License.find_by_text(@license_text.to_s) || default_license].to_set
18
10
  end
@@ -2,8 +2,13 @@ require "xmlsimple"
2
2
 
3
3
  module LicenseFinder
4
4
  class Gradle < PackageManager
5
+ def initialize(options={})
6
+ super
7
+ @command = options[:gradle_command] || "gradle"
8
+ end
9
+
5
10
  def current_packages
6
- `#{LicenseFinder.config.gradle_command} downloadLicenses`
11
+ `#{@command} downloadLicenses`
7
12
 
8
13
  xml = license_report.read
9
14
 
@@ -11,7 +16,6 @@ module LicenseFinder
11
16
  'GroupTags' => { 'dependencies' => 'dependency' }
12
17
  }
13
18
  XmlSimple.xml_in(xml, options).fetch('dependency', []).map do |dep|
14
- dep["license"].reject! { |l| l["name"] == "No license found" }
15
19
  GradlePackage.new(dep, logger: logger)
16
20
  end
17
21
  end
@@ -1,36 +1,12 @@
1
1
  module LicenseFinder
2
2
  class GradlePackage < Package
3
- attr_reader :name, :version
3
+ def initialize(spec, options={})
4
+ _, name, version = spec["name"].split(":")
5
+ licenses = Array(spec["license"])
6
+ .map { |l| l["name"] }
7
+ .reject { |name| name == "No license found" }
4
8
 
5
- def initialize(gradle_dependency, options={})
6
- super options
7
- @gradle_dependency = gradle_dependency
8
- @name = @gradle_dependency["name"].split(":")[1]
9
- @version = @gradle_dependency["name"].split(":")[2]
10
- end
11
-
12
- def description
13
- ""
14
- end
15
-
16
- def summary
17
- ""
18
- end
19
-
20
- def homepage
21
- ""
22
- end
23
-
24
- def groups
25
- []
26
- end
27
-
28
- def children
29
- []
30
- end
31
-
32
- def license_names_from_spec
33
- @gradle_dependency["license"].map { |l| l["name"] }
9
+ super(name, version, options.merge(spec_licenses: licenses))
34
10
  end
35
11
  end
36
12
  end
@@ -0,0 +1,25 @@
1
+ module LicenseFinder
2
+ class ManualPackage < Package
3
+ def ==(other)
4
+ eql? other
5
+ end
6
+
7
+ def eql?(other)
8
+ name == other.name # && version.to_s == other.version.to_s # ignore version
9
+ end
10
+
11
+ def hash
12
+ name.hash # ^ version.to_s.hash # ignore version
13
+ end
14
+
15
+ private
16
+
17
+ def licenses_from_spec
18
+ Set.new
19
+ end
20
+
21
+ def licenses_from_files
22
+ Set.new
23
+ end
24
+ end
25
+ end
@@ -1,42 +1,13 @@
1
1
  module LicenseFinder
2
2
  class MavenPackage < Package
3
- attr_reader :mvn_dependency
4
-
5
- def initialize(mvn_dependency, options={})
6
- super options
7
- @mvn_dependency = mvn_dependency
8
- end
9
-
10
- def name
11
- mvn_dependency["artifactId"]
12
- end
13
-
14
- def version
15
- mvn_dependency["version"]
16
- end
17
-
18
- def description
19
- ""
20
- end
21
-
22
- def summary
23
- ""
24
- end
25
-
26
- def homepage
27
- ""
28
- end
29
-
30
- def groups
31
- []
32
- end
33
-
34
- def children
35
- []
36
- end
37
-
38
- def license_names_from_spec
39
- mvn_dependency["licenses"].map { |l| l["name"] }
3
+ def initialize(spec, options={})
4
+ super(
5
+ spec["artifactId"],
6
+ spec["version"],
7
+ options.merge(
8
+ spec_licenses: Array(spec["licenses"]).map { |l| l["name"] }
9
+ )
10
+ )
40
11
  end
41
12
  end
42
13
  end
@@ -2,15 +2,15 @@ require 'json'
2
2
 
3
3
  module LicenseFinder
4
4
  class NPM < PackageManager
5
- DEPENDENCY_GROUPS = ["dependencies", "devDependencies", "bundleDependencies", "bundledDependencies"]
5
+ DEPENDENCY_GROUPS = ["dependencies", "devDependencies"]
6
6
 
7
7
  def current_packages
8
8
  json = npm_json
9
9
  dependencies = DEPENDENCY_GROUPS.map { |g| (json[g] || {}).values }.flatten(1).reject{ |d| d.is_a?(String) }
10
10
 
11
- dependencies.map do |node_module|
12
- NpmPackage.new(node_module, logger: logger)
13
- end
11
+ pkgs = {} # name => spec
12
+ dependencies.each { |d| recursive_dependencies(d, pkgs) }
13
+ pkgs.values.map { |d| NpmPackage.new(d, logger: logger) }
14
14
  end
15
15
 
16
16
  private
@@ -38,5 +38,17 @@ module LicenseFinder
38
38
  def package_path
39
39
  Pathname.new('package.json')
40
40
  end
41
+
42
+ # node_module can be empty hash if it is included elsewhere
43
+ def recursive_dependencies(node_module, memo)
44
+ key = node_module['name']
45
+ memo[key] ||= {}
46
+ memo[key].merge!(node_module)
47
+ node_module.fetch('dependencies', {}).each do |dep_key, data|
48
+ data['name'] ||= dep_key
49
+ recursive_dependencies(data, memo)
50
+ end
51
+ memo
52
+ end
41
53
  end
42
54
  end
@@ -1,48 +1,17 @@
1
1
  module LicenseFinder
2
2
  class NpmPackage < Package
3
- def initialize(node_module, options={})
4
- super options
5
- @node_module = node_module
6
- end
7
-
8
- def name
9
- node_module["name"]
10
- end
11
-
12
- def version
13
- node_module["version"]
14
- end
15
-
16
- def summary
17
- node_module["description"]
18
- end
19
-
20
- def description
21
- node_module["readme"]
22
- end
23
-
24
- def homepage
25
- node_module["homepage"]
26
- end
27
-
28
- def children
29
- [] # no way to determine child deps from npm (maybe?)
30
- end
31
-
32
- def groups
33
- [] # no concept of dev/test groups in npm (maybe?)
34
- end
35
-
36
- private
37
-
38
- attr_reader :node_module
39
-
40
- def install_path
41
- node_module["path"]
42
- end
43
-
44
- def license_names_from_spec
45
- Package.license_names_from_standard_spec(node_module)
3
+ def initialize(spec, options={})
4
+ super(
5
+ spec["name"],
6
+ spec["version"],
7
+ options.merge(
8
+ description: spec["description"],
9
+ homepage: spec["homepage"],
10
+ spec_licenses: Package.license_names_from_standard_spec(spec),
11
+ install_path: spec["path"],
12
+ children: spec.fetch("dependencies", {}).map { |_, d| d["name"] }
13
+ )
14
+ )
46
15
  end
47
16
  end
48
17
  end