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
@@ -0,0 +1,50 @@
1
+ require 'feature_helper'
2
+
3
+ describe "HTML report" do
4
+ # As a non-technical application product owner
5
+ # I want license finder to generate an easy-to-understand HTML report
6
+ # So that I can quickly review my application dependencies and licenses
7
+
8
+ let(:user) { LicenseFinder::TestingDSL::User.new }
9
+
10
+ specify "shows basic dependency data" do
11
+ gem_name = "a_gem"
12
+ gem_group = "test"
13
+ gem_attributes = {
14
+ license: "MIT",
15
+ summary: "gem is cool",
16
+ description: "seriously",
17
+ version: "0.0.1",
18
+ homepage: "http://a_gem.github.com"
19
+ }
20
+
21
+ project = user.create_ruby_app
22
+ gem = user.create_gem gem_name, gem_attributes
23
+ project.depend_on gem, groups: [gem_group]
24
+
25
+ user.view_html.in_dep(gem_name) do |section|
26
+ expect(section.find("a[href='#{gem_attributes[:homepage]}']", text: gem_name)).to be
27
+ expect(section).to have_content gem_attributes[:license]
28
+ expect(section).to have_content gem_attributes[:summary]
29
+ expect(section).to have_content gem_attributes[:description]
30
+ expect(section).to have_content gem_attributes[:version]
31
+ expect(section).to have_content gem_group
32
+ end
33
+ end
34
+
35
+ specify "shows approval status of dependencies" do
36
+ user.create_empty_project
37
+ user.execute_command 'license_finder dependencies add gpl_dep GPL'
38
+ user.execute_command 'license_finder dependencies add mit_dep MIT'
39
+ user.execute_command 'license_finder whitelist add MIT'
40
+
41
+ html = user.view_html
42
+ expect(html).to be_unapproved 'gpl_dep'
43
+ expect(html).to be_approved 'mit_dep'
44
+
45
+ expect(html).to have_content '1 GPL'
46
+ action_items = html.find('.action-items')
47
+ expect(action_items).to have_content '(GPL)'
48
+ expect(action_items).not_to have_content 'MIT'
49
+ end
50
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,295 @@
1
+ require 'delegate'
2
+
3
+ module LicenseFinder::TestingDSL
4
+ class User
5
+ def run_license_finder
6
+ execute_command "license_finder --quiet"
7
+ end
8
+
9
+ def create_empty_project
10
+ EmptyProject.create
11
+ end
12
+
13
+ def create_ruby_app
14
+ BundlerProject.create
15
+ end
16
+
17
+ def create_gem(name, options)
18
+ GemProject.create(name, options)
19
+ end
20
+
21
+ def execute_command(command)
22
+ @output, @exit_code = Paths.project.shell_out(command, true)
23
+ end
24
+
25
+ def seeing?(content)
26
+ @output.include? content
27
+ end
28
+
29
+ def seeing_line?(content)
30
+ seeing_something_like? /^#{Regexp.escape content}$/
31
+ end
32
+
33
+ def seeing_something_like?(regex)
34
+ @output =~ regex
35
+ end
36
+
37
+ def receiving_exit_code?(code)
38
+ @exit_code == code
39
+ end
40
+
41
+ def view_html
42
+ execute_command 'license_finder report --format html'
43
+ HtmlReport.from_string(@output)
44
+ end
45
+ end
46
+
47
+ require 'forwardable'
48
+ class Project
49
+ extend Forwardable
50
+ def_delegators :project_dir, :shell_out, :add_to_file, :install_fixture
51
+
52
+ def self.create
53
+ project = new
54
+ project.add_dep
55
+ project.install
56
+ project
57
+ end
58
+
59
+ def initialize
60
+ Paths.reset_projects!
61
+ project_dir.make
62
+ end
63
+
64
+ def add_dep
65
+ end
66
+
67
+ def install
68
+ end
69
+
70
+ private
71
+
72
+ def project_dir
73
+ Paths.project
74
+ end
75
+ end
76
+
77
+ class EmptyProject < Project
78
+ end
79
+
80
+ class PipProject < Project
81
+ def add_dep
82
+ add_to_file("requirements.txt", 'argparse==1.2.1')
83
+ end
84
+
85
+ def install
86
+ shell_out("pip install -r requirements.txt")
87
+ end
88
+ end
89
+
90
+ class NpmProject < Project
91
+ def add_dep
92
+ add_to_file("package.json", '{"dependencies" : {"http-server": "0.6.1"}}')
93
+ end
94
+
95
+ def install
96
+ shell_out("npm install 2>/dev/null")
97
+ end
98
+ end
99
+
100
+ class BowerProject < Project
101
+ def add_dep
102
+ add_to_file('bower.json', '{"name": "my_app", "dependencies" : {"gmaps": "0.2.30"}}')
103
+ end
104
+
105
+ def install
106
+ shell_out("bower install 2>/dev/null")
107
+ end
108
+ end
109
+
110
+ class MavenProject < Project
111
+ def add_dep
112
+ install_fixture("pom.xml")
113
+ end
114
+
115
+ def install
116
+ shell_out("mvn install")
117
+ end
118
+ end
119
+
120
+ class GradleProject < Project
121
+ def add_dep
122
+ install_fixture("build.gradle")
123
+ end
124
+ end
125
+
126
+ class CocoaPodsProject < Project
127
+ def add_dep
128
+ install_fixture("Podfile")
129
+ end
130
+
131
+ def install
132
+ shell_out("pod install --no-integrate")
133
+ end
134
+ end
135
+
136
+ class BundlerProject < Project
137
+ def add_dep
138
+ add_to_bundler('license_finder', path: Paths.root.to_s)
139
+ end
140
+
141
+ def install
142
+ shell_out("bundle install")
143
+ end
144
+
145
+ def depend_on(gem, bundler_options = {})
146
+ add_to_bundler(gem.name, bundler_options.merge(path: gem.project_dir.to_s))
147
+ install
148
+ end
149
+
150
+ private
151
+
152
+ def add_to_bundler(gem_name, options)
153
+ add_to_file("Gemfile", "gem #{gem_name.inspect}, #{options.inspect}")
154
+ end
155
+ end
156
+
157
+ class GemProject # lives adjacent to a BundlerProject, so has a different lifecycle from other Projects and doesn't inherit
158
+ def self.create(name, options)
159
+ result = new(name)
160
+ result.define(options)
161
+ result
162
+ end
163
+
164
+ def initialize(name)
165
+ @name = name
166
+ project_dir.make
167
+ end
168
+
169
+ def define(options)
170
+ project_dir.write_file("#{name}.gemspec", gemspec_string(options))
171
+ end
172
+
173
+ attr_reader :name
174
+
175
+ def project_dir
176
+ Paths.project(name)
177
+ end
178
+
179
+ private
180
+
181
+ def gemspec_string(options)
182
+ <<-GEMSPEC
183
+ Gem::Specification.new do |s|
184
+ s.name = "#{name}"
185
+ s.version = "#{options[:version] || "0.0.0"}"
186
+ s.license = "#{options.fetch(:license)}"
187
+ s.author = "license_finder tests"
188
+ s.summary = "#{options[:summary]}"
189
+ s.description = "#{options[:description]}"
190
+ s.homepage = "#{options[:homepage]}"
191
+ end
192
+ GEMSPEC
193
+ end
194
+ end
195
+
196
+ require 'capybara'
197
+ class HtmlReport < SimpleDelegator # delegates to the parsed html
198
+ def self.from_string(str)
199
+ new(Capybara.string(str))
200
+ end
201
+
202
+ def in_dep(dep_name)
203
+ result = find("##{dep_name}")
204
+ yield result if block_given?
205
+ result
206
+ end
207
+
208
+ def approved?(dep_name)
209
+ classes_of(dep_name).include? "approved"
210
+ end
211
+
212
+ def unapproved?(dep_name)
213
+ classes_of(dep_name).include? "unapproved"
214
+ end
215
+
216
+ def titled?(title)
217
+ find("h1").has_content? title
218
+ end
219
+
220
+ private
221
+
222
+ def classes_of(dep_name)
223
+ in_dep(dep_name)[:class].split(' ')
224
+ end
225
+ end
226
+
227
+ class ProjectDir < SimpleDelegator # delegates to a Pathname
228
+ def shell_out(command, allow_failures = false)
229
+ Shell.run("cd #{self} && #{command}", allow_failures)
230
+ end
231
+
232
+ def add_to_file(filename, content)
233
+ join(filename).open('a') { |file| file.puts content }
234
+ end
235
+
236
+ def write_file(filename, content)
237
+ join(filename).open('w') { |file| file.write content }
238
+ end
239
+
240
+ def install_fixture(fixture_name)
241
+ join(fixture_name).make_symlink Paths.fixtures.join(fixture_name)
242
+ end
243
+
244
+ def make
245
+ mkpath
246
+ end
247
+ end
248
+
249
+ require 'pathname'
250
+ module Paths
251
+ extend self
252
+
253
+ def root
254
+ # where license_finder is installed
255
+ Pathname.new(__FILE__).dirname.join("..", "..").realpath
256
+ end
257
+
258
+ def fixtures
259
+ root.join("features", "fixtures")
260
+ end
261
+
262
+ def projects
263
+ root.join("tmp", "projects")
264
+ end
265
+
266
+ def project(name = "my_app")
267
+ ProjectDir.new(projects.join(name))
268
+ end
269
+
270
+ def reset_projects!
271
+ # only destroyed when a test starts, so you can poke around after a failure
272
+ projects.rmtree if projects.exist?
273
+ projects.mkpath
274
+ end
275
+ end
276
+
277
+ module Shell
278
+ ERROR_MESSAGE_FORMAT = <<EOM
279
+ Command failed: `%s`
280
+ output: %s
281
+ exit: %d
282
+ EOM
283
+
284
+ def self.run(command, allow_failures = false)
285
+ output = `#{command} 2>&1`
286
+ status = $?
287
+ unless status.success? || allow_failures
288
+ message = sprintf ERROR_MESSAGE_FORMAT, command, output.chomp, status.exitstatus
289
+ raise RuntimeError.new(message)
290
+ end
291
+
292
+ return [output, status.exitstatus]
293
+ end
294
+ end
295
+ end
@@ -1,60 +1,26 @@
1
1
  require 'pathname'
