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,307 +0,0 @@
1
- require 'fileutils'
2
- require 'pathname'
3
- require 'bundler'
4
- require 'capybara'
5
- require 'open3'
6
-
7
- ########## COMMON STEPS ##########
8
-
9
- Given(/^I have an app$/) do
10
- @user = ::DSL::User.new
11
- @user.create_ruby_app
12
- end
13
-
14
- When(/^I run license_finder$/) do
15
- @user.execute_command "license_finder --quiet"
16
- end
17
-
18
- When(/^I whitelist everything I can think of$/) do
19
- @user.configure_license_finder_whitelist ["MIT","other","New BSD","Apache 2.0","Ruby"]
20
- @user.execute_command "license_finder --quiet"
21
- end
22
-
23
- Then(/^I should see the project name (\w+) in the html$/) do |project_name|
24
- @user.in_html do |page|
25
- title = page.find("h1")
26
-
27
- expect(title).to have_content project_name
28
- end
29
- end
30
-
31
-
32
- module DSL
33
- class User
34
- def create_python_app
35
- reset_projects!
36
-
37
- app_path.mkpath
38
- shell_out("cd #{app_path} && touch requirements.txt")
39
-
40
- add_pip_dependency('argparse==1.2.1')
41
-
42
- pip_install
43
- end
44
-
45
- def create_node_app
46
- reset_projects!
47
-
48
- app_path.mkpath
49
- shell_out("cd #{app_path} && touch package.json")
50
-
51
- add_npm_dependency('http-server', '0.6.1')
52
-
53
- npm_install
54
- end
55
-
56
- def create_maven_app
57
- reset_projects!
58
-
59
- app_path.mkpath
60
-
61
- add_maven_dependency
62
-
63
- mvn_install
64
- end
65
-
66
- def create_gradle_app
67
- reset_projects!
68
-
69
- app_path.mkpath
70
-
71
- add_gradle_dependency
72
- end
73
-
74
- def create_ruby_app
75
- reset_projects!
76
-
77
- shell_out("cd #{projects_path} && bundle gem #{app_name}")
78
-
79
- add_gem_dependency('license_finder', path: root_path.to_s)
80
-
81
- bundle_install
82
- end
83
-
84
- def create_cocoapods_app
85
- reset_projects!
86
-
87
- app_path.mkpath
88
-
89
- add_pod_dependency
90
-
91
- pod_install
92
- end
93
-
94
- def create_and_depend_on_gem(gem_name, options)
95
- create_gem(gem_name, options)
96
- depend_on_local_gem(gem_name)
97
- end
98
-
99
- def create_gem(gem_name, options)
100
- gem_dir = projects_path.join(gem_name)
101
-
102
- gem_dir.mkpath
103
- gem_dir.join("#{gem_name}.gemspec").open('w') do |file|
104
- file.write gemspec_string(gem_name, options)
105
- end
106
- end
107
-
108
- def depend_on_local_gem(gem_name, options={})
109
- gem_dir = projects_path.join(gem_name)
110
- options[:path] = gem_dir.to_s
111
-
112
- add_gem_dependency(gem_name, options)
113
-
114
- bundle_install
115
- end
116
-
117
- def configure_license_finder_whitelist(whitelisted_licenses=[])
118
- config_path.mkpath
119
- config_file.open("w") do |f|
120
- f.write({'whitelist' => whitelisted_licenses}.to_yaml)
121
- end
122
- end
123
-
124
- def execute_command(command)
125
- ::Bundler.with_clean_env do
126
- @output = shell_out("cd #{app_path} && bundle exec #{command}", true)
127
- end
128
- end
129
-
130
- def seeing?(content)
131
- @output.include? content
132
- end
133
-
134
- def seeing_line?(content)
135
- seeing_something_like? /^#{Regexp.escape content}$/
136
- end
137
-
138
- def seeing_something_like?(regex)
139
- @output =~ regex
140
- end
141
-
142
- def app_path(sub_directory = nil)
143
- path = base_path = projects_path.join(app_name).cleanpath
144
-
145
- if sub_directory
146
- path = base_path.join(sub_directory).cleanpath
147
-
148
- raise "#{sub_directory} is outside of the app" unless path.to_s =~ %r{^#{base_path}/}
149
- end
150
-
151
- path
152
- end
153
-
154
- def config_path
155
- app_path('config')
156
- end
157
-
158
- def config_file
159
- config_path.join("license_finder.yml")
160
- end
161
-
162
- def in_html
163
- yield Capybara.string(app_path('doc/dependencies.html').read)
164
- end
165
-
166
- def in_gem_html(gem_name)
167
- in_html do |page|
168
- yield page.find("##{gem_name}")
169
- end
170
- end
171
-
172
- private
173
-
174
- def gemspec_string(gem_name, options)
175
- if options.has_key?(:license) && options.has_key?(:licenses)
176
- raise "Can't specify both `license` and `licenses`"
177
- end
178
-
179
- license_key = ([:license, :licenses] & options.keys).first
180
- license_value = options.fetch(license_key)
181
- summary = options.fetch(:summary, "")
182
- description = options.fetch(:description, "")
183
- version = options[:version] || "0.0.0"
184
- homepage = options[:homepage]
185
-
186
- <<-GEMSPEC
187
- Gem::Specification.new do |s|
188
- s.name = "#{gem_name}"
189
- s.version = "#{version}"
190
- s.author = "Cucumber"
191
- s.summary = "#{summary}"
192
- s.#{license_key} = #{license_value.inspect}
193
- s.description = "#{description}"
194
- s.homepage = "#{homepage}"
195
- end
196
- GEMSPEC
197
- end
198
-
199
- def add_gem_dependency(name, options = {})
200
- line = "gem #{name.inspect}"
201
- line << ", " + options.inspect unless options.empty?
202
-
203
- add_to_gemfile(line)
204
- end
205
-
206
- def add_pip_dependency(dependency)
207
- add_to_requirements(dependency)
208
- end
209
-
210
- def add_npm_dependency(dependency, version)
211
- line = "{\"dependencies\" : {\"#{dependency}\": \"#{version}\"}}"
212
-
213
- add_to_package(line)
214
- end
215
-
216
- def add_maven_dependency
217
- path = fixtures_path.join("pom.xml")
218
- shell_out("cp #{path} #{app_path}")
219
- end
220
-
221
- def add_gradle_dependency
222
- path = fixtures_path.join("build.gradle")
223
- shell_out("cd #{app_path} && cp #{path} .")
224
- end
225
-
226
- def add_pod_dependency
227
- path = fixtures_path.join("Podfile")
228
- shell_out("cp #{path} #{app_path}")
229
- end
230
-
231
- def bundle_install
232
- ::Bundler.with_clean_env do
233
- shell_out("cd #{app_path} && bundle check || bundle install")
234
- end
235
- end
236
-
237
- def pip_install
238
- shell_out("cd #{app_path} && pip install -r requirements.txt")
239
- end
240
-
241
- def npm_install
242
- shell_out("cd #{app_path} && npm install 2>/dev/null")
243
- end
244
-
245
- def mvn_install
246
- shell_out("cd #{app_path} && mvn install")
247
- end
248
-
249
- def pod_install
250
- shell_out("cd #{app_path} && pod install --no-integrate")
251
- end
252
-
253
- def add_to_gemfile(line)
254
- shell_out("echo #{line.inspect} >> #{app_path.join("Gemfile")}")
255
- end
256
-
257
- def add_to_requirements(line)
258
- shell_out("echo #{line.inspect} >> #{app_path.join("requirements.txt")}")
259
- end
260
-
261
- def add_to_package(line)
262
- shell_out("echo #{line.inspect} >> #{app_path.join("package.json")}")
263
- end
264
-
265
- def app_name
266
- "my_app"
267
- end
268
-
269
- def sandbox_path
270
- root_path.join("tmp")
271
- end
272
-
273
- def projects_path
274
- sandbox_path.join("projects")
275
- end
276
-
277
- def fixtures_path
278
- root_path.join("spec", "fixtures")
279
- end
280
-
281
- def reset_projects!
282
- shell_out("rm -rf #{projects_path}")
283
- projects_path.mkpath
284
- end
285
-
286
- def root_path
287
- Pathname.new(__FILE__).dirname.join("..", "..").realpath
288
- end
289
-
290
- def shell_out(command, allow_failures = false)
291
- output = `#{command} 2>&1`
292
- status = $?
293
- unless status.success? || allow_failures
294
- message_format = <<EOM
295
- Command failed: `%s`
296
- output: %s
297
- exit: %d
298
- EOM
299
- message = sprintf message_format, command, output.chomp, status.exitstatus
300
- raise RuntimeError.new(message)
301
- end
302
-
303
- $last_command_exit_status = status
304
- output
305
- end
306
- end
307
- end
@@ -1,12 +0,0 @@
1
- ---
2
- whitelist:
3
- #- MIT
4
- #- Apache 2.0
5
- ignore_groups:
6
- #- test
7
- #- development
8
- ignore_dependencies:
9
- #- bundler
10
- dependencies_file_dir: './doc/'
11
- project_name: # project name
12
- gradle_command: # only meaningful if used with a Java/gradle project. Defaults to "gradle".
@@ -1,92 +0,0 @@
1
- require 'digest'
2
-
3
- module LicenseFinder
4
- class DependencyManager
5
- attr_reader :logger
6
-
7
- def initialize options={}
8
- @logger = options[:logger] || LicenseFinder::Logger::Default.new
9
- end
10
-
11
- def sync_with_package_managers options={}
12
- modifying {
13
- current_dependencies = PackageSaver.save_all(current_packages)
14
-
15
- Dependency.added_automatically.obsolete(current_dependencies).each(&:destroy)
16
- }
17
- end
18
-
19
- def manually_add(license, name, version)
20
- raise Error.new("#{name} dependency already exists") unless Dependency.where(name: name).empty?
21
-
22
- modifying {
23
- dependency = Dependency.new(added_manually: true, name: name, version: version)
24
- dependency.licenses = [License.find_by_name(license)].to_set
25
- dependency.save
26
- }
27
- end
28
-
29
- def manually_remove(name)
30
- modifying { find_by_name(name, Dependency.added_manually).destroy }
31
- end
32
-
33
- def license!(name, license_name)
34
- license = License.find_by_name(license_name)
35
- modifying { find_by_name(name).set_license_manually!(license) }
36
- end
37
-
38
- def approve!(name, approver = nil, notes = nil)
39
- modifying { find_by_name(name).approve!(approver, notes) }
40
- end
41
-
42
- def modifying
43
- checksum_before = checksum
44
- result = DB.transaction { yield }
45
- checksum_after = checksum
46
-
47
- database_changed = checksum_before != checksum_after
48
-
49
- if database_changed || reports_do_not_exist || reports_are_stale
50
- Reporter.write_reports
51
- end
52
-
53
- result
54
- end
55
-
56
- private # not really private, but it looks like it is!
57
-
58
- def reports_do_not_exist
59
- !(LicenseFinder.config.artifacts.html_file.exist?)
60
- end
61
-
62
- def reports_are_stale
63
- LicenseFinder.config.last_modified > LicenseFinder.config.artifacts.last_refreshed
64
- end
65
-
66
- def current_packages
67
- package_managers.
68
- map { |pm| pm.new(logger: logger) }.
69
- select(&:active?).
70
- map(&:current_packages).
71
- flatten
72
- end
73
-
74
- def package_managers
75
- [Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods]
76
- end
77
-
78
- def find_by_name(name, scope = Dependency)
79
- dep = scope.first(name: name)
80
- raise Error.new("could not find dependency named #{name}") unless dep
81
- dep
82
- end
83
-
84
- def checksum
85
- database_file = LicenseFinder.config.artifacts.database_file
86
- if database_file.exist?
87
- Digest::SHA2.file(database_file).hexdigest
88
- end
89
- end
90
- end
91
- end
92
-
@@ -1,44 +0,0 @@
1
- require 'forwardable'
2
-
3
- module LicenseFinder
4
- class PackageSaver
5
- extend Forwardable
6
- def_delegators :package, :licenses, :children, :groups, :summary, :description, :version, :homepage
7
-
8
- attr_reader :dependency, :package
9
-
10
- def self.save_all(packages)
11
- packages.map do |package|
12
- find_or_create_by_name(package).save
13
- end
14
- end
15
-
16
- def initialize(dependency, package)
17
- @dependency = dependency
18
- @package = package
19
- end
20
-
21
- def save
22
- dependency.version = version.to_s
23
- dependency.summary = summary
24
- dependency.description = description
25
- dependency.homepage = homepage
26
- dependency.bundler_group_names = groups.map(&:to_s)
27
- dependency.children_names = children
28
- dependency.set_licenses licenses
29
-
30
- # Only save *changed* dependencies. This ensures re-running
31
- # `license_finder` won't always update the DB, and therefore won't always
32
- # update the HTML/markdown reports with a new timestamp.
33
- dependency.save_changes
34
- dependency
35
- end
36
-
37
- private
38
-
39
- def self.find_or_create_by_name(package)
40
- dependency = Dependency.named(package.name)
41
- new(dependency, package)
42
- end
43
- end
44
- end