license_finder 1.0.0.0-java → 1.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.force-build +0 -0
  3. data/.travis.yml +8 -7
  4. data/CHANGELOG.rdoc +29 -1
  5. data/Rakefile +2 -2
  6. data/db/migrate/201311192003_reassociate_manual_approval.rb +2 -3
  7. data/db/migrate/201403181732_rename_manual_fields.rb +10 -0
  8. data/db/migrate/201403190028_add_manual_approvals.rb +22 -0
  9. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +15 -0
  10. data/db/migrate/201403191645_remove_license_aliases.rb +23 -0
  11. data/features/cli.feature +21 -20
  12. data/features/cocoapods_dependencies.feature +10 -0
  13. data/features/configure_bundler_groups.feature +23 -0
  14. data/features/configure_ignore_dependencies.feature +16 -0
  15. data/features/{project_name.feature → configure_project_name.feature} +1 -1
  16. data/features/{whitelist.feature → configure_whitelist.feature} +6 -6
  17. data/features/manually_added.feature +19 -0
  18. data/features/{approve_dependencies.feature → manually_approved.feature} +2 -2
  19. data/features/manually_assigned_license.feature +16 -0
  20. data/features/{text_report.feature → report_csv.feature} +2 -2
  21. data/features/{html_report.feature → report_html.feature} +2 -2
  22. data/features/step_definitions/cli_steps.rb +22 -32
  23. data/features/step_definitions/cocoapod_steps.rb +8 -0
  24. data/features/step_definitions/configure_bundler_groups_steps.rb +30 -0
  25. data/features/step_definitions/configure_ignore_dependencies.rb +35 -0
  26. data/features/step_definitions/{project_name_steps.rb → configure_project_name_steps.rb} +0 -0
  27. data/features/step_definitions/configure_whitelist_steps.rb +45 -0
  28. data/features/step_definitions/gradle_steps.rb +2 -2
  29. data/features/step_definitions/manually_added_steps.rb +28 -0
  30. data/features/step_definitions/manually_approved_steps.rb +24 -0
  31. data/features/step_definitions/manually_assigned_license_steps.rb +34 -0
  32. data/features/step_definitions/maven_steps.rb +2 -2
  33. data/features/step_definitions/node_steps.rb +2 -2
  34. data/features/step_definitions/python_steps.rb +1 -1
  35. data/features/step_definitions/report_csv_steps.rb +20 -0
  36. data/features/step_definitions/report_html_steps.rb +60 -0
  37. data/features/step_definitions/shared_steps.rb +125 -104
  38. data/{files/license_finder.yml → lib/data/license_finder.example.yml} +3 -0
  39. data/lib/license_finder.rb +3 -2
  40. data/lib/license_finder/cli.rb +94 -49
  41. data/lib/license_finder/configuration.rb +21 -14
  42. data/lib/license_finder/dependency_manager.rb +27 -19
  43. data/lib/license_finder/license.rb +33 -19
  44. data/lib/license_finder/license/definitions.rb +153 -104
  45. data/lib/license_finder/license/matcher.rb +6 -1
  46. data/lib/license_finder/license/none_matcher.rb +9 -0
  47. data/lib/license_finder/license/text.rb +1 -0
  48. data/lib/license_finder/package.rb +30 -6
  49. data/lib/license_finder/package_managers/bower.rb +2 -2
  50. data/lib/license_finder/package_managers/bower_package.rb +2 -2
  51. data/lib/license_finder/package_managers/bundler.rb +9 -17
  52. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  53. data/lib/license_finder/package_managers/cocoa_pods.rb +35 -0
  54. data/lib/license_finder/package_managers/cocoa_pods_package.rb +19 -0
  55. data/lib/license_finder/package_managers/gradle.rb +9 -5
  56. data/lib/license_finder/package_managers/gradle_package.rb +4 -4
  57. data/lib/license_finder/package_managers/maven.rb +7 -3
  58. data/lib/license_finder/package_managers/maven_package.rb +5 -5
  59. data/lib/license_finder/package_managers/npm.rb +2 -2
  60. data/lib/license_finder/package_managers/npm_package.rb +2 -2
  61. data/lib/license_finder/package_managers/pip.rb +2 -2
  62. data/lib/license_finder/package_managers/pip_package.rb +7 -11
  63. data/lib/license_finder/package_saver.rb +12 -10
  64. data/lib/license_finder/possible_license_file.rb +1 -1
  65. data/lib/license_finder/possible_license_files.rb +11 -15
  66. data/lib/license_finder/reports/formatted_report.rb +25 -6
  67. data/lib/license_finder/reports/html_report.rb +2 -1
  68. data/lib/license_finder/reports/reporter.rb +3 -3
  69. data/lib/license_finder/tables.rb +6 -4
  70. data/lib/license_finder/tables/dependency.rb +36 -16
  71. data/lib/license_finder/tables/manual_approval.rb +13 -0
  72. data/lib/license_finder/yml_to_sql.rb +12 -9
  73. data/lib/templates/html_report.erb +68 -74
  74. data/lib/templates/markdown_report.erb +20 -21
  75. data/license_finder.gemspec +7 -7
  76. data/readme.md +76 -79
  77. data/spec/fixtures/Podfile +3 -0
  78. data/spec/lib/license_finder/cli_spec.rb +71 -23
  79. data/spec/lib/license_finder/configuration_spec.rb +61 -21
  80. data/spec/lib/license_finder/dependency_manager_spec.rb +52 -33
  81. data/spec/lib/license_finder/license/definitions_spec.rb +30 -14
  82. data/spec/lib/license_finder/license_spec.rb +55 -12
  83. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +38 -19
  84. data/spec/lib/license_finder/package_managers/bower_spec.rb +10 -16
  85. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +39 -15
  86. data/spec/lib/license_finder/package_managers/bundler_spec.rb +10 -22
  87. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +44 -0
  88. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +79 -0
  89. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +4 -5
  90. data/spec/lib/license_finder/package_managers/gradle_spec.rb +26 -20
  91. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +4 -5
  92. data/spec/lib/license_finder/package_managers/maven_spec.rb +16 -19
  93. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +39 -19
  94. data/spec/lib/license_finder/package_managers/npm_spec.rb +10 -16
  95. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +8 -8
  96. data/spec/lib/license_finder/package_managers/pip_spec.rb +10 -16
  97. data/spec/lib/license_finder/package_saver_spec.rb +27 -3
  98. data/spec/lib/license_finder/possible_license_file_spec.rb +25 -23
  99. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +6 -8
  100. data/spec/lib/license_finder/reports/html_report_spec.rb +45 -44
  101. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -9
  102. data/spec/lib/license_finder/reports/reporter_spec.rb +1 -1
  103. data/spec/lib/license_finder/reports/text_report_spec.rb +6 -8
  104. data/spec/lib/license_finder/tables/dependency_spec.rb +57 -41
  105. data/spec/lib/license_finder/yml_to_sql_spec.rb +94 -92
  106. data/spec/spec_helper.rb +1 -0
  107. data/spec/support/stdout_helpers.rb +25 -0
  108. metadata +86 -69
  109. data/MIT.LICENSE +0 -20
  110. data/features/ignore_bundle_groups.feature +0 -23
  111. data/features/manually_managed_dependencies.feature +0 -19
  112. data/features/set_license.feature +0 -10
  113. data/features/step_definitions/approve_dependencies_steps.rb +0 -25
  114. data/features/step_definitions/html_report_steps.rb +0 -62
  115. data/features/step_definitions/ignore_bundle_groups_steps.rb +0 -29
  116. data/features/step_definitions/manually_managed_steps.rb +0 -33
  117. data/features/step_definitions/set_license_steps.rb +0 -20
  118. data/features/step_definitions/text_report_steps.rb +0 -19
  119. data/features/step_definitions/whitelist_steps.rb +0 -45
  120. data/files/dependency_breakdown.png +0 -0
  121. data/files/report_breakdown.png +0 -0
  122. data/lib/license_finder/license_url.rb +0 -9
  123. data/lib/license_finder/tables/license_alias.rb +0 -22
  124. data/spec/lib/license_finder/license_url_spec.rb +0 -16
  125. data/spec/lib/license_finder/tables/license_alias_spec.rb +0 -37
  126. data/spec/support/silence_stdout.rb +0 -13