2
2
  require 'yaml'
3
- require 'erb'
4
3
 
5
4
  module LicenseFinder
6
- ROOT_PATH = Pathname.new(__FILE__).dirname
7
- BIN_PATH = ROOT_PATH.join("../bin")
8
-
9
- Error = Class.new(StandardError)
5
+ ROOT_PATH = Pathname.new(__FILE__).dirname.join("license_finder")
6
+ BIN_PATH = ROOT_PATH.join("../../bin")
7
+ end
10
8
 
11
- autoload :Logger, 'license_finder/logger'
12
- autoload :CLI, 'license_finder/cli'
13
- autoload :PackageManager, 'license_finder/package_manager'
14
- autoload :DependencyManager, 'license_finder/dependency_manager'
15
- autoload :PackageSaver, 'license_finder/package_saver'
16
- autoload :License, 'license_finder/license'
17
- autoload :PossibleLicenseFile, 'license_finder/possible_license_file'
18
- autoload :PossibleLicenseFiles, 'license_finder/possible_license_files'
19
- autoload :Configuration, 'license_finder/configuration'
20
- autoload :Platform, 'license_finder/platform'
9
+ require 'license_finder/platform'
10
+ require 'license_finder/version'
11
+ require 'license_finder/logger'
12
+ require 'license_finder/configuration'
21
13
 