@@ -5,5 +5,8 @@ whitelist:
5
5
  ignore_groups:
6
6
  #- test
7
7
  #- development
8
+ ignore_dependencies:
9
+ #- bundler
8
10
  dependencies_file_dir: './doc/'
9
11
  project_name: # project name
12
+ gradle_command: # only meaningful if used with a Java/gradle project. Defaults to "gradle".
@@ -11,7 +11,6 @@ module LicenseFinder
11
11
  autoload :DependencyManager, 'license_finder/dependency_manager'
12
12
  autoload :PackageSaver, 'license_finder/package_saver'
13
13
  autoload :License, 'license_finder/license'
14
- autoload :LicenseUrl, 'license_finder/license_url'
15
14
  autoload :PossibleLicenseFile, 'license_finder/possible_license_file'
16
15
  autoload :PossibleLicenseFiles, 'license_finder/possible_license_files'
17
16
  autoload :Configuration, 'license_finder/configuration'
@@ -23,6 +22,7 @@ module LicenseFinder
23
22
  autoload :NPM, 'license_finder/package_managers/npm'
24
23
  autoload :Pip, 'license_finder/package_managers/pip'
25
24
  autoload :Maven, 'license_finder/package_managers/maven'
25
+ autoload :CocoaPods, 'license_finder/package_managers/cocoa_pods'
26
26
  autoload :Gradle, 'license_finder/package_managers/gradle'
27
27
  autoload :BowerPackage, 'license_finder/package_managers/bower_package'
28
28
  autoload :BundlerPackage, 'license_finder/package_managers/bundler_package'
@@ -30,11 +30,12 @@ module LicenseFinder
30
30
  autoload :NpmPackage, 'license_finder/package_managers/npm_package'
31
31
  autoload :MavenPackage, 'license_finder/package_managers/maven_package'
32
32
  autoload :GradlePackage, 'license_finder/package_managers/gradle_package'
33
+ autoload :CocoaPodsPackage, 'license_finder/package_managers/cocoa_pods_package'
33
34
 
34
35
 
35
36
  autoload :BundlerGroup, 'license_finder/tables/bundler_group'
36
37
  autoload :Dependency, 'license_finder/tables/dependency'
37
- autoload :LicenseAlias, 'license_finder/tables/license_alias'
38
+ autoload :ManualApproval, 'license_finder/tables/manual_approval'
38
39
  autoload :YmlToSql, 'license_finder/yml_to_sql'
39
40
 
40
41
  autoload :DependencyReport, 'license_finder/reports/dependency_report'
@@ -11,12 +11,43 @@ module LicenseFinder
11
11
 
12
12
  private
13
13
 
14
+ def sync_with_spinner
15
+ die_on_error {
16
+ spinner {
17
+ DependencyManager.sync_with_package_managers
18
+ }
19
+ }
20
+ end
21
+
14
22
  def die_on_error
15
23
  yield
16
24
  rescue LicenseFinder::Error => e
17
25
  say e.message, :red
18
26
  exit 1
19
27
  end
28
+
29
+ def spinner
30
+ if options[:quiet]
31
+ yield
32
+ else
33
+ begin
34
+ thread = Thread.new {
35
+ wheel = '\|/-'
36
+ i = 0
37
+ while true do
38
+ print "\r ---------- #{wheel[i]} ----------"
39
+ i = (i + 1) % 4
40
+ end
41
+ }
42
+ yield
43
+ ensure
44
+ if thread
45
+ thread.kill
46
+ puts "\r" + " "*24
47
+ end
48
+ end
49
+ end
50
+ end
20
51
  end
21
52
 
22
53
  # Thor fix for `license_finder <subcommand> help <action>`
@@ -40,11 +71,13 @@ module LicenseFinder
40
71
 
41
72
  class Dependencies < Subcommand
42
73
  method_option :approve, type: :boolean, desc: "Approve the added dependency"
43
- desc "add LICENSE DEPENDENCY_NAME [VERSION] [--approve]", "Add a dependency that is not managed by Bundler, NPM, etc"
74
+ method_option :approver, desc: "The person granting the approval"
75
+ method_option :message, desc: "The reason for the approval"
76
+ 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"
44
77
  def add(license, name, version = nil)