22
- autoload :Package, 'license_finder/package'
23
- autoload :Bower, 'license_finder/package_managers/bower'
24
- autoload :Bundler, 'license_finder/package_managers/bundler'
25
- autoload :NPM, 'license_finder/package_managers/npm'
26
- autoload :Pip, 'license_finder/package_managers/pip'
27
- autoload :Maven, 'license_finder/package_managers/maven'
28
- autoload :CocoaPods, 'license_finder/package_managers/cocoa_pods'
29
- autoload :Gradle, 'license_finder/package_managers/gradle'
30
- autoload :BowerPackage, 'license_finder/package_managers/bower_package'
31
- autoload :BundlerPackage, 'license_finder/package_managers/bundler_package'
32
- autoload :PipPackage, 'license_finder/package_managers/pip_package'
33
- autoload :NpmPackage, 'license_finder/package_managers/npm_package'
34
- autoload :MavenPackage, 'license_finder/package_managers/maven_package'
35
- autoload :GradlePackage, 'license_finder/package_managers/gradle_package'
36
- autoload :CocoaPodsPackage, 'license_finder/package_managers/cocoa_pods_package'
14
+ require 'license_finder/license'
37
15
 
16
+ require 'license_finder/possible_license_file'
17
+ require 'license_finder/possible_license_files'
18
+ require 'license_finder/package'
19
+ require 'license_finder/package_manager'
38
20
 
39
- autoload :BundlerGroup, 'license_finder/tables/bundler_group'
40
- autoload :Dependency, 'license_finder/tables/dependency'
41
- autoload :ManualApproval, 'license_finder/tables/manual_approval'
42
- autoload :YmlToSql, 'license_finder/yml_to_sql'
21
+ require 'license_finder/decisions'
22
+ require 'license_finder/decision_applier'
43
23
 
44
- autoload :DependencyReport, 'license_finder/reports/dependency_report'
45
- autoload :FormattedReport, 'license_finder/reports/formatted_report'
46
- autoload :HtmlReport, 'license_finder/reports/html_report'
47
- autoload :MarkdownReport, 'license_finder/reports/markdown_report'
48
- autoload :Reporter, 'license_finder/reports/reporter'
49
- autoload :TextReport, 'license_finder/reports/text_report'
50
- autoload :DetailedTextReport, 'license_finder/reports/detailed_text_report'
24
+ require 'license_finder/report'
51
25
 
52
- def self.config
53
- @config ||= Configuration.ensure_default
54
- end
55
- end
56
-
57
- unless defined?(LicenseAudit)
58
- require 'license_finder/tables'
59
- LicenseFinder::YmlToSql.convert_if_required
60
- end
26
+ require 'license_finder/cli'
@@ -1,259 +1,19 @@
1
- require 'thor'
2
-
3
1
  module LicenseFinder
4
2
  module CLI