45
78
  die_on_error {
46
- DependencyManager.create_manually_managed(license, name, version)
47
- DependencyManager.approve!(name) if options[:approve]
79
+ DependencyManager.manually_add(license, name, version)
80
+ DependencyManager.approve!(name, options[:approver], options[:message]) if options[:approve]
48
81
  }
49
82
  if options[:approve]
50
83
  say "The #{name} dependency has been added and approved!", :green
@@ -53,10 +86,10 @@ module LicenseFinder
53
86
  end
54
87
  end
55
88
 
56
- desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler, NPM, etc"
89
+ desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by a package manager"
57
90
  def remove(name)
58
91
  die_on_error {
59
- DependencyManager.destroy_manually_managed(name)
92
+ DependencyManager.manually_remove(name)
60
93
  }
61
94
 
62
95
  say "The #{name} dependency has been removed.", :green
@@ -71,7 +104,7 @@ module LicenseFinder
71
104
  yield
72
105
 
73
106
  LicenseFinder.config.save
74
- Reporter.write_reports
107
+ sync_with_spinner
75
108
  }
76
109
  end
77
110
  end
@@ -88,7 +121,8 @@ module LicenseFinder
88
121
  end
89
122
 
90
123
  desc "add LICENSE...", "Add one or more licenses to the whitelist"