5
- class Base < Thor
6
- def self.subcommand(namespace, klass, namespace_description)
7
- description = "#{namespace} [#{(klass.tasks.keys - ["help"]).join("|")}]"
8
- desc description, "#{namespace_description} - see `license_finder #{namespace} help` for more information"
9
- super namespace, klass
10
- end
11
-
12
- private
13
-
14
- def sync_with_package_managers options={}
15
- die_on_error {
16
- logger = LicenseFinder::Logger.new options
17
- DependencyManager.new(logger: logger).sync_with_package_managers
18
- }
19
- end
20
-
21
- def die_on_error
22
- yield
23
- rescue LicenseFinder::Error => e
24
- say e.message, :red
25
- exit 1
26
- end
27
- end
28
-
29
- # Thor fix for `license_finder <subcommand> help <action>`
30
- class Subcommand < Base
31
- # Hack to override the help message produced by Thor.
32
- # https://github.com/wycats/thor/issues/261#issuecomment-16880836
33
- def self.banner(command, namespace = nil, subcommand = nil)
34
- "#{basename} #{underscore_name(name)} #{command.usage}"
35
- end
36
-
37
- protected
38
-
39
- def self.underscore_name(name)
40
- underscored = name.split("::").last
41
- underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
42
- underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
43
- underscored.tr!("-", "_")
44
- underscored.downcase
45
- end
46
- end
47
-
48
- class Dependencies < Subcommand
49
- method_option :approve, type: :boolean, desc: "Approve the added dependency"
50
- method_option :approver, desc: "The person granting the approval"
51
- method_option :message, desc: "The reason for the approval"
52
- desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve] [--approver APPROVER_NAME] [--message APPROVAL_MESSAGE]", "Add a dependency that is not managed by a package manager, optionally storing who approved the dependency and why"
53
- def add(license, name, version = nil)
54
- die_on_error {
55
- DependencyManager.new.tap do |dependency_manager|
56
- dependency_manager.manually_add(license, name, version)
57
- dependency_manager.approve!(name, options[:approver], options[:message]) if options[:approve]
58
- end
59
- }
60
- if options[:approve]
61
- say "The #{name} dependency has been added and approved!", :green
62
- else
63
- say "The #{name} dependency has been added!", :green
64
- end
65
- end
66
-
67
- desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by a package manager"
68
- def remove(name)
69
- die_on_error {
70
- DependencyManager.new.manually_remove(name)
71
- }
72
-
73
- say "The #{name} dependency has been removed.", :green
74
- end
75
- end
76
-
77
- class ConfigSubcommand < Subcommand
78
- private
79
-
80
- def modifying
81
- die_on_error {
82
- yield
83
-
84
- LicenseFinder.config.save
85
- sync_with_package_managers
86
- }
87
- end
88
- end
89
-
90
- class Whitelist < ConfigSubcommand
91
- desc "list", "List all the whitelisted licenses"
92
- def list
93
- whitelist = LicenseFinder.config.whitelist
94
-
95
- say "Whitelisted Licenses:", :blue
96
- whitelist.each do |license|
97
- say license
98
- end
99
- end
100
-
101
- desc "add LICENSE...", "Add one or more licenses to the whitelist"
102
- def add(license, *other_licenses)
103
- licenses = other_licenses.unshift license
104
- modifying {
105
- licenses.each do |license|
106
- LicenseFinder.config.whitelist.push(license)
107
- end
108
- }
109
- say "Added #{licenses.join(", ")} to the license whitelist"
110
- end
111
-
112
- desc "remove LICENSE...", "Remove one or more licenses from the whitelist"
113
- def remove(license, *other_licenses)
114
- licenses = other_licenses.unshift license
115
- modifying {
116
- licenses.each do |license|
117
- LicenseFinder.config.whitelist.delete(license)
118
- end
119
- }
120
- say "Removed #{licenses.join(", ")} from the license whitelist"
121
- end
122
- end
123
-
124
- class ProjectName < ConfigSubcommand
125
- desc "set NAME", "Set the project name"
126
- def set(name)
127
- modifying {
128
- LicenseFinder.config.project_name = name
129
- }
130
- say "Set the project name to #{name}", :green
131
- end
132
- end
133
-
134
- class IgnoredBundlerGroups < ConfigSubcommand
135
- desc "list", "List all the ignored bundler groups"
136
- def list
137
- ignored = LicenseFinder.config.ignore_groups
138
-
139
- say "Ignored Bundler Groups:", :blue
140
- ignored.each do |group|
141
- say group
142
- end
143
- end
144
-
145
- desc "add GROUP", "Add a bundler group to be ignored"
146
- def add(group)
147
- modifying {
148
- LicenseFinder.config.ignore_groups.push(group)
149
- }
150
- say "Added #{group} to the ignored bundler groups"
151
- end
152
-
153
- desc "remove GROUP", "Remove a bundler group from the ignored bundler groups"
154
- def remove(group)
155
- modifying {
156
- LicenseFinder.config.ignore_groups.delete(group)
157
- }
158
- say "Removed #{group} from the ignored bundler groups"
159
- end
160
- end
161
-
162
- class IgnoredDependencies < ConfigSubcommand
163
- desc "list", "List all the ignored dependencies"
164
- def list
165
- ignored = LicenseFinder.config.ignore_dependencies
166
-
167
- say "Ignored Dependencies:", :blue
168
- if ignored.any?
169
- ignored.each do |group|
170
- say group
171
- end
172
- else
173
- say '(none)'
174
- end
175
- end
176
-
177
- desc "add DEPENDENCY", "Add a dependency to be ignored"
178
- def add(group)
179
- modifying {
180
- LicenseFinder.config.ignore_dependencies.push(group)
181
- }
182
- say "Added #{group} to the ignored dependencies"
183
- end
184
-
185
- desc "remove DEPENDENCY", "Remove a dependency from the ignored dependencies"
186
- def remove(group)
187
- modifying {
188
- LicenseFinder.config.ignore_dependencies.delete(group)
189
- }
190
- say "Removed #{group} from the ignored dependencies"
191
- end
192
- end
193
-
194
- class Main < Base
195
- method_option :quiet, type: :boolean, desc: "silences loading output"
196
- method_option :debug, type: :boolean, desc: "emit detailed info about what LicenseFinder is doing"
197
- desc "rescan", "Find new dependencies. (Default action)"
198
- def rescan
199
- sync_with_package_managers options
200
- show_results
201
- end
202
-
203
- desc "show_results", "Display ignored dependencies and action items"
204
- def show_results
205
- IgnoredDependencies.new.list
206
- action_items
207
- end
208
-
209
- default_task :rescan
210
-
211
- method_option :approver, desc: "The person granting the approval"
212
- method_option :message, desc: "The reason for the approval"
213
- desc "approve DEPENDENCY_NAME... [--approver APPROVER_NAME] [--message APPROVAL_MESSAGE]", "Approve one or more dependencies by name, optionally storing who approved the dependency and why"
214
- def approve(name, *other_names)
215
- names = other_names.unshift name
216
- die_on_error {
217
- names.each { |name| DependencyManager.new.approve!(name, options[:approver], options[:message]) }
218
- }
219
-
220
- say "The #{names.join(", ")} dependency has been approved!", :green
221
- end
222
-
223
- desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license"
224
- def license(license, name)
225
- die_on_error {
226
- DependencyManager.new.license!(name, license)
227
- }
228
-
229
- say "The #{name} dependency has been marked as using #{license} license!", :green
230
- end
231
-
232
- desc "move", "Move dependency.* files from root directory to doc/"
233
- def move
234
- Configuration.move!
235
- say "Congratulations, you have cleaned up your root directory!'", :green
236
- end
3
+ end
4
+ end
237
5
 