91
- def add(*licenses)
124
+ def add(license, *other_licenses)
125
+ licenses = other_licenses.unshift license
92
126
  modifying {
93
127
  licenses.each do |license|
94
128
  LicenseFinder.config.whitelist.push(license)
@@ -98,7 +132,8 @@ module LicenseFinder
98
132
  end
99
133
 
100
134
  desc "remove LICENSE...", "Remove one or more licenses from the whitelist"
101
- def remove(*licenses)
135
+ def remove(license, *other_licenses)
136
+ licenses = other_licenses.unshift license
102
137
  modifying {
103
138
  licenses.each do |license|
104
139
  LicenseFinder.config.whitelist.delete(license)
@@ -146,31 +181,64 @@ module LicenseFinder
146
181
  end
147
182
  end
148
183
 
184
+ class IgnoredDependencies < ConfigSubcommand
185
+ desc "list", "List all the ignored dependencies"
186
+ def list
187
+ ignored = LicenseFinder.config.ignore_dependencies
188
+
189
+ say "Ignored Dependencies:", :blue
190
+ if ignored.any?
191
+ ignored.each do |group|
192
+ say group
193
+ end
194
+ else
195
+ say '(none)'
196
+ end
197
+ end
198
+
199
+ desc "add DEPENDENCY", "Add a dependency to be ignored"
200
+ def add(group)
201
+ modifying {
202
+ LicenseFinder.config.ignore_dependencies.push(group)
203
+ }
204
+ say "Added #{group} to the ignored dependencies"
205
+ end
206
+
207
+ desc "remove DEPENDENCY", "Remove a dependency from the ignored dependencies"
208
+ def remove(group)
209
+ modifying {
210
+ LicenseFinder.config.ignore_dependencies.delete(group)
211
+ }
212
+ say "Removed #{group} from the ignored dependencies"
213
+ end
214
+ end
215
+
149
216
  class Main < Base
150
217
  method_option :quiet, type: :boolean, desc: "silences loading output"
151
218
  desc "rescan", "Find new dependencies. (Default action)"
152
219
  def rescan
153
- die_on_error {
154
- spinner {
155
- DependencyManager.sync_with_package_managers
156
- }
157
- }
220
+ sync_with_spinner
221
+ show_results
222
+ end
158
223
 
224
+ desc "show_results", "Display ignored dependencies and action items"
225
+ def show_results
226
+ IgnoredDependencies.new.list
159
227
  action_items
160
228
  end
229
+
161
230
  default_task :rescan
162
231
 
163
- desc "approve DEPENDENCY_NAME...", "Approve one or more dependencies by name"
164
- def approve(*names)
165
- if(names.count < 1)
166
- say "Warning: Must specify dependencies to approve.", :red
167
- else
168
- die_on_error {
169
- names.each { |name| DependencyManager.approve!(name) }
170
- }
232
+ method_option :approver, desc: "The person granting the approval"
233
+ method_option :message, desc: "The reason for the approval"
234
+ 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"
235
+ def approve(name, *other_names)
236
+ names = other_names.unshift name
237
+ die_on_error {
238
+ names.each { |name| DependencyManager.approve!(name, options[:approver], options[:message]) }
239
+ }
171
240
 
172
- say "The #{names.join(", ")} dependency has been approved!", :green
173
- end
241
+ say "The #{names.join(", ")} dependency has been approved!", :green
174
242
  end
175
243
 
176
244
  desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license"
@@ -201,35 +269,12 @@ module LicenseFinder
201
269
  end
202
270
  end
203
271
 
204
- subcommand "dependencies", Dependencies, "Manually manage dependencies outside of Bundler, NPM, pip, etc"
205
- subcommand "ignored_bundler_groups", IgnoredBundlerGroups, "Manage ignored bundler groups"
272
+ subcommand "dependencies", Dependencies, "Manually manage dependencies that your package managers are not aware of"
273
+ subcommand "ignored_bundler_groups", IgnoredBundlerGroups, "Manage ignored Bundler groups"
274
+ subcommand "ignored_dependencies", IgnoredDependencies, "Manage ignored dependencies"
206
275
  subcommand "whitelist", Whitelist, "Manage whitelisted licenses"
207
276
  subcommand "project_name", ProjectName, "Manage the project name"
208
277
 
209
- private
210
-
211
- def spinner
212
- if options[:quiet]
213
- yield
214
- else
215
- begin
216
- thread = Thread.new {
217
- wheel = '\|/-'
218
- i = 0
219
- while true do
220
- print "\r ---------- #{wheel[i]} ----------"
221
- i = (i + 1) % 4
222
- end
223
- }
224
- yield
225
- ensure
226
- if thread
227
- thread.kill
228
- puts "\r" + " "*24
229
- end
230
- end
231
- end
232
- end
233
278
  end
234
279
  end
235
280
  end
@@ -7,6 +7,10 @@ module LicenseFinder
7
7
  prepare(Persistence.get)
8
8
  end
9
9
 
10
+ def last_modified
11
+ Persistence.last_modified
12
+ end
13
+
10
14
  def self.move!
11
15
  config = prepare(Persistence.get.merge('dependencies_file_dir' => './doc/'))
12
16
  config.save
@@ -24,18 +28,15 @@ module LicenseFinder
24
28
  result
25
29
  end
26
30
 
27
- attr_accessor :whitelist, :ignore_groups, :artifacts, :project_name
31
+ attr_accessor :whitelist, :ignore_groups, :ignore_dependencies, :artifacts, :project_name, :gradle_command
28
32
 
29
33
  def initialize(config)
30
34
  @whitelist = Array(config['whitelist'])
31
35
  @ignore_groups = Array(config["ignore_groups"])
36
+ @ignore_dependencies = Array(config["ignore_dependencies"])
32
37
  @artifacts = Artifacts.new(Pathname(config['dependencies_file_dir'] || './doc/'))
33
38
  @project_name = config['project_name'] || determine_project_name
34
- end
35
-
36
- def whitelisted?(license_name)
37
- license = License.find_by_name(license_name)
38
- whitelisted_licenses.include? license
39
+ @gradle_command = config['gradle_command'] || 'gradle'
39
40
  end
40
41
 
41
42
  def save
@@ -48,17 +49,13 @@ module LicenseFinder
48
49
  {
49
50
  'whitelist' => whitelist.uniq,
50
51
  'ignore_groups' => ignore_groups.uniq,
52
+ 'ignore_dependencies' => ignore_dependencies.uniq,
51
53
  'dependencies_file_dir' => artifacts.dir.to_s,
52
- 'project_name' => project_name
54
+ 'project_name' => project_name,
55
+ 'gradle_command' => gradle_command
53
56
  }
54
57
  end
55
58
 
56
- def whitelisted_licenses
57
- whitelist.map do |license_name|
58
- License.find_by_name(license_name) || license_name
59
- end.compact
60
- end
61
-
62
59
  def determine_project_name
63
60
  Pathname.pwd.basename.to_s
64
61
  end
@@ -103,6 +100,12 @@ module LicenseFinder
103
100
  def legacy_text_file
104
101
  join("dependencies.txt")
105
102
  end
103
+
104
+ def last_refreshed
105
+ [database_file, text_file, detailed_text_file, html_file, markdown_file].map do |path|
106
+ File.mtime(path)
107
+ end.min
108
+ end
106
109
  end
107
110
 
108
111
  module Persistence
@@ -122,6 +125,10 @@ module LicenseFinder
122
125
  file.open('w') { |f| f.write(YAML.dump(hash)) }
123
126
  end
124
127
 
128
+ def last_modified
129
+ File.mtime(file)
130
+ end
131
+
125
132
  private
126
133
 
127
134
  def inited?
@@ -142,7 +149,7 @@ module LicenseFinder
142
149
  end
143
150
 
144
151
  def file_template
145
- ROOT_PATH.join('..', 'files', 'license_finder.yml')
152
+ ROOT_PATH.join('data', 'license_finder.example.yml')
146
153
  end
147
154
  end
148
155
  end
@@ -6,42 +6,41 @@ module LicenseFinder
6
6
  modifying {
7
7
  current_dependencies = PackageSaver.save_all(current_packages)
8
8
 
9
- Dependency.managed.obsolete(current_dependencies).each(&:destroy)
9
+ Dependency.added_automatically.obsolete(current_dependencies).each(&:destroy)
10
10
  }
11
11
  end
12
12
 
13
- def self.create_manually_managed(license, name, version)
13
+ def self.manually_add(license, name, version)
14
14
  raise Error.new("#{name} dependency already exists") unless Dependency.where(name: name).empty?
15
15
 
16
16
  modifying {
17
- dependency = Dependency.new(manual: true, name: name, version: version)
18
- dependency.license = LicenseAlias.named(license)
17
+ dependency = Dependency.new(added_manually: true, name: name, version: version)
18
+ dependency.license = License.find_by_name(license)
19
19
  dependency.save
20
20
  }
21
21
  end
22
22
 
23
- def self.destroy_manually_managed(name)
24
- modifying { find_by_name(name, Dependency.manually_managed).destroy }
23
+ def self.manually_remove(name)
24
+ modifying { find_by_name(name, Dependency.added_manually).destroy }
25
25
  end
26
26
 
27
- def self.license!(name, license)
27
+ def self.license!(name, license_name)
28
+ license = License.find_by_name(license_name)
28
29
  modifying { find_by_name(name).set_license_manually!(license) }
29
30
  end
30
31
 
31
- def self.approve!(name)
32
- modifying { find_by_name(name).approve! }
32
+ def self.approve!(name, approver = nil, notes = nil)
33
+ modifying { find_by_name(name).approve!(approver, notes) }
33
34
  end
34
35
 
35
36
  def self.modifying
36
- database_file = LicenseFinder.config.artifacts.database_file
37
- checksum_before_modifying = checksum(database_file)
38
- result = yield
39
- checksum_after_modifying = checksum(database_file)
37
+ checksum_before = checksum
38
+ result = DB.transaction { yield }
39
+ checksum_after = checksum
40
40
 
41
- unless checksum_after_modifying == checksum_before_modifying
42
- Reporter.write_reports
43
- end
44
- unless LicenseFinder.config.artifacts.html_file.exist?
41
+ database_changed = checksum_before != checksum_after
42
+
43
+ if database_changed || reports_do_not_exist || reports_are_stale
45
44
  Reporter.write_reports
46
45
  end
47
46
 
@@ -50,12 +49,20 @@ module LicenseFinder
50
49
 
51
50
  private # not really private, but it looks like it is!
52
51
 
52
+ def self.reports_do_not_exist
53
+ !(LicenseFinder.config.artifacts.html_file.exist?)
54
+ end
55
+
56
+ def self.reports_are_stale
57
+ LicenseFinder.config.last_modified > LicenseFinder.config.artifacts.last_refreshed
58
+ end
59
+
53
60
  def self.current_packages
54
61
  package_managers.select(&:active?).map(&:current_packages).flatten
55
62
  end
56
63
 
57
64
  def self.package_managers
58
- [Bundler, NPM, Pip, Bower, Maven, Gradle]
65
+ [Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods]
59
66
  end
60
67
 
61
68
  def self.find_by_name(name, scope = Dependency)
@@ -64,7 +71,8 @@ module LicenseFinder
64
71
  dep
65
72
  end
66
73
 
67
- def self.checksum(database_file)
74
+ def self.checksum
75
+ database_file = LicenseFinder.config.artifacts.database_file
68
76
  if database_file.exist?
69
77
  Digest::SHA2.file(database_file).hexdigest
70
78
  end
@@ -2,34 +2,42 @@ module LicenseFinder
2
2
  class License
3
3
  class << self
4
4
  def all
5
- @all ||= []
5
+ @all ||= Definitions.all(LicenseFinder.config.whitelist)
6
6
  end
7
7
 
8
8
  def find_by_name(name)
9
- all.detect { |l| l.matches_name? name } || UnknownLicense.new(name)
9
+ name ||= "other"
10
+ all.detect { |l| l.matches_name? name } || Definitions.build_unrecognized(name, LicenseFinder.config.whitelist)
10
11
  end
11
12
 
12
13
  def find_by_text(text)
13
- all.detect { |l| l.matches_text? text } || UnknownLicense.new
14
+ all.detect { |l| l.matches_text? text }
14
15
  end
15
16
  end
16
17
 
18
+ autoload :Definitions, "license_finder/license/definitions"
17
19
  autoload :Text, "license_finder/license/text"
18
20
  autoload :Template, "license_finder/license/template"
19
21
  autoload :Matcher, "license_finder/license/matcher"
20
22
  autoload :HeaderMatcher, "license_finder/license/header_matcher"
21
23
  autoload :AnyMatcher, "license_finder/license/any_matcher"
22
-
23
- attr_reader :url, :pretty_name
24
+ autoload :NoneMatcher, "license_finder/license/none_matcher"
24
25
 
25
26
  def initialize(settings)
26
27
  @short_name = settings.fetch(:short_name)
27
28
  @pretty_name = settings.fetch(:pretty_name, short_name)
28
29
  @other_names = settings.fetch(:other_names, [])
29
30
  @url = settings.fetch(:url)
31
+ @whitelisted = settings.fetch(:whitelisted, false)
30
32
  @matcher = settings.fetch(:matcher) { Matcher.from_template(Template.named(short_name)) }
31
33
  end
32
34
 
35
+ attr_reader :url
36
+
37
+ def name
38
+ pretty_name
39
+ end
40
+
33
41
  def matches_name?(name)
34
42
  names.map(&:downcase).include? name.to_s.downcase
35
43
  end
@@ -38,27 +46,33 @@ module LicenseFinder
38
46
  matcher.matches_text?(text)
39
47
  end
40
48
 
49
+ def whitelisted?
50
+ @whitelisted
51
+ end
52
+
53
+ def whitelist
54
+ copy(whitelisted: true)
55
+ end
56
+
41
57
  private
42
58
 
43
- attr_reader :short_name, :other_names, :matcher
59
+ attr_reader :short_name, :pretty_name, :other_names
60
+ attr_reader :matcher
44
61
 
45
62
  def names
46
63
  ([short_name, pretty_name] + other_names).uniq
47
64
  end
48
- end
49
-
50
- class UnknownLicense
51
- attr_reader :pretty_name
52
-
53
- def initialize(name = nil)
54
- @pretty_name = name
55
- end
56
- def url; end
57
65
 
58
- def ==(other)
59
- pretty_name.eql?(other.pretty_name)
66
+ def copy(overrides)
67
+ settings = {
68
+ short_name: short_name,
69
+ pretty_name: pretty_name,
70
+ other_names: other_names,
71
+ url: url,
72
+ whitelisted: whitelisted?,
73
+ matcher: matcher
74
+ }
75
+ self.class.new(settings.merge(overrides))
60
76
  end
61
77
  end
62
78
  end
63
-
64
- require LicenseFinder::ROOT_PATH.join("license_finder", "license", "definitions.rb")