238
- desc "action_items", "List unapproved dependencies"
239
- def action_items
240
- unapproved = Dependency.unapproved
6
+ require 'license_finder/cli/patched_thor'
241
7
 
242
- if unapproved.empty?
243
- say "All dependencies are approved for use", :green
244
- else
245
- say "Dependencies that need approval:", :red
246
- say TextReport.new(unapproved)
247
- exit 1
248
- end
249
- end
8
+ require 'license_finder/cli/base'
9
+ require 'license_finder/cli/makes_decisions'
250
10
 
251
- subcommand "dependencies", Dependencies, "Manually manage dependencies that your package managers are not aware of"
252
- subcommand "ignored_bundler_groups", IgnoredBundlerGroups, "Manage ignored Bundler groups"
253
- subcommand "ignored_dependencies", IgnoredDependencies, "Manage ignored dependencies"
254
- subcommand "whitelist", Whitelist, "Manage whitelisted licenses"
255
- subcommand "project_name", ProjectName, "Manage the project name"
11
+ require 'license_finder/cli/whitelist'
12
+ require 'license_finder/cli/dependencies'
13
+ require 'license_finder/cli/licenses'
14
+ require 'license_finder/cli/approvals'
15
+ require 'license_finder/cli/ignored_groups'
16
+ require 'license_finder/cli/ignored_dependencies'
17
+ require 'license_finder/cli/project_name'
256
18
 
257
- end
258
- end
259
- end
19
+ require 'license_finder/cli/main